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

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

Issue 2413533003: [Payments] Normalize billing address before sending to the merchant. (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentInstrument.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentInstrument.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentInstrument.java
index 62ee4cffa1fa44ede450a96efa8e00bfed5e7d77..d975bd7fc0b0706838f5ce47fde130d408780fc7 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentInstrument.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentInstrument.java
@@ -4,18 +4,20 @@
package org.chromium.chrome.browser.payments;
+import android.os.Handler;
import android.text.TextUtils;
import android.util.JsonWriter;
+import org.json.JSONObject;
+
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.autofill.PersonalDataManager.FullCardRequestDelegate;
+import org.chromium.chrome.browser.autofill.PersonalDataManager.NormalizedAddressRequestDelegate;
import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentItem;
-import org.json.JSONObject;
-
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
@@ -25,13 +27,16 @@ import javax.annotation.Nullable;
/**
* The locally stored credit card payment instrument.
*/
-public class AutofillPaymentInstrument
- extends PaymentInstrument implements FullCardRequestDelegate {
+public class AutofillPaymentInstrument extends PaymentInstrument
+ implements FullCardRequestDelegate, NormalizedAddressRequestDelegate {
private final WebContents mWebContents;
+ private final Handler mHandler = new Handler();
private CreditCard mCard;
private boolean mIsComplete;
+ private String mTempsCvc;
please use gerrit instead 2016/10/17 20:44:18 Let's not put the word "temp" in the variable name
sebsg 2016/10/18 14:38:19 Done.
@Nullable private AutofillProfile mBillingAddress;
@Nullable private DetailsCallback mCallback;
+ private boolean mIsWaitingForBillingNormalization;
/**
* Builds a payment instrument for the given credit card.
@@ -65,17 +70,62 @@ public class AutofillPaymentInstrument
}
@Override
- public void onFullCardDetails(CreditCard card, String cvc) {
+ public void onFullCardDetails(CreditCard unusedCard, String cvc) {
please use gerrit instead 2016/10/17 20:44:18 You can't throw away the card, because it might ha
sebsg 2016/10/18 14:38:19 This will require some rework then, because as it
please use gerrit instead 2016/10/18 17:30:30 The merchant website currently gets the updated ex
sebsg 2016/10/18 22:44:31 Yup! that's why I assigned the new exp month and y
+ // Keep the cvc for after the normalization.
+ mTempsCvc = cvc;
+
+ // Show the processing message while the billing address gets normalized.
+ mCallback.loadingInstrumentDetails();
please use gerrit instead 2016/10/17 20:44:18 This is a good idea. We should keep this, but move
sebsg 2016/10/18 14:38:19 Done.
+
+ if (mBillingAddress != null) {
please use gerrit instead 2016/10/17 20:44:18 mBillingAddress should never be null when getDetai
sebsg 2016/10/18 14:38:19 Done.
+ // Start the normalization task.
+ mIsWaitingForBillingNormalization = true;
+ boolean willNormalizeAsync =
+ PersonalDataManager.getInstance().normalizeAddress(mBillingAddress.getGUID(),
please use gerrit instead 2016/10/17 20:44:18 if willNormalizeAsync is false, then the address i
sebsg 2016/10/18 14:38:19 Right, with the way I did it initially I needed th
+ AutofillAddress.getCountryCode(mBillingAddress), this);
+
+ if (willNormalizeAsync) {
+ // If the normalization was not done synchronously, start a timer to cancel the
+ // asynchronous normalization if it takes too long.
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ onAddressNormalized(null);
+ }
+ }, PersonalDataManager.getInstance().getNormalizationTimeoutMS());
+ }
+
+ // SendInstrumentDetails will be called when the billing address has been normalized or
+ // when the timer has expired.
+ return;
+ }
+
+ // No billing normalization required, return the details now.
+ sendIntrumentDetails();
+ }
+
+ @Override
+ public void onAddressNormalized(AutofillProfile profile) {
+ if (!mIsWaitingForBillingNormalization) return;
please use gerrit instead 2016/10/17 20:44:18 This check is not necessary here, I think. If you
sebsg 2016/10/18 14:38:19 I see what you mean and I have done the flow sugge
+ mIsWaitingForBillingNormalization = false;
+
+ // If the normalization finished first, use the normalized address.
+ if (profile != null) mBillingAddress = profile;
+
+ sendIntrumentDetails();
+ }
+
+ private void sendIntrumentDetails() {
StringWriter stringWriter = new StringWriter();
JsonWriter json = new JsonWriter(stringWriter);
try {
json.beginObject();
- json.name("cardholderName").value(card.getName());
- json.name("cardNumber").value(card.getNumber());
- json.name("expiryMonth").value(card.getMonth());
- json.name("expiryYear").value(card.getYear());
- json.name("cardSecurityCode").value(cvc);
+ json.name("cardholderName").value(mCard.getName());
+ json.name("cardNumber").value(mCard.getNumber());
+ json.name("expiryMonth").value(mCard.getMonth());
+ json.name("expiryYear").value(mCard.getYear());
+ json.name("cardSecurityCode").value(mTempsCvc);
json.name("billingAddress").beginObject();
@@ -110,7 +160,10 @@ public class AutofillPaymentInstrument
return;
}
- mCallback.onInstrumentDetailsReady(card.getBasicCardPaymentType(), stringWriter.toString());
+ mCallback.onInstrumentDetailsReady(
+ mCard.getBasicCardPaymentType(), stringWriter.toString());
+
+ mTempsCvc = "";
please use gerrit instead 2016/10/17 20:44:18 This should be inside of the finally{} block for t
sebsg 2016/10/18 14:38:19 Done.
}
private static String ensureNotNull(@Nullable String value) {
@@ -161,4 +214,9 @@ public class AutofillPaymentInstrument
public CreditCard getCard() {
return mCard;
}
-}
+
+ /** @return The billing address associated with this credit card. */
+ public AutofillProfile getBillingAddress() {
+ return mBillingAddress;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698