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

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

Issue 2558993003: Billing address not required for canMakePayment(). (Closed)
Patch Set: gogerald comments 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.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.content.Context; 7 import android.content.Context;
8 import android.os.Handler; 8 import android.os.Handler;
9 import android.text.TextUtils; 9 import android.text.TextUtils;
10 import android.util.JsonWriter; 10 import android.util.JsonWriter;
(...skipping 24 matching lines...) Expand all
35 public class AutofillPaymentInstrument extends PaymentInstrument 35 public class AutofillPaymentInstrument extends PaymentInstrument
36 implements FullCardRequestDelegate, NormalizedAddressRequestDelegate { 36 implements FullCardRequestDelegate, NormalizedAddressRequestDelegate {
37 private final Context mContext; 37 private final Context mContext;
38 private final WebContents mWebContents; 38 private final WebContents mWebContents;
39 private CreditCard mCard; 39 private CreditCard mCard;
40 private String mSecurityCode; 40 private String mSecurityCode;
41 @Nullable private AutofillProfile mBillingAddress; 41 @Nullable private AutofillProfile mBillingAddress;
42 @Nullable private InstrumentDetailsCallback mCallback; 42 @Nullable private InstrumentDetailsCallback mCallback;
43 private boolean mIsWaitingForBillingNormalization; 43 private boolean mIsWaitingForBillingNormalization;
44 private boolean mIsWaitingForFullCardDetails; 44 private boolean mIsWaitingForFullCardDetails;
45 private boolean mHasValidNumberAndName;
45 46
46 /** 47 /**
47 * Builds a payment instrument for the given credit card. 48 * Builds a payment instrument for the given credit card.
48 * 49 *
49 * @param context The application context. 50 * @param context The application context.
50 * @param webContents The web contents where PaymentRequest was invoked. 51 * @param webContents The web contents where PaymentRequest was invoked.
51 * @param card The autofill card that can be used for payment. 52 * @param card The autofill card that can be used for payment.
52 * @param billingAddress The billing address for the card. 53 * @param billingAddress The billing address for the card.
53 */ 54 */
54 public AutofillPaymentInstrument(Context context, WebContents webContents, C reditCard card, 55 public AutofillPaymentInstrument(Context context, WebContents webContents, C reditCard card,
(...skipping 18 matching lines...) Expand all
73 return result; 74 return result;
74 } 75 }
75 76
76 @Override 77 @Override
77 public void invokePaymentApp(String unusedMerchantName, String unusedOrigin, 78 public void invokePaymentApp(String unusedMerchantName, String unusedOrigin,
78 PaymentItem unusedTotal, List<PaymentItem> unusedCart, 79 PaymentItem unusedTotal, List<PaymentItem> unusedCart,
79 Map<String, PaymentMethodData> unusedMethodData, 80 Map<String, PaymentMethodData> unusedMethodData,
80 InstrumentDetailsCallback callback) { 81 InstrumentDetailsCallback callback) {
81 // The billing address should never be null for a credit card at this po int. 82 // The billing address should never be null for a credit card at this po int.
82 assert mBillingAddress != null; 83 assert mBillingAddress != null;
84 assert AutofillAddress.checkAddressCompletionStatus(mBillingAddress)
85 == AutofillAddress.COMPLETE;
83 assert mIsComplete; 86 assert mIsComplete;
87 assert mHasValidNumberAndName;
84 assert mCallback == null; 88 assert mCallback == null;
85 mCallback = callback; 89 mCallback = callback;
86 90
87 mIsWaitingForBillingNormalization = true; 91 mIsWaitingForBillingNormalization = true;
88 mIsWaitingForFullCardDetails = true; 92 mIsWaitingForFullCardDetails = true;
89 93
90 // Start the billing address normalization. 94 // Start the billing address normalization.
91 PersonalDataManager.getInstance().normalizeAddress( 95 PersonalDataManager.getInstance().normalizeAddress(
92 mBillingAddress.getGUID(), AutofillAddress.getCountryCode(mBilli ngAddress), this); 96 mBillingAddress.getGUID(), AutofillAddress.getCountryCode(mBilli ngAddress), this);
93 97
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 207
204 @Override 208 @Override
205 public void onFullCardError() { 209 public void onFullCardError() {
206 mCallback.onInstrumentDetailsError(); 210 mCallback.onInstrumentDetailsError();
207 mCallback = null; 211 mCallback = null;
208 } 212 }
209 213
210 @Override 214 @Override
211 public void dismissInstrument() {} 215 public void dismissInstrument() {}
212 216
213 /** @return Whether the card is complete and ready to be sent to the merchan t as-is. */ 217 /**
218 * @return Whether the card is complete and ready to be sent to the merchant as-is. If true,
219 * this card has a valid card number, a non-empty name on card, and a comple te billing address.
220 */
214 public boolean isComplete() { 221 public boolean isComplete() {
215 return mIsComplete; 222 return mIsComplete;
216 } 223 }
217 224
218 /** 225 /**
226 * @return Whether the card number is valid and name on card is non-empty. B illing address is
227 * not taken into consideration.
228 */
229 public boolean isValid() {
230 return mHasValidNumberAndName;
231 }
232
233 /**
219 * Updates the instrument and marks it "complete." Called after the user has edited this 234 * Updates the instrument and marks it "complete." Called after the user has edited this
220 * instrument. 235 * instrument.
221 * 236 *
222 * @param card The new credit card to use. The GUID should not cha nge. 237 * @param card The new credit card to use. The GUID should not cha nge.
223 * @param billingAddress The billing address for the card. The GUID should m atch the billing 238 * @param billingAddress The billing address for the card. The GUID should m atch the billing
224 * address ID of the new card to use. 239 * address ID of the new card to use.
225 */ 240 */
226 public void completeInstrument(CreditCard card, AutofillProfile billingAddre ss) { 241 public void completeInstrument(CreditCard card, AutofillProfile billingAddre ss) {
227 assert card != null; 242 assert card != null;
228 assert billingAddress != null; 243 assert billingAddress != null;
229 assert card.getBillingAddressId() != null; 244 assert card.getBillingAddressId() != null;
230 assert card.getBillingAddressId().equals(billingAddress.getGUID()); 245 assert card.getBillingAddressId().equals(billingAddress.getGUID());
231 assert card.getIssuerIconDrawableId() != 0; 246 assert card.getIssuerIconDrawableId() != 0;
232 assert AutofillAddress.checkAddressCompletionStatus(billingAddress) 247 assert AutofillAddress.checkAddressCompletionStatus(billingAddress)
233 == AutofillAddress.COMPLETE; 248 == AutofillAddress.COMPLETE;
234 249
235 mCard = card; 250 mCard = card;
236 mBillingAddress = billingAddress; 251 mBillingAddress = billingAddress;
237 updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber() , card.getName(), 252 updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber() , card.getName(),
238 null, ApiCompatibilityUtils.getDrawable( 253 null, ApiCompatibilityUtils.getDrawable(
239 mContext.getResources(), card.getIssuerIconDrawabl eId())); 254 mContext.getResources(), card.getIssuerIconDrawabl eId()));
240 checkAndUpateCardCompleteness(); 255 checkAndUpateCardCompleteness();
241 assert mIsComplete; 256 assert mIsComplete;
257 assert mHasValidNumberAndName;
242 } 258 }
243 259
244 /** 260 /**
245 * Checks whether card is complete, i.e., can be sent to the merchant as-is without editing 261 * Checks whether card is complete, i.e., can be sent to the merchant as-is without editing
246 * first. And updates edit message, edit title and complete status. 262 * first. And updates edit message, edit title and complete status.
247 * 263 *
248 * For both local and server cards, verifies that the billing address is com plete. For local 264 * For both local and server cards, verifies that the billing address is pre sent. For local
249 * cards also verifies that the card number is valid and the name on card is not empty. 265 * cards also verifies that the card number is valid and the name on card is not empty.
250 * 266 *
267 * Does not check that the billing address has all of the required fields. T his is done
268 * elsewhere to filter out such billing addresses entirely.
269 *
251 * Does not check the expiration date. If the card is expired, the user has the opportunity 270 * Does not check the expiration date. If the card is expired, the user has the opportunity
252 * update the expiration date when providing their CVC in the card unmask di alog. 271 * update the expiration date when providing their CVC in the card unmask di alog.
253 * 272 *
254 * Does not check that the card type is accepted by the merchant. This is do ne elsewhere to 273 * Does not check that the card type is accepted by the merchant. This is do ne elsewhere to
255 * filter out such cards from view entirely. 274 * filter out such cards from view entirely.
256 */ 275 */
257 private void checkAndUpateCardCompleteness() { 276 private void checkAndUpateCardCompleteness() {
258 int editMessageResId = 0; // Zero is the invalid resource Id. 277 int editMessageResId = 0; // Zero is the invalid resource Id.
259 int editTitleResId = R.string.payments_edit_card; 278 int editTitleResId = R.string.payments_edit_card;
260 int invalidFieldsCount = 0; 279 int invalidFieldsCount = 0;
261 280
262 if (mBillingAddress == null) { 281 if (mBillingAddress == null) {
263 editMessageResId = R.string.payments_billing_address_required; 282 editMessageResId = R.string.payments_billing_address_required;
264 editTitleResId = R.string.payments_add_billing_address; 283 editTitleResId = R.string.payments_add_billing_address;
265 invalidFieldsCount++; 284 invalidFieldsCount++;
266 } 285 }
267 286
287 mHasValidNumberAndName = true;
268 if (mCard.getIsLocal()) { 288 if (mCard.getIsLocal()) {
269 if (TextUtils.isEmpty(mCard.getName())) { 289 if (TextUtils.isEmpty(mCard.getName())) {
290 mHasValidNumberAndName = false;
270 editMessageResId = R.string.payments_name_on_card_required; 291 editMessageResId = R.string.payments_name_on_card_required;
271 editTitleResId = R.string.payments_add_name_on_card; 292 editTitleResId = R.string.payments_add_name_on_card;
272 invalidFieldsCount++; 293 invalidFieldsCount++;
273 } 294 }
274 295
275 if (PersonalDataManager.getInstance().getBasicCardPaymentType( 296 if (PersonalDataManager.getInstance().getBasicCardPaymentType(
276 mCard.getNumber().toString(), true) 297 mCard.getNumber().toString(), true)
277 == null) { 298 == null) {
299 mHasValidNumberAndName = false;
278 editMessageResId = R.string.payments_card_number_invalid; 300 editMessageResId = R.string.payments_card_number_invalid;
279 editTitleResId = R.string.payments_add_valid_card_number; 301 editTitleResId = R.string.payments_add_valid_card_number;
280 invalidFieldsCount++; 302 invalidFieldsCount++;
281 } 303 }
282 } 304 }
283 305
284 if (invalidFieldsCount > 1) { 306 if (invalidFieldsCount > 1) {
285 editMessageResId = R.string.payments_more_information_required; 307 editMessageResId = R.string.payments_more_information_required;
286 editTitleResId = R.string.payments_add_more_information; 308 editTitleResId = R.string.payments_add_more_information;
287 } 309 }
288 310
289 mEditMessage = editMessageResId == 0 ? null : mContext.getString(editMes sageResId); 311 mEditMessage = editMessageResId == 0 ? null : mContext.getString(editMes sageResId);
290 mEditTitle = mContext.getString(editTitleResId); 312 mEditTitle = mContext.getString(editTitleResId);
291 mIsComplete = mEditMessage == null; 313 mIsComplete = mEditMessage == null;
292 } 314 }
293 315
294 /** @return The credit card represented by this payment instrument. */ 316 /** @return The credit card represented by this payment instrument. */
295 public CreditCard getCard() { 317 public CreditCard getCard() {
296 return mCard; 318 return mCard;
297 } 319 }
298 320
299 /** @return The billing address associated with this credit card. */ 321 /** @return The billing address associated with this credit card. */
300 public AutofillProfile getBillingAddress() { 322 public AutofillProfile getBillingAddress() {
301 return mBillingAddress; 323 return mBillingAddress;
302 } 324 }
303 } 325 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698