Commit dc864d5b authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payment][Android] Shipping Option bundle matches PR/PH spec.

This cl changes the ShippingOption bundle to match web payments spec[1]:

1- "ShippingOptionId" key has been changed to "id"
2- shipping cost is kept as a PaymentCurrencyAmount bundle rather than
being flattened to string values with "amountValue"/"amountCurrency"
keys.

[1] https://www.w3.org/TR/payment-request/#dom-paymentshippingoption-id

Bug: 1103686
Change-Id: I05d0983a54e8795904dd5b1278c49bd858706b57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2289992Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787885}
parent 5a00bc83
...@@ -111,7 +111,7 @@ public final class WebPaymentIntentHelperTypeConverter { ...@@ -111,7 +111,7 @@ public final class WebPaymentIntentHelperTypeConverter {
@Nullable PaymentShippingOption shippingOption) { @Nullable PaymentShippingOption shippingOption) {
if (shippingOption == null) return null; if (shippingOption == null) return null;
return new WebPaymentIntentHelperType.PaymentShippingOption(shippingOption.id, return new WebPaymentIntentHelperType.PaymentShippingOption(shippingOption.id,
shippingOption.label, shippingOption.amount.currency, shippingOption.amount.value, shippingOption.label, fromMojoPaymentCurrencyAmount(shippingOption.amount),
shippingOption.selected); shippingOption.selected);
} }
......
...@@ -133,8 +133,8 @@ public class PaymentDetailsUpdateServiceHelperTest { ...@@ -133,8 +133,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
// Populate shipping options. // Populate shipping options.
List<PaymentShippingOption> shippingOptions = new ArrayList<PaymentShippingOption>(); List<PaymentShippingOption> shippingOptions = new ArrayList<PaymentShippingOption>();
shippingOptions.add(new PaymentShippingOption( shippingOptions.add(new PaymentShippingOption("shippingId", "Free shipping",
"shippingId", "Free shipping", "CAD", "0.00", /*selected=*/true)); new PaymentCurrencyAmount("CAD", "0.00"), /*selected=*/true));
// Populate address errors. // Populate address errors.
Bundle bundledShippingAddressErrors = new Bundle(); Bundle bundledShippingAddressErrors = new Bundle();
...@@ -178,11 +178,10 @@ public class PaymentDetailsUpdateServiceHelperTest { ...@@ -178,11 +178,10 @@ public class PaymentDetailsUpdateServiceHelperTest {
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID)); shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID));
Assert.assertEquals("Free shipping", Assert.assertEquals("Free shipping",
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_LABEL)); shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_LABEL));
Assert.assertEquals("CAD", Bundle amount =
shippingOption.getString( shippingOption.getBundle(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT);
PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_CURRENCY)); Assert.assertEquals("CAD", amount.getString(PaymentCurrencyAmount.EXTRA_CURRENCY));
Assert.assertEquals("0.00", Assert.assertEquals("0.00", amount.getString(PaymentCurrencyAmount.EXTRA_VALUE));
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_VALUE));
Assert.assertTrue( Assert.assertTrue(
shippingOption.getBoolean(PaymentShippingOption.EXTRA_SHIPPING_OPTION_SELECTED)); shippingOption.getBoolean(PaymentShippingOption.EXTRA_SHIPPING_OPTION_SELECTED));
......
...@@ -72,7 +72,7 @@ public class WebPaymentIntentHelperTest { ...@@ -72,7 +72,7 @@ public class WebPaymentIntentHelperTest {
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_NAME, "John Smith"); extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_NAME, "John Smith");
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_PHONE, "4169158200"); extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_PHONE, "4169158200");
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_EMAIL, "JohnSmith@google.com"); extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_EMAIL, "JohnSmith@google.com");
extras.putString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID, "shippingId"); extras.putString(WebPaymentIntentHelper.EXTRA_SHIPPING_OPTION_ID, "shippingId");
// Redact the entry with missingField key. // Redact the entry with missingField key.
extras.remove(missingField); extras.remove(missingField);
...@@ -111,8 +111,8 @@ public class WebPaymentIntentHelperTest { ...@@ -111,8 +111,8 @@ public class WebPaymentIntentHelperTest {
/*requestPayerPhone=*/true, /*requestShipping=*/true, /*shippingType=*/"delivery"); /*requestPayerPhone=*/true, /*requestShipping=*/true, /*shippingType=*/"delivery");
List<PaymentShippingOption> shippingOptions = new ArrayList<PaymentShippingOption>(); List<PaymentShippingOption> shippingOptions = new ArrayList<PaymentShippingOption>();
shippingOptions.add(new PaymentShippingOption( shippingOptions.add(new PaymentShippingOption("shippingId", "Free shipping",
"shippingId", "Free shipping", "USD", "0", /*selected=*/true)); new PaymentCurrencyAmount("USD", "0"), /*selected=*/true));
Intent intent = WebPaymentIntentHelper.createPayIntent("package.name", "activity.name", Intent intent = WebPaymentIntentHelper.createPayIntent("package.name", "activity.name",
"payment.request.id", "merchant.name", "schemeless.origin", "payment.request.id", "merchant.name", "schemeless.origin",
...@@ -181,11 +181,10 @@ public class WebPaymentIntentHelperTest { ...@@ -181,11 +181,10 @@ public class WebPaymentIntentHelperTest {
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID)); shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID));
Assert.assertEquals("Free shipping", Assert.assertEquals("Free shipping",
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_LABEL)); shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_LABEL));
Assert.assertEquals("USD", Bundle amount =
shippingOption.getString( shippingOption.getBundle(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT);
PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_CURRENCY)); Assert.assertEquals("USD", amount.getString(PaymentCurrencyAmount.EXTRA_CURRENCY));
Assert.assertEquals("0", Assert.assertEquals("0", amount.getString(PaymentCurrencyAmount.EXTRA_VALUE));
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_VALUE));
Assert.assertTrue( Assert.assertTrue(
shippingOption.getBoolean(PaymentShippingOption.EXTRA_SHIPPING_OPTION_SELECTED)); shippingOption.getBoolean(PaymentShippingOption.EXTRA_SHIPPING_OPTION_SELECTED));
} }
...@@ -682,7 +681,7 @@ public class WebPaymentIntentHelperTest { ...@@ -682,7 +681,7 @@ public class WebPaymentIntentHelperTest {
@Feature({"Payments"}) @Feature({"Payments"})
public void parsePaymentResponseMissingShippingOptionTest() throws Throwable { public void parsePaymentResponseMissingShippingOptionTest() throws Throwable {
Intent intent = createPaymentResponseWithMissingField( Intent intent = createPaymentResponseWithMissingField(
PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID); WebPaymentIntentHelper.EXTRA_SHIPPING_OPTION_ID);
mErrorString = null; mErrorString = null;
WebPaymentIntentHelper.parsePaymentResponse(Activity.RESULT_OK, intent, WebPaymentIntentHelper.parsePaymentResponse(Activity.RESULT_OK, intent,
new PaymentOptions(/*requestPayerName=*/false, /*requestPayerEmail=*/false, new PaymentOptions(/*requestPayerName=*/false, /*requestPayerEmail=*/false,
...@@ -766,7 +765,7 @@ public class WebPaymentIntentHelperTest { ...@@ -766,7 +765,7 @@ public class WebPaymentIntentHelperTest {
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_NAME, "John Smith"); extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_NAME, "John Smith");
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_PHONE, "4169158200"); extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_PHONE, "4169158200");
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_EMAIL, "JohnSmith@google.com"); extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_EMAIL, "JohnSmith@google.com");
extras.putString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID, "shippingId"); extras.putString(WebPaymentIntentHelper.EXTRA_SHIPPING_OPTION_ID, "shippingId");
intent.putExtras(extras); intent.putExtras(extras);
mErrorString = null; mErrorString = null;
WebPaymentIntentHelper.parsePaymentResponse(Activity.RESULT_OK, intent, WebPaymentIntentHelper.parsePaymentResponse(Activity.RESULT_OK, intent,
......
...@@ -72,6 +72,7 @@ public class WebPaymentIntentHelper { ...@@ -72,6 +72,7 @@ public class WebPaymentIntentHelper {
public static final String EXTRA_RESPONSE_PAYER_NAME = "payerName"; public static final String EXTRA_RESPONSE_PAYER_NAME = "payerName";
public static final String EXTRA_RESPONSE_PAYER_EMAIL = "payerEmail"; public static final String EXTRA_RESPONSE_PAYER_EMAIL = "payerEmail";
public static final String EXTRA_RESPONSE_PAYER_PHONE = "payerPhone"; public static final String EXTRA_RESPONSE_PAYER_PHONE = "payerPhone";
public static final String EXTRA_SHIPPING_OPTION_ID = "shippingOptionId";
// Shipping address bundle used in payment response and shippingAddressChange. // Shipping address bundle used in payment response and shippingAddressChange.
public static final String EXTRA_SHIPPING_ADDRESS = "shippingAddress"; public static final String EXTRA_SHIPPING_ADDRESS = "shippingAddress";
...@@ -183,7 +184,7 @@ public class WebPaymentIntentHelper { ...@@ -183,7 +184,7 @@ public class WebPaymentIntentHelper {
} }
String selectedShippingOptionId = requestedPaymentOptions.requestShipping String selectedShippingOptionId = requestedPaymentOptions.requestShipping
? getStringOrEmpty(data, PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID) ? getStringOrEmpty(data, EXTRA_SHIPPING_OPTION_ID)
: ""; : "";
if (requestedPaymentOptions.requestShipping if (requestedPaymentOptions.requestShipping
&& TextUtils.isEmpty(selectedShippingOptionId)) { && TextUtils.isEmpty(selectedShippingOptionId)) {
......
...@@ -180,23 +180,20 @@ public final class WebPaymentIntentHelperType { ...@@ -180,23 +180,20 @@ public final class WebPaymentIntentHelperType {
/** The class that mirrors mojom.PaymentShippingOption. */ /** The class that mirrors mojom.PaymentShippingOption. */
public static final class PaymentShippingOption { public static final class PaymentShippingOption {
public static final String EXTRA_SHIPPING_OPTION_ID = "shippingOptionId"; public static final String EXTRA_SHIPPING_OPTION_ID = "id";
public static final String EXTRA_SHIPPING_OPTION_LABEL = "label"; public static final String EXTRA_SHIPPING_OPTION_LABEL = "label";
public static final String EXTRA_SHIPPING_OPTION_AMOUNT = "amount";
public static final String EXTRA_SHIPPING_OPTION_SELECTED = "selected"; public static final String EXTRA_SHIPPING_OPTION_SELECTED = "selected";
public static final String EXTRA_SHIPPING_OPTION_AMOUNT_CURRENCY = "amountCurrency";
public static final String EXTRA_SHIPPING_OPTION_AMOUNT_VALUE = "amountValue";
public final String id; public final String id;
public final String label; public final String label;
public final String amountCurrency; public final PaymentCurrencyAmount amount;
public final String amountValue;
public final boolean selected; public final boolean selected;
public PaymentShippingOption(String id, String label, String amountCurrency, public PaymentShippingOption(
String amountValue, boolean selected) { String id, String label, PaymentCurrencyAmount amount, boolean selected) {
this.id = id; this.id = id;
this.label = label; this.label = label;
this.amountCurrency = amountCurrency; this.amount = amount;
this.amountValue = amountValue;
this.selected = selected; this.selected = selected;
} }
...@@ -204,8 +201,7 @@ public final class WebPaymentIntentHelperType { ...@@ -204,8 +201,7 @@ public final class WebPaymentIntentHelperType {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(EXTRA_SHIPPING_OPTION_ID, id); bundle.putString(EXTRA_SHIPPING_OPTION_ID, id);
bundle.putString(EXTRA_SHIPPING_OPTION_LABEL, label); bundle.putString(EXTRA_SHIPPING_OPTION_LABEL, label);
bundle.putString(EXTRA_SHIPPING_OPTION_AMOUNT_CURRENCY, amountCurrency); bundle.putBundle(EXTRA_SHIPPING_OPTION_AMOUNT, amount.asBundle());
bundle.putString(EXTRA_SHIPPING_OPTION_AMOUNT_VALUE, amountValue);
bundle.putBoolean(EXTRA_SHIPPING_OPTION_SELECTED, selected); bundle.putBoolean(EXTRA_SHIPPING_OPTION_SELECTED, selected);
return bundle; return bundle;
} }
......
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