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 aa705adb7d819b84f6e6053ba388ddfb3f41dd1c..822172d9b88a648a251941db86c83f01c6dc43dc 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 |
@@ -28,7 +28,8 @@ import javax.annotation.Nullable; |
public class AutofillPaymentInstrument |
extends PaymentInstrument implements FullCardRequestDelegate { |
private final WebContents mWebContents; |
- private final CreditCard mCard; |
+ private CreditCard mCard; |
+ private boolean mIsComplete; |
@Nullable private AutofillProfile mBillingAddress; |
@Nullable private DetailsCallback mCallback; |
@@ -37,7 +38,7 @@ public class AutofillPaymentInstrument |
* |
* @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. |
+ * @param billingAddress The billing address for the card. |
*/ |
public AutofillPaymentInstrument( |
WebContents webContents, CreditCard card, @Nullable AutofillProfile billingAddress) { |
@@ -45,6 +46,7 @@ public class AutofillPaymentInstrument |
card.getIssuerIconDrawableId()); |
mWebContents = webContents; |
mCard = card; |
+ mIsComplete = false; |
mBillingAddress = billingAddress; |
} |
@@ -56,9 +58,15 @@ public class AutofillPaymentInstrument |
@Override |
public void getDetails(String unusedMerchantName, String unusedOrigin, PaymentItem unusedTotal, |
List<PaymentItem> unusedCart, JSONObject unusedDetails, DetailsCallback callback) { |
+ assert mIsComplete; |
assert mCallback == null; |
mCallback = callback; |
- PersonalDataManager.getInstance().getFullCard(mWebContents, mCard.getGUID(), this); |
+ if (mCard.getGUID().isEmpty()) { |
+ PersonalDataManager.getInstance().getFullTemporaryCard(mWebContents, mCard.getNumber(), |
+ mCard.getName(), mCard.getMonth(), mCard.getYear(), this); |
+ } else { |
+ PersonalDataManager.getInstance().getFullCard(mWebContents, mCard.getGUID(), this); |
+ } |
} |
@Override |
@@ -74,35 +82,33 @@ public class AutofillPaymentInstrument |
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("billingAddress").beginObject(); |
- 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.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.endObject(); |
+ 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) { |
@@ -125,4 +131,40 @@ public class AutofillPaymentInstrument |
@Override |
public void dismiss() {} |
+ |
+ /** @return Whether the card is complete and ready to be sent to the merchant as-is. */ |
+ public boolean isComplete() { |
+ return mIsComplete; |
+ } |
+ |
+ /** Marks this card complete and ready to be sent to the merchant without editing first. */ |
+ public void setIsComplete() { |
+ mIsComplete = true; |
+ } |
+ |
+ /** |
+ * Updates the instrument and marks it "complete." Called after the user has edited this |
+ * instrument. |
+ * |
+ * @param card The new credit card to use. The GUID should not change. |
+ * @param billingAddress The billing address for the card. The GUID should match the billing |
+ * address ID of the new card to use. |
+ */ |
+ public void completeInstrument(CreditCard card, AutofillProfile billingAddress) { |
+ assert card != null; |
+ assert billingAddress != null; |
+ assert card.getBillingAddressId() != null; |
+ assert card.getBillingAddressId().equals(billingAddress.getGUID()); |
+ |
+ mCard = card; |
+ mBillingAddress = billingAddress; |
+ mIsComplete = true; |
+ updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber(), card.getName(), |
+ card.getIssuerIconDrawableId()); |
+ } |
+ |
+ /** @return The credit card represented by this payment instrument. */ |
+ public CreditCard getCard() { |
+ return mCard; |
+ } |
} |