Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6da7b9ae371db8e9387625f3be81f37d38652863 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillPaymentInstrument.java |
| @@ -0,0 +1,68 @@ |
| +// 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 android.util.JsonWriter; |
| + |
| +import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| +import org.chromium.chrome.browser.payments.ui.LineItem; |
| +import org.chromium.content_public.browser.WebContents; |
| + |
| +import org.json.JSONObject; |
| + |
| +import java.io.IOException; |
| +import java.io.StringWriter; |
| +import java.util.ArrayList; |
| + |
| +/** |
| + * The locally stored credit card payment instrument. |
| + */ |
| +public class AutofillPaymentInstrument extends PaymentInstrument { |
| + private CreditCard mCard; |
|
Ted C
2016/04/22 03:59:36
final?
please use gerrit instead
2016/04/25 19:22:30
Done.
|
| + |
| + /** |
| + * 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. |
| + */ |
| + public AutofillPaymentInstrument(WebContents webContents, CreditCard card) { |
| + super(card.getGUID(), card.getObfuscatedNumber(), card.getName(), |
| + card.getIssuerIconDrawableId()); |
| + mCard = card; |
| + } |
| + |
| + @Override |
| + public String getMethodName() { |
| + return mCard.getBasicCardPaymentType(); |
| + } |
| + |
| + @Override |
| + public void getDetails(String unusedMerchantName, String unusedOrigin, |
| + ArrayList<LineItem> unusedItems, JSONObject unusedDetails, DetailsCallback callback) { |
| + // TODO(rouslan): Prompt the user for the CVC and unmask the card (if it's masked). |
| + // http://crbug.com/602657 |
| + StringWriter stringWriter = new StringWriter(); |
| + JsonWriter json = new JsonWriter(stringWriter); |
| + try { |
| + json.beginObject(); |
| + json.name("cardholderName").value(mCard.getName()); |
| + json.name("cardNumber").value(mCard.getNumber()); |
| + json.name("expiryMonth").value(mCard.getMonth()); |
| + json.name("expiryYear").value(mCard.getYear()); |
| + // TODO(rouslan): Add "cardSecurityCode" after prompting the user for the CVC. |
| + // http://crbug.com/602657 |
| + json.endObject(); |
| + } catch (IOException e) { |
| + callback.onInstrumentDetailsError(); |
| + return; |
| + } |
| + |
| + callback.onInstrumentDetailsReady(mCard.getBasicCardPaymentType(), stringWriter.toString()); |
| + } |
| + |
| + @Override |
| + public void dismiss() {} |
| +} |