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 {
@Nullable PaymentShippingOption shippingOption) {
if (shippingOption == null) return null;
return new WebPaymentIntentHelperType.PaymentShippingOption(shippingOption.id,
shippingOption.label, shippingOption.amount.currency, shippingOption.amount.value,
shippingOption.label, fromMojoPaymentCurrencyAmount(shippingOption.amount),
shippingOption.selected);
}
......
......@@ -133,8 +133,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
// Populate shipping options.
List<PaymentShippingOption> shippingOptions = new ArrayList<PaymentShippingOption>();
shippingOptions.add(new PaymentShippingOption(
"shippingId", "Free shipping", "CAD", "0.00", /*selected=*/true));
shippingOptions.add(new PaymentShippingOption("shippingId", "Free shipping",
new PaymentCurrencyAmount("CAD", "0.00"), /*selected=*/true));
// Populate address errors.
Bundle bundledShippingAddressErrors = new Bundle();
......@@ -178,11 +178,10 @@ public class PaymentDetailsUpdateServiceHelperTest {
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID));
Assert.assertEquals("Free shipping",
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_LABEL));
Assert.assertEquals("CAD",
shippingOption.getString(
PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_CURRENCY));
Assert.assertEquals("0.00",
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_VALUE));
Bundle amount =
shippingOption.getBundle(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT);
Assert.assertEquals("CAD", amount.getString(PaymentCurrencyAmount.EXTRA_CURRENCY));
Assert.assertEquals("0.00", amount.getString(PaymentCurrencyAmount.EXTRA_VALUE));
Assert.assertTrue(
shippingOption.getBoolean(PaymentShippingOption.EXTRA_SHIPPING_OPTION_SELECTED));
......
......@@ -72,7 +72,7 @@ public class WebPaymentIntentHelperTest {
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_NAME, "John Smith");
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_PHONE, "4169158200");
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.
extras.remove(missingField);
......@@ -111,8 +111,8 @@ public class WebPaymentIntentHelperTest {
/*requestPayerPhone=*/true, /*requestShipping=*/true, /*shippingType=*/"delivery");
List<PaymentShippingOption> shippingOptions = new ArrayList<PaymentShippingOption>();
shippingOptions.add(new PaymentShippingOption(
"shippingId", "Free shipping", "USD", "0", /*selected=*/true));
shippingOptions.add(new PaymentShippingOption("shippingId", "Free shipping",
new PaymentCurrencyAmount("USD", "0"), /*selected=*/true));
Intent intent = WebPaymentIntentHelper.createPayIntent("package.name", "activity.name",
"payment.request.id", "merchant.name", "schemeless.origin",
......@@ -181,11 +181,10 @@ public class WebPaymentIntentHelperTest {
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID));
Assert.assertEquals("Free shipping",
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_LABEL));
Assert.assertEquals("USD",
shippingOption.getString(
PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_CURRENCY));
Assert.assertEquals("0",
shippingOption.getString(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT_VALUE));
Bundle amount =
shippingOption.getBundle(PaymentShippingOption.EXTRA_SHIPPING_OPTION_AMOUNT);
Assert.assertEquals("USD", amount.getString(PaymentCurrencyAmount.EXTRA_CURRENCY));
Assert.assertEquals("0", amount.getString(PaymentCurrencyAmount.EXTRA_VALUE));
Assert.assertTrue(
shippingOption.getBoolean(PaymentShippingOption.EXTRA_SHIPPING_OPTION_SELECTED));
}
......@@ -682,7 +681,7 @@ public class WebPaymentIntentHelperTest {
@Feature({"Payments"})
public void parsePaymentResponseMissingShippingOptionTest() throws Throwable {
Intent intent = createPaymentResponseWithMissingField(
PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID);
WebPaymentIntentHelper.EXTRA_SHIPPING_OPTION_ID);
mErrorString = null;
WebPaymentIntentHelper.parsePaymentResponse(Activity.RESULT_OK, intent,
new PaymentOptions(/*requestPayerName=*/false, /*requestPayerEmail=*/false,
......@@ -766,7 +765,7 @@ public class WebPaymentIntentHelperTest {
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_NAME, "John Smith");
extras.putString(WebPaymentIntentHelper.EXTRA_RESPONSE_PAYER_PHONE, "4169158200");
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);
mErrorString = null;
WebPaymentIntentHelper.parsePaymentResponse(Activity.RESULT_OK, intent,
......
......@@ -72,6 +72,7 @@ public class WebPaymentIntentHelper {
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_PHONE = "payerPhone";
public static final String EXTRA_SHIPPING_OPTION_ID = "shippingOptionId";
// Shipping address bundle used in payment response and shippingAddressChange.
public static final String EXTRA_SHIPPING_ADDRESS = "shippingAddress";
......@@ -183,7 +184,7 @@ public class WebPaymentIntentHelper {
}
String selectedShippingOptionId = requestedPaymentOptions.requestShipping
? getStringOrEmpty(data, PaymentShippingOption.EXTRA_SHIPPING_OPTION_ID)
? getStringOrEmpty(data, EXTRA_SHIPPING_OPTION_ID)
: "";
if (requestedPaymentOptions.requestShipping
&& TextUtils.isEmpty(selectedShippingOptionId)) {
......
......@@ -180,23 +180,20 @@ public final class WebPaymentIntentHelperType {
/** The class that mirrors mojom.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_AMOUNT = "amount";
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 label;
public final String amountCurrency;
public final String amountValue;
public final PaymentCurrencyAmount amount;
public final boolean selected;
public PaymentShippingOption(String id, String label, String amountCurrency,
String amountValue, boolean selected) {
public PaymentShippingOption(
String id, String label, PaymentCurrencyAmount amount, boolean selected) {
this.id = id;
this.label = label;
this.amountCurrency = amountCurrency;
this.amountValue = amountValue;
this.amount = amount;
this.selected = selected;
}
......@@ -204,8 +201,7 @@ public final class WebPaymentIntentHelperType {
Bundle bundle = new Bundle();
bundle.putString(EXTRA_SHIPPING_OPTION_ID, id);
bundle.putString(EXTRA_SHIPPING_OPTION_LABEL, label);
bundle.putString(EXTRA_SHIPPING_OPTION_AMOUNT_CURRENCY, amountCurrency);
bundle.putString(EXTRA_SHIPPING_OPTION_AMOUNT_VALUE, amountValue);
bundle.putBundle(EXTRA_SHIPPING_OPTION_AMOUNT, amount.asBundle());
bundle.putBoolean(EXTRA_SHIPPING_OPTION_SELECTED, selected);
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