Commit 366394ac authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payments][Android] change paymentOptions to bundle

paymentOptions used to get populated as an string arraylist in intent
extras. This cl changes the paymentOptions to a bundle so that native
app developers won't need to convert string values to boolean.

Bug: 1026667
Change-Id: I6804d8765b9c90da73b8533ca55c7304823858f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2219684Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773372}
parent 443e02a4
...@@ -158,8 +158,19 @@ public class WebPaymentIntentHelperTest { ...@@ -158,8 +158,19 @@ public class WebPaymentIntentHelperTest {
Assert.assertEquals("{\"currency\":\"CAD\",\"value\":\"200\"}", Assert.assertEquals("{\"currency\":\"CAD\",\"value\":\"200\"}",
bundle.get(WebPaymentIntentHelper.EXTRA_TOTAL)); bundle.get(WebPaymentIntentHelper.EXTRA_TOTAL));
Assert.assertEquals(bundle.getStringArrayList(WebPaymentIntentHelper.EXTRA_PAYMENT_OPTIONS), Bundle expectedPaymentOptions =
paymentOptions.asStringArrayList()); bundle.getBundle(WebPaymentIntentHelper.EXTRA_PAYMENT_OPTIONS);
Assert.assertTrue(expectedPaymentOptions.getBoolean(
WebPaymentIntentHelper.EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_NAME));
Assert.assertTrue(expectedPaymentOptions.getBoolean(
WebPaymentIntentHelper.EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_EMAIL));
Assert.assertTrue(expectedPaymentOptions.getBoolean(
WebPaymentIntentHelper.EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_PHONE));
Assert.assertTrue(expectedPaymentOptions.getBoolean(
WebPaymentIntentHelper.EXTRA_PAYMENT_OPTIONS_REQUEST_SHIPPING));
Assert.assertEquals("delivery",
expectedPaymentOptions.getString(
WebPaymentIntentHelper.EXTRA_PAYMENT_OPTIONS_SHIPPING_TYPE));
Parcelable[] expectedShippingOptions = Parcelable[] expectedShippingOptions =
bundle.getParcelableArray(WebPaymentIntentHelper.EXTRA_SHIPPING_OPTIONS); bundle.getParcelableArray(WebPaymentIntentHelper.EXTRA_SHIPPING_OPTIONS);
......
...@@ -50,6 +50,11 @@ public class WebPaymentIntentHelper { ...@@ -50,6 +50,11 @@ public class WebPaymentIntentHelper {
public static final String EXTRA_TOP_ORIGIN = "topLevelOrigin"; public static final String EXTRA_TOP_ORIGIN = "topLevelOrigin";
public static final String EXTRA_TOTAL = "total"; public static final String EXTRA_TOTAL = "total";
public static final String EXTRA_PAYMENT_OPTIONS = "paymentOptions"; public static final String EXTRA_PAYMENT_OPTIONS = "paymentOptions";
public static final String EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_NAME = "requestPayerName";
public static final String EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_PHONE = "requestPayerPhone";
public static final String EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_EMAIL = "requestPayerEmail";
public static final String EXTRA_PAYMENT_OPTIONS_REQUEST_SHIPPING = "requestShipping";
public static final String EXTRA_PAYMENT_OPTIONS_SHIPPING_TYPE = "shippingType";
public static final String EXTRA_SHIPPING_OPTIONS = "shippingOptions"; public static final String EXTRA_SHIPPING_OPTIONS = "shippingOptions";
public static final String EXTRA_SHIPPING_OPTION_ID = "shippingOptionId"; public static final String EXTRA_SHIPPING_OPTION_ID = "shippingOptionId";
public static final String EXTRA_SHIPPING_OPTION_LABEL = "label"; public static final String EXTRA_SHIPPING_OPTION_LABEL = "label";
...@@ -381,7 +386,7 @@ public class WebPaymentIntentHelper { ...@@ -381,7 +386,7 @@ public class WebPaymentIntentHelper {
} }
if (paymentOptions != null) { if (paymentOptions != null) {
extras.putStringArrayList(EXTRA_PAYMENT_OPTIONS, paymentOptions.asStringArrayList()); extras.putBundle(EXTRA_PAYMENT_OPTIONS, buildPaymentOptionsBundle(paymentOptions));
} }
// ShippingOptions are populated only when shipping is requested. // ShippingOptions are populated only when shipping is requested.
...@@ -452,6 +457,21 @@ public class WebPaymentIntentHelper { ...@@ -452,6 +457,21 @@ public class WebPaymentIntentHelper {
return result; return result;
} }
private static Bundle buildPaymentOptionsBundle(PaymentOptions paymentOptions) {
Bundle bundle = new Bundle();
bundle.putBoolean(
EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_NAME, paymentOptions.requestPayerName);
bundle.putBoolean(
EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_EMAIL, paymentOptions.requestPayerEmail);
bundle.putBoolean(
EXTRA_PAYMENT_OPTIONS_REQUEST_PAYER_PHONE, paymentOptions.requestPayerPhone);
bundle.putBoolean(EXTRA_PAYMENT_OPTIONS_REQUEST_SHIPPING, paymentOptions.requestShipping);
if (paymentOptions.shippingType != null) {
bundle.putString(EXTRA_PAYMENT_OPTIONS_SHIPPING_TYPE, paymentOptions.shippingType);
}
return bundle;
}
private static String deprecatedSerializeDetails( private static String deprecatedSerializeDetails(
@Nullable PaymentItem total, @Nullable List<PaymentItem> displayItems) { @Nullable PaymentItem total, @Nullable List<PaymentItem> displayItems) {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
......
...@@ -6,8 +6,6 @@ package org.chromium.components.payments.intent; ...@@ -6,8 +6,6 @@ package org.chromium.components.payments.intent;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.util.ArrayList;
/** /**
* The types that corresponds to the types in org.chromium.payments.mojom. The fields of these types * The types that corresponds to the types in org.chromium.payments.mojom. The fields of these types
* are the subset of those in the mojom types. The subset is minimally selected based on the need of * are the subset of those in the mojom types. The subset is minimally selected based on the need of
...@@ -94,22 +92,5 @@ public final class WebPaymentIntentHelperType { ...@@ -94,22 +92,5 @@ public final class WebPaymentIntentHelperType {
this.requestShipping = requestShipping; this.requestShipping = requestShipping;
this.shippingType = shippingType; this.shippingType = shippingType;
} }
/**
* @return an ArrayList of stringified payment options. This should be an ArrayList vs a
* List since the |Bundle.putStringArrayList()| function used for populating
* "paymentOptions" in "Pay" intents accepts ArrayLists.
*/
public ArrayList<String> asStringArrayList() {
ArrayList<String> paymentOptionList = new ArrayList<>();
if (requestPayerName) paymentOptionList.add("requestPayerName");
if (requestPayerEmail) paymentOptionList.add("requestPayerEmail");
if (requestPayerPhone) paymentOptionList.add("requestPayerPhone");
if (requestShipping) {
paymentOptionList.add("requestShipping");
paymentOptionList.add(shippingType);
}
return paymentOptionList;
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment