Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3803)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java

Issue 2542493004: Show modified total price for payment instruments. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
index ec1e158d0f3527b66fb3dec953855bf92f0f135f..47d56439d7b2ea8ced1e10dfd384b31a04d160a5 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
@@ -219,6 +219,12 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
private List<PaymentItem> mRawLineItems;
/**
+ * A mapping from method names to modified totals. Used to display modified totals for each
+ * payment instrument.
+ */
+ private Map<String, PaymentItem> mModifiedTotals;
+
+ /**
* The UI model of the shopping cart, including the total. Each item includes a label and a
* price string. This data is passed to the UI.
*/
@@ -244,6 +250,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
private ContactEditor mContactEditor;
private boolean mHasRecordedAbortReason;
private boolean mQueriedCanMakeActivePayment;
+ private CurrencyStringFormatter mFormatter;
/** True if any of the requested payment methods are supported. */
private boolean mArePaymentMethodsSupported;
@@ -596,25 +603,55 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
String totalCurrency = details.total.amount.currency;
- CurrencyStringFormatter formatter =
- new CurrencyStringFormatter(totalCurrency, Locale.getDefault());
+ if (mFormatter == null) {
+ mFormatter = new CurrencyStringFormatter(totalCurrency, Locale.getDefault());
+ }
// Total is never pending.
LineItem uiTotal = new LineItem(
- details.total.label, formatter.getFormattedCurrencyCode(),
- formatter.format(details.total.amount.value), /* isPending */ false);
+ details.total.label, mFormatter.getFormattedCurrencyCode(),
+ mFormatter.format(details.total.amount.value), /* isPending */ false);
- List<LineItem> uiLineItems = getLineItems(details.displayItems, totalCurrency, formatter);
+ List<LineItem> uiLineItems = getLineItems(details.displayItems, totalCurrency, mFormatter);
mUiShoppingCart = new ShoppingCart(uiTotal, uiLineItems);
mRawTotal = details.total;
mRawLineItems = Collections.unmodifiableList(Arrays.asList(details.displayItems));
- mUiShippingOptions = getShippingOptions(details.shippingOptions, totalCurrency, formatter);
+ mUiShippingOptions = getShippingOptions(details.shippingOptions, totalCurrency, mFormatter);
+
+ for (int i = 0; i < details.modifiers.length; i++) {
+ PaymentItem total = details.modifiers[i].total;
+ String[] methods = details.modifiers[i].methodData.supportedMethods;
+ if (total != null) {
+ for (int j = 0; j < methods.length; j++) {
+ if (mModifiedTotals == null) mModifiedTotals = new ArrayMap<>();
+ mModifiedTotals.put(methods[j], total);
+ }
+ }
+ }
+
+ updateInstrumentModifiedTotals();
return true;
}
+ /** Updates the modified totals for payment instruments. */
+ private void updateInstrumentModifiedTotals() {
+ if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS_MODIFIERS)) return;
+ if (mModifiedTotals == null) return;
+ if (mPaymentMethodsSection == null) return;
+
+ for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) {
+ PaymentOption option = mPaymentMethodsSection.getItem(i);
+ assert option instanceof PaymentInstrument;
+ PaymentInstrument instrument = (PaymentInstrument) option;
+ PaymentItem modifiedTotal = mModifiedTotals.get(instrument.getInstrumentMethodName());
+ instrument.setModifiedTotal(
+ modifiedTotal == null ? null : mFormatter.format(modifiedTotal.amount.value));
+ }
+ }
+
/**
* Returns true if all fields in the payment item are non-null and non-empty.
*
@@ -1127,6 +1164,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
mPendingInstruments.clear();
+ updateInstrumentModifiedTotals();
+
// UI has requested the full list of payment instruments. Provide it now.
if (mPaymentInformationCallback != null) providePaymentInformation();
}

Powered by Google App Engine
This is Rietveld 408576698