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

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

Issue 2501593003: Implement the new basic card specification. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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/CardEditor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
index 0f98c44a56f4366f30e69845bb48f239396c68d7..1aa62de54480c03ad0dd953e67a5cbb7ebba6cf6 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
@@ -23,6 +23,7 @@ import org.chromium.chrome.browser.payments.ui.EditorModel;
import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content_public.browser.WebContents;
+import org.chromium.payments.mojom.PaymentMethodData;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -103,6 +104,13 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
private final Set<String> mAcceptedCardTypes;
/**
+ * The card types accepted by the merchant website that should have "basic-card" as the payment
+ * method. This is a subset of the accepted card types. Used when creating the complete payment
+ * instrument.
+ */
+ private final Set<String> mAcceptedBasicCardTypes;
+
+ /**
* The information about the accepted card types. Used in the editor as a hint to the user about
* the valid card types. This is important to keep in a list, because the display order matters.
*/
@@ -177,6 +185,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
new CardTypeInfo(R.drawable.pr_visa, R.string.autofill_cc_visa));
mAcceptedCardTypes = new HashSet<>();
+ mAcceptedBasicCardTypes = new HashSet<>();
mAcceptedCardTypeInfos = new ArrayList<>();
mHandler = new Handler();
@@ -214,20 +223,46 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
/**
* Adds accepted payment methods to the editor, if they are recognized credit card types.
*
- * @param acceptedMethods The accepted method payments.
+ * @param data Supported methods and method specific data. Should not be null.
*/
- public void addAcceptedPaymentMethodsIfRecognized(String[] acceptedMethods) {
- assert acceptedMethods != null;
- for (int i = 0; i < acceptedMethods.length; i++) {
- String method = acceptedMethods[i];
+ public void addAcceptedPaymentMethodsIfRecognized(PaymentMethodData data) {
+ assert data != null;
+ for (int i = 0; i < data.supportedMethods.length; i++) {
+ String method = data.supportedMethods[i];
if (mCardTypes.containsKey(method)) {
- assert !mAcceptedCardTypes.contains(method);
mAcceptedCardTypes.add(method);
mAcceptedCardTypeInfos.add(mCardTypes.get(method));
+ } else if (AutofillPaymentApp.BASIC_CARD_METHOD_NAME.equals(method)) {
+ Set<String> basicCardNetworks = AutofillPaymentApp.convertBasicCardToNetworks(data);
+ if (basicCardNetworks != null) {
+ mAcceptedCardTypes.addAll(basicCardNetworks);
+ mAcceptedBasicCardTypes.addAll(basicCardNetworks);
+ for (String network : basicCardNetworks) {
+ mAcceptedCardTypeInfos.add(mCardTypes.get(network));
+ }
+ }
}
}
}
+ /** Removes duplicate payment method icons from UI. */
+ public void removeDuplicatePaymentMethods() {
+ int read;
+ int write;
+ Set<CardTypeInfo> unique = new HashSet<>();
+ for (read = 0, write = 0; read < mAcceptedCardTypeInfos.size(); read++) {
+ CardTypeInfo info = mAcceptedCardTypeInfos.get(read);
+ if (!unique.contains(info)) {
+ unique.add(info);
+ mAcceptedCardTypeInfos.set(write++, info);
+ }
+ }
+
+ for (int i = mAcceptedCardTypeInfos.size() - 1; i >= write; i--) {
+ mAcceptedCardTypeInfos.remove(i);
+ }
+ }
+
/**
* Builds and shows an editor model with the following fields for local cards.
*
@@ -253,7 +288,8 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
// Ensure that |instrument| and |card| are never null.
final AutofillPaymentInstrument instrument = isNewCard
- ? new AutofillPaymentInstrument(mContext, mWebContents, new CreditCard(), null)
+ ? new AutofillPaymentInstrument(mContext, mWebContents, new CreditCard(),
+ null /* billingAddress */, null /* methodName */)
: toEdit;
final CreditCard card = instrument.getCard();
@@ -305,13 +341,24 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
@Override
public void run() {
commitChanges(card, isNewCard);
+
+ String methodName = card.getBasicCardPaymentType();
+ if (mAcceptedBasicCardTypes.contains(methodName)) {
+ methodName = AutofillPaymentApp.BASIC_CARD_METHOD_NAME;
+ }
+ assert methodName != null;
+
+ AutofillProfile billingAddress = null;
for (int i = 0; i < mProfilesForBillingAddress.size(); ++i) {
if (TextUtils.equals(mProfilesForBillingAddress.get(i).getGUID(),
card.getBillingAddressId())) {
- instrument.completeInstrument(card, mProfilesForBillingAddress.get(i));
+ billingAddress = mProfilesForBillingAddress.get(i);
break;
}
}
+ assert billingAddress != null;
+
+ instrument.completeInstrument(card, methodName, billingAddress);
callback.onResult(instrument);
}
});

Powered by Google App Engine
This is Rietveld 408576698