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

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

Issue 2028603004: Rename 'items' into 'displayItems' in PaymentDetails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/android/payments/dynamic_shipping.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.os.Handler; 9 import android.os.Handler;
10 import android.text.TextUtils; 10 import android.text.TextUtils;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 private final Handler mHandler = new Handler(); 63 private final Handler mHandler = new Handler();
64 64
65 private Activity mContext; 65 private Activity mContext;
66 private String mMerchantName; 66 private String mMerchantName;
67 private String mOrigin; 67 private String mOrigin;
68 private Bitmap mFavicon; 68 private Bitmap mFavicon;
69 private List<PaymentApp> mApps; 69 private List<PaymentApp> mApps;
70 private PaymentRequestClient mClient; 70 private PaymentRequestClient mClient;
71 private Set<String> mSupportedMethods; 71 private Set<String> mSupportedMethods;
72 private List<LineItem> mLineItems; 72 private List<LineItem> mLineItems;
73 private List<PaymentItem> mPaymentItems; 73 private List<PaymentItem> mDisplayItems;
74 private List<ShippingOption> mShippingOptions; 74 private List<ShippingOption> mShippingOptions;
75 private SectionInformation mShippingOptionsSection; 75 private SectionInformation mShippingOptionsSection;
76 private JSONObject mData; 76 private JSONObject mData;
77 private SectionInformation mShippingAddressesSection; 77 private SectionInformation mShippingAddressesSection;
78 private List<PaymentApp> mPendingApps; 78 private List<PaymentApp> mPendingApps;
79 private List<PaymentInstrument> mPendingInstruments; 79 private List<PaymentInstrument> mPendingInstruments;
80 private SectionInformation mPaymentMethodsSection; 80 private SectionInformation mPaymentMethodsSection;
81 private PaymentRequestUI mUI; 81 private PaymentRequestUI mUI;
82 private Callback<PaymentInformation> mPaymentInformationCallback; 82 private Callback<PaymentInformation> mPaymentInformationCallback;
83 private Pattern mRegionCodePattern; 83 private Pattern mRegionCodePattern;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 boolean isGettingInstruments = false; 199 boolean isGettingInstruments = false;
200 200
201 for (int i = 0; i < mApps.size(); i++) { 201 for (int i = 0; i < mApps.size(); i++) {
202 PaymentApp app = mApps.get(i); 202 PaymentApp app = mApps.get(i);
203 Set<String> appMethods = app.getSupportedMethodNames(); 203 Set<String> appMethods = app.getSupportedMethodNames();
204 appMethods.retainAll(mSupportedMethods); 204 appMethods.retainAll(mSupportedMethods);
205 if (appMethods.isEmpty()) { 205 if (appMethods.isEmpty()) {
206 mPendingApps.remove(app); 206 mPendingApps.remove(app);
207 } else { 207 } else {
208 isGettingInstruments = true; 208 isGettingInstruments = true;
209 app.getInstruments(mPaymentItems, this); 209 app.getInstruments(mDisplayItems, this);
210 } 210 }
211 } 211 }
212 212
213 if (!isGettingInstruments) { 213 if (!isGettingInstruments) {
214 mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.TYP E_PAYMENT_METHODS); 214 mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.TYP E_PAYMENT_METHODS);
215 } 215 }
216 216
217 mUI = PaymentRequestUI.show(mContext, this, requestShipping, mMerchantNa me, mOrigin); 217 mUI = PaymentRequestUI.show(mContext, this, requestShipping, mMerchantNa me, mOrigin);
218 if (mFavicon != null) mUI.setTitleBitmap(mFavicon); 218 if (mFavicon != null) mUI.setTitleBitmap(mFavicon);
219 mFavicon = null; 219 mFavicon = null;
(...skipping 25 matching lines...) Expand all
245 mUI.updateOrderSummarySection(mLineItems); 245 mUI.updateOrderSummarySection(mLineItems);
246 mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, mShippingOptio nsSection); 246 mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, mShippingOptio nsSection);
247 } 247 }
248 248
249 private boolean setLineItemsAndShippingOptionsOrDisconnectFromClient(Payment Details details) { 249 private boolean setLineItemsAndShippingOptionsOrDisconnectFromClient(Payment Details details) {
250 mLineItems = getValidatedLineItems(details); 250 mLineItems = getValidatedLineItems(details);
251 if (mLineItems == null) { 251 if (mLineItems == null) {
252 disconnectFromClientWithDebugMessage("Invalid line items"); 252 disconnectFromClientWithDebugMessage("Invalid line items");
253 return false; 253 return false;
254 } 254 }
255 mPaymentItems = Arrays.asList(details.items); 255 mDisplayItems = Arrays.asList(details.displayItems);
256 256
257 mShippingOptionsSection = 257 mShippingOptionsSection =
258 getValidatedShippingOptions(details.items[0].amount.currencyCode , details); 258 getValidatedShippingOptions(details.displayItems[0].amount.curre ncyCode, details);
259 if (mShippingOptionsSection == null) { 259 if (mShippingOptionsSection == null) {
260 disconnectFromClientWithDebugMessage("Invalid shipping options"); 260 disconnectFromClientWithDebugMessage("Invalid shipping options");
261 return false; 261 return false;
262 } 262 }
263 mShippingOptions = Arrays.asList(details.shippingOptions); 263 mShippingOptions = Arrays.asList(details.shippingOptions);
264 264
265 return true; 265 return true;
266 } 266 }
267 267
268 private HashSet<String> getValidatedSupportedMethods(String[] methods) { 268 private HashSet<String> getValidatedSupportedMethods(String[] methods) {
269 // Payment methods are required. 269 // Payment methods are required.
270 if (methods == null || methods.length == 0) return null; 270 if (methods == null || methods.length == 0) return null;
271 271
272 HashSet<String> result = new HashSet<>(); 272 HashSet<String> result = new HashSet<>();
273 for (int i = 0; i < methods.length; i++) { 273 for (int i = 0; i < methods.length; i++) {
274 // Payment methods should be non-empty. 274 // Payment methods should be non-empty.
275 if (TextUtils.isEmpty(methods[i])) return null; 275 if (TextUtils.isEmpty(methods[i])) return null;
276 result.add(methods[i]); 276 result.add(methods[i]);
277 } 277 }
278 278
279 return result; 279 return result;
280 } 280 }
281 281
282 private List<LineItem> getValidatedLineItems(PaymentDetails details) { 282 private List<LineItem> getValidatedLineItems(PaymentDetails details) {
283 // Line items are required. 283 // Line items are required.
284 if (details == null || details.items == null || details.items.length == 0) return null; 284 if (details == null || details.displayItems == null || details.displayIt ems.length == 0) {
285 return null;
286 }
285 287
286 for (int i = 0; i < details.items.length; i++) { 288 for (int i = 0; i < details.displayItems.length; i++) {
287 PaymentItem item = details.items[i]; 289 PaymentItem item = details.displayItems[i];
288 // "id", "label", "currencyCode", and "value" should be non-empty. 290 // "id", "label", "currencyCode", and "value" should be non-empty.
289 if (item == null || TextUtils.isEmpty(item.label) || item.amount == null 291 if (item == null || TextUtils.isEmpty(item.label) || item.amount == null
290 || TextUtils.isEmpty(item.amount.currencyCode) 292 || TextUtils.isEmpty(item.amount.currencyCode)
291 || TextUtils.isEmpty(item.amount.value)) { 293 || TextUtils.isEmpty(item.amount.value)) {
292 return null; 294 return null;
293 } 295 }
294 } 296 }
295 297
296 CurrencyStringFormatter formatter = new CurrencyStringFormatter( 298 CurrencyStringFormatter formatter = new CurrencyStringFormatter(
297 details.items[0].amount.currencyCode, Locale.getDefault()); 299 details.displayItems[0].amount.currencyCode, Locale.getDefault() );
298 300
299 // Currency codes should be in correct format. 301 // Currency codes should be in correct format.
300 if (!formatter.isValidAmountCurrencyCode(details.items[0].amount.currenc yCode)) return null; 302 if (!formatter.isValidAmountCurrencyCode(details.displayItems[0].amount. currencyCode)) {
303 return null;
304 }
301 305
302 List<LineItem> result = new ArrayList<>(details.items.length); 306 List<LineItem> result = new ArrayList<>(details.displayItems.length);
303 for (int i = 0; i < details.items.length; i++) { 307 for (int i = 0; i < details.displayItems.length; i++) {
304 PaymentItem item = details.items[i]; 308 PaymentItem item = details.displayItems[i];
305 309
306 // All currency codes must match. 310 // All currency codes must match.
307 if (!item.amount.currencyCode.equals(details.items[0].amount.currenc yCode)) return null; 311 if (!item.amount.currencyCode.equals(details.displayItems[0].amount. currencyCode)) {
312 return null;
313 }
308 314
309 // Value should be in correct format. 315 // Value should be in correct format.
310 if (!formatter.isValidAmountValue(item.amount.value)) return null; 316 if (!formatter.isValidAmountValue(item.amount.value)) return null;
311 317
312 result.add(new LineItem(item.label, 318 result.add(new LineItem(item.label,
313 i == details.items.length - 1 ? item.amount.currencyCode : " ", 319 i == details.displayItems.length - 1 ? item.amount.currencyC ode : "",
314 formatter.format(item.amount.value))); 320 formatter.format(item.amount.value)));
315 } 321 }
316 322
317 return result; 323 return result;
318 } 324 }
319 325
320 private SectionInformation getValidatedShippingOptions( 326 private SectionInformation getValidatedShippingOptions(
321 String itemsCurrencyCode, PaymentDetails details) { 327 String itemsCurrencyCode, PaymentDetails details) {
322 // Shipping options are optional. 328 // Shipping options are optional.
323 if (details.shippingOptions == null || details.shippingOptions.length == 0) { 329 if (details.shippingOptions == null || details.shippingOptions.length == 0) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 PreferencesLauncher.launchSettingsPage( 483 PreferencesLauncher.launchSettingsPage(
478 mContext, AutofillCreditCardEditor.class.getName()); 484 mContext, AutofillCreditCardEditor.class.getName());
479 } 485 }
480 } 486 }
481 487
482 @Override 488 @Override
483 public void onPayClicked(PaymentOption selectedShippingAddress, 489 public void onPayClicked(PaymentOption selectedShippingAddress,
484 PaymentOption selectedShippingOption, PaymentOption selectedPaymentM ethod) { 490 PaymentOption selectedShippingOption, PaymentOption selectedPaymentM ethod) {
485 assert selectedPaymentMethod instanceof PaymentInstrument; 491 assert selectedPaymentMethod instanceof PaymentInstrument;
486 PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod ; 492 PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod ;
487 instrument.getDetails(mMerchantName, mOrigin, mPaymentItems, 493 instrument.getDetails(mMerchantName, mOrigin, mDisplayItems,
488 mData.optJSONObject(instrument.getMethodName()), this); 494 mData.optJSONObject(instrument.getMethodName()), this);
489 } 495 }
490 496
491 @Override 497 @Override
492 public void onDismiss() { 498 public void onDismiss() {
493 disconnectFromClientWithDebugMessage("Dialog dismissed"); 499 disconnectFromClientWithDebugMessage("Dialog dismissed");
494 closeUI(false); 500 closeUI(false);
495 } 501 }
496 502
497 /** 503 /**
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 626 }
621 mPaymentMethodsSection = null; 627 mPaymentMethodsSection = null;
622 } 628 }
623 } 629 }
624 630
625 private void closeClient() { 631 private void closeClient() {
626 if (mClient != null) mClient.close(); 632 if (mClient != null) mClient.close();
627 mClient = null; 633 mClient = null;
628 } 634 }
629 } 635 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/android/payments/dynamic_shipping.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698