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

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

Issue 1904553003: Java implementation of PaymentRequest mojo service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable Pay button before user provided required information. Created 4 years, 8 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/AutofillPaymentApp.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentApp.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentApp.java
new file mode 100644
index 0000000000000000000000000000000000000000..394a70d0cfdb72df51f74c51a35528d6388f5a52
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentApp.java
@@ -0,0 +1,60 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.payments;
+
+import org.chromium.chrome.browser.autofill.PersonalDataManager;
+import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
+import org.chromium.chrome.browser.payments.ui.LineItem;
+import org.chromium.content_public.browser.WebContents;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Provides access to locally stored user credit cards.
+ */
+public class AutofillPaymentApp implements PaymentApp {
+ private final WebContents mWebContents;
+
+ /**
+ * Builds a payment app backed by autofill cards.
+ *
+ * @param webContents The web contents where PaymentRequest was invoked.
+ */
+ public AutofillPaymentApp(WebContents webContents) {
+ mWebContents = webContents;
+ }
+
+ @Override
+ public void getInstruments(ArrayList<LineItem> unusedItems, InstrumentsCallback callback) {
+ List<PaymentInstrument> instruments = new LinkedList<PaymentInstrument>();
+ for (CreditCard card : PersonalDataManager.getInstance().getCreditCards()) {
Ted C 2016/04/22 03:59:36 if getCreditCards doesn't return an array (instead
please use gerrit instead 2016/04/25 19:22:30 Done.
+ instruments.add(new AutofillPaymentInstrument(mWebContents, card));
+ }
+ callback.onInstrumentsReady(this, instruments);
Ted C 2016/04/22 03:59:36 Maybe we should be posting this (new Handler().pos
please use gerrit instead 2016/04/25 19:22:29 Made AutofillPaymentApp implement the Runnable int
Ted C 2016/04/25 22:49:02 it is more efficient, but I would argue that reada
please use gerrit instead 2016/04/25 23:19:24 Done.
+ }
+
+ @Override
+ public HashSet<String> getSupportedMethodNames() {
+ // https://w3c.github.io/browser-payment-api/specs/basic-card-payment.html#method-id
+ //
+ // The spec does not include "generic" card types. That's the type of card for which
+ // Chrome cannot determine the type.
+ //
+ // The spec also includes more detailed card types, e.g., "visa/credit" and "visa/debit".
+ // Autofill does not distinguish between these types of cards, so they are not in the list
+ // of supported method names.
+ return new HashSet<String>(Arrays.asList(new String[] {
Ted C 2016/04/22 03:59:36 this is an allocation of a string array, arraylist
please use gerrit instead 2016/04/25 19:22:30 Done.
+ "visa", "mastercard", "amex", "discover", "diners", "jcb", "unionpay", "generic"}));
+ }
+
+ @Override
+ public String getIdentifier() {
+ return "org.chromium.chrome.browser.payments.AutofillPaymentApp";
Ted C 2016/04/22 03:59:36 do you want this to stay consistent over time (acr
please use gerrit instead 2016/04/25 19:22:30 Using "Chrome_Autofill_Payment_App".
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698