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

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

Issue 1931233002: Implement PaymentRequestUpdateEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicit-shipping
Patch Set: Rebase Created 4 years, 7 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/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java » ('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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 disconnectFromClientWithDebugMessage("PaymentRequest.show() called m ore than once."); 147 disconnectFromClientWithDebugMessage("PaymentRequest.show() called m ore than once.");
148 return; 148 return;
149 } 149 }
150 150
151 mSupportedMethods = getValidatedSupportedMethods(supportedMethods); 151 mSupportedMethods = getValidatedSupportedMethods(supportedMethods);
152 if (mSupportedMethods == null) { 152 if (mSupportedMethods == null) {
153 disconnectFromClientWithDebugMessage("Invalid payment methods"); 153 disconnectFromClientWithDebugMessage("Invalid payment methods");
154 return; 154 return;
155 } 155 }
156 156
157 mLineItems = getValidatedLineItems(details); 157 if (!setLineItemsAndShippingOptionsOrDisconnectFromClient(details)) retu rn;
158 if (mLineItems == null) {
159 disconnectFromClientWithDebugMessage("Invalid line items");
160 return;
161 }
162 mPaymentItems = Arrays.asList(details.items);
163
164 mShippingOptions =
165 getValidatedShippingOptions(details.items[0].amount.currencyCode , details);
166 if (mShippingOptions == null) {
167 disconnectFromClientWithDebugMessage("Invalid shipping options");
168 return;
169 }
170 158
171 // If the merchant requests shipping and does not provide shipping optio ns here, then the 159 // If the merchant requests shipping and does not provide shipping optio ns here, then the
172 // merchant needs the shipping address to calculate shipping price and a vailability. 160 // merchant needs the shipping address to calculate shipping price and a vailability.
173 boolean requestShipping = options != null && options.requestShipping; 161 boolean requestShipping = options != null && options.requestShipping;
174 mMerchantNeedsShippingAddress = requestShipping && mShippingOptions.isEm pty(); 162 mMerchantNeedsShippingAddress = requestShipping && mShippingOptions.isEm pty();
175 163
176 mData = getValidatedData(mSupportedMethods, stringifiedData); 164 mData = getValidatedData(mSupportedMethods, stringifiedData);
177 if (mData == null) { 165 if (mData == null) {
178 disconnectFromClientWithDebugMessage("Invalid payment method specifi c data"); 166 disconnectFromClientWithDebugMessage("Invalid payment method specifi c data");
179 return; 167 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 205 }
218 } 206 }
219 207
220 if (!isGettingInstruments) mPaymentMethods = new SectionInformation(); 208 if (!isGettingInstruments) mPaymentMethods = new SectionInformation();
221 209
222 mUI = PaymentRequestUI.show(mContext, this, requestShipping, mMerchantNa me, mOrigin); 210 mUI = PaymentRequestUI.show(mContext, this, requestShipping, mMerchantNa me, mOrigin);
223 if (mFavicon != null) mUI.setTitleBitmap(mFavicon); 211 if (mFavicon != null) mUI.setTitleBitmap(mFavicon);
224 mFavicon = null; 212 mFavicon = null;
225 } 213 }
226 214
215 /**
216 * Called by merchant to update the shipping options and line items after th e user has selected
217 * their shipping address or shipping option.
218 */
219 @Override
220 public void updateWith(PaymentDetails details) {
221 if (mClient == null) return;
222
223 if (mUI == null) {
224 disconnectFromClientWithDebugMessage(
225 "PaymentRequestUpdateEvent.updateWith() called without Payme ntRequest.show()");
226 return;
227 }
228
229 if (!setLineItemsAndShippingOptionsOrDisconnectFromClient(details)) retu rn;
230
231 // Empty shipping options means the merchant cannot ship to the user's s elected shipping
232 // address.
233 if (mShippingOptions.isEmpty() && !mMerchantNeedsShippingAddress) {
234 disconnectFromClientWithDebugMessage("Merchant indicates inablity to ship although "
235 + "originally indicated that can ship anywhere");
236 }
237
238 mUI.updateOrderSummarySection(mLineItems);
239 mUI.updateShippingOptionsSection(mShippingOptions);
240 }
241
242 private boolean setLineItemsAndShippingOptionsOrDisconnectFromClient(Payment Details details) {
243 mLineItems = getValidatedLineItems(details);
244 if (mLineItems == null) {
245 disconnectFromClientWithDebugMessage("Invalid line items");
246 return false;
247 }
248 mPaymentItems = Arrays.asList(details.items);
249
250 mShippingOptions =
251 getValidatedShippingOptions(details.items[0].amount.currencyCode , details);
252 if (mShippingOptions == null) {
253 disconnectFromClientWithDebugMessage("Invalid shipping options");
254 return false;
255 }
256
257 return true;
258 }
259
227 private HashSet<String> getValidatedSupportedMethods(String[] methods) { 260 private HashSet<String> getValidatedSupportedMethods(String[] methods) {
228 // Payment methods are required. 261 // Payment methods are required.
229 if (methods == null || methods.length == 0) return null; 262 if (methods == null || methods.length == 0) return null;
230 263
231 HashSet<String> result = new HashSet<>(); 264 HashSet<String> result = new HashSet<>();
232 for (int i = 0; i < methods.length; i++) { 265 for (int i = 0; i < methods.length; i++) {
233 // Payment methods should be non-empty. 266 // Payment methods should be non-empty.
234 if (TextUtils.isEmpty(methods[i])) return null; 267 if (TextUtils.isEmpty(methods[i])) return null;
235 result.add(methods[i]); 268 result.add(methods[i]);
236 } 269 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 if (mPaymentMethods != null) { 592 if (mPaymentMethods != null) {
560 for (int i = 0; i < mPaymentMethods.getSize(); i++) { 593 for (int i = 0; i < mPaymentMethods.getSize(); i++) {
561 PaymentOption option = mPaymentMethods.getItem(i); 594 PaymentOption option = mPaymentMethods.getItem(i);
562 assert option instanceof PaymentInstrument; 595 assert option instanceof PaymentInstrument;
563 ((PaymentInstrument) option).dismiss(); 596 ((PaymentInstrument) option).dismiss();
564 } 597 }
565 mPaymentMethods = null; 598 mPaymentMethods = null;
566 } 599 }
567 } 600 }
568 } 601 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698