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

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

Issue 2097713002: Specify billing address for autofill cards in PaymentRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments 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 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 7d576d83836c37c8aeb7d964dc8a2fdc65f12045..682acfee84d655cc4ab2befe179c2182d26ce4e1 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,9 +4,11 @@
package org.chromium.chrome.browser.payments;
+import android.text.TextUtils;
import android.util.JsonWriter;
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.content_public.browser.WebContents;
@@ -18,6 +20,8 @@ import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
+import javax.annotation.Nullable;
+
/**
* The locally stored credit card payment instrument.
*/
@@ -25,19 +29,23 @@ public class AutofillPaymentInstrument
extends PaymentInstrument implements FullCardRequestDelegate {
private final WebContents mWebContents;
private final CreditCard mCard;
- private DetailsCallback mCallback;
+ @Nullable private AutofillProfile mBillingAddress;
+ @Nullable private DetailsCallback mCallback;
/**
* Builds a payment instrument for the given credit card.
*
- * @param webContents The web contents where PaymentRequest was invoked.
- * @param card The autofill card that can be used for payment.
+ * @param webContents The web contents where PaymentRequest was invoked.
+ * @param card The autofill card that can be used for payment.
+ * @param billingAddress The optional billing address for the card.
*/
- public AutofillPaymentInstrument(WebContents webContents, CreditCard card) {
+ public AutofillPaymentInstrument(
+ WebContents webContents, CreditCard card, @Nullable AutofillProfile billingAddress) {
super(card.getGUID(), card.getObfuscatedNumber(), card.getName(),
card.getIssuerIconDrawableId());
mWebContents = webContents;
mCard = card;
+ mBillingAddress = billingAddress;
}
@Override
@@ -59,11 +67,43 @@ public class AutofillPaymentInstrument
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);
+
+ if (mBillingAddress != null) {
+ json.name("billingAddress").beginObject();
+
+ json.name("country").value(ensureNotNull(mBillingAddress.getCountryCode()));
+ json.name("region").value(ensureNotNull(mBillingAddress.getRegion()));
+ json.name("city").value(ensureNotNull(mBillingAddress.getLocality()));
+ json.name("dependentLocality")
+ .value(ensureNotNull(mBillingAddress.getDependentLocality()));
+
+ json.name("addressLine").beginArray();
+ String multipleLines = ensureNotNull(mBillingAddress.getStreetAddress());
+ if (!TextUtils.isEmpty(multipleLines)) {
+ String[] lines = multipleLines.split("\n");
+ for (int i = 0; i < lines.length; i++) {
+ json.value(lines[i]);
+ }
+ }
+ json.endArray();
+
+ json.name("postalCode").value(ensureNotNull(mBillingAddress.getPostalCode()));
+ json.name("sortingCode").value(ensureNotNull(mBillingAddress.getSortingCode()));
+ json.name("languageCode").value(ensureNotNull(mBillingAddress.getLanguageCode()));
+ json.name("organization").value(ensureNotNull(mBillingAddress.getCompanyName()));
+ json.name("recipient").value(ensureNotNull(mBillingAddress.getFullName()));
+ json.name("careOf").value("");
+ json.name("phone").value(ensureNotNull(mBillingAddress.getPhoneNumber()));
+
+ json.endObject();
+ }
+
json.endObject();
} catch (IOException e) {
mCallback.onInstrumentDetailsError();
@@ -73,6 +113,10 @@ public class AutofillPaymentInstrument
mCallback.onInstrumentDetailsReady(card.getBasicCardPaymentType(), stringWriter.toString());
}
+ private static String ensureNotNull(@Nullable String value) {
+ return value == null ? "" : value;
+ }
+
@Override
public void onFullCardError() {
mCallback.onInstrumentDetailsError();

Powered by Google App Engine
This is Rietveld 408576698