| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.text.TextUtils; | 7 import android.text.TextUtils; |
| 9 import android.util.JsonWriter; | 8 import android.util.JsonWriter; |
| 10 | 9 |
| 11 import org.json.JSONObject; | |
| 12 | |
| 13 import org.chromium.base.ApiCompatibilityUtils; | |
| 14 import org.chromium.chrome.browser.autofill.PersonalDataManager; | 10 import org.chromium.chrome.browser.autofill.PersonalDataManager; |
| 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 11 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | 12 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| 17 import org.chromium.chrome.browser.autofill.PersonalDataManager.FullCardRequestD
elegate; | 13 import org.chromium.chrome.browser.autofill.PersonalDataManager.FullCardRequestD
elegate; |
| 18 import org.chromium.content_public.browser.WebContents; | 14 import org.chromium.content_public.browser.WebContents; |
| 19 import org.chromium.payments.mojom.PaymentItem; | 15 import org.chromium.payments.mojom.PaymentItem; |
| 20 | 16 |
| 17 import org.json.JSONObject; |
| 18 |
| 21 import java.io.IOException; | 19 import java.io.IOException; |
| 22 import java.io.StringWriter; | 20 import java.io.StringWriter; |
| 23 import java.util.List; | 21 import java.util.List; |
| 24 | 22 |
| 25 import javax.annotation.Nullable; | 23 import javax.annotation.Nullable; |
| 26 | 24 |
| 27 /** | 25 /** |
| 28 * The locally stored credit card payment instrument. | 26 * The locally stored credit card payment instrument. |
| 29 */ | 27 */ |
| 30 public class AutofillPaymentInstrument | 28 public class AutofillPaymentInstrument |
| 31 extends PaymentInstrument implements FullCardRequestDelegate { | 29 extends PaymentInstrument implements FullCardRequestDelegate { |
| 32 private final Context mContext; | |
| 33 private final WebContents mWebContents; | 30 private final WebContents mWebContents; |
| 34 private CreditCard mCard; | 31 private CreditCard mCard; |
| 35 private boolean mIsComplete; | 32 private boolean mIsComplete; |
| 36 @Nullable private AutofillProfile mBillingAddress; | 33 @Nullable private AutofillProfile mBillingAddress; |
| 37 @Nullable private DetailsCallback mCallback; | 34 @Nullable private DetailsCallback mCallback; |
| 38 | 35 |
| 39 /** | 36 /** |
| 40 * Builds a payment instrument for the given credit card. | 37 * Builds a payment instrument for the given credit card. |
| 41 * | 38 * |
| 42 * @param webContents The web contents where PaymentRequest was invoked. | 39 * @param webContents The web contents where PaymentRequest was invoked. |
| 43 * @param card The autofill card that can be used for payment. | 40 * @param card The autofill card that can be used for payment. |
| 44 * @param billingAddress The billing address for the card. | 41 * @param billingAddress The billing address for the card. |
| 45 */ | 42 */ |
| 46 public AutofillPaymentInstrument(Context context, WebContents webContents, C
reditCard card, | 43 public AutofillPaymentInstrument( |
| 47 @Nullable AutofillProfile billingAddress) { | 44 WebContents webContents, CreditCard card, @Nullable AutofillProfile
billingAddress) { |
| 48 super(card.getGUID(), card.getObfuscatedNumber(), card.getName(), | 45 super(card.getGUID(), card.getObfuscatedNumber(), card.getName(), |
| 49 card.getIssuerIconDrawableId() == 0 | 46 card.getIssuerIconDrawableId()); |
| 50 ? null | |
| 51 : ApiCompatibilityUtils.getDrawable( | |
| 52 context.getResources(), card.getIssuerIconDrawableId()))
; | |
| 53 mContext = context; | |
| 54 mWebContents = webContents; | 47 mWebContents = webContents; |
| 55 mCard = card; | 48 mCard = card; |
| 56 mIsComplete = false; | 49 mIsComplete = false; |
| 57 mBillingAddress = billingAddress; | 50 mBillingAddress = billingAddress; |
| 58 } | 51 } |
| 59 | 52 |
| 60 @Override | 53 @Override |
| 61 public String getMethodName() { | 54 public String getMethodName() { |
| 62 return mCard.getBasicCardPaymentType(); | 55 return mCard.getBasicCardPaymentType(); |
| 63 } | 56 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 * | 142 * |
| 150 * @param card The new credit card to use. The GUID should not cha
nge. | 143 * @param card The new credit card to use. The GUID should not cha
nge. |
| 151 * @param billingAddress The billing address for the card. The GUID should m
atch the billing | 144 * @param billingAddress The billing address for the card. The GUID should m
atch the billing |
| 152 * address ID of the new card to use. | 145 * address ID of the new card to use. |
| 153 */ | 146 */ |
| 154 public void completeInstrument(CreditCard card, AutofillProfile billingAddre
ss) { | 147 public void completeInstrument(CreditCard card, AutofillProfile billingAddre
ss) { |
| 155 assert card != null; | 148 assert card != null; |
| 156 assert billingAddress != null; | 149 assert billingAddress != null; |
| 157 assert card.getBillingAddressId() != null; | 150 assert card.getBillingAddressId() != null; |
| 158 assert card.getBillingAddressId().equals(billingAddress.getGUID()); | 151 assert card.getBillingAddressId().equals(billingAddress.getGUID()); |
| 159 assert card.getIssuerIconDrawableId() != 0; | |
| 160 | 152 |
| 161 mCard = card; | 153 mCard = card; |
| 162 mBillingAddress = billingAddress; | 154 mBillingAddress = billingAddress; |
| 163 mIsComplete = true; | 155 mIsComplete = true; |
| 164 updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber()
, card.getName(), | 156 updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber()
, card.getName(), |
| 165 null, ApiCompatibilityUtils.getDrawable( | 157 null, card.getIssuerIconDrawableId()); |
| 166 mContext.getResources(), card.getIssuerIconDrawabl
eId())); | |
| 167 } | 158 } |
| 168 | 159 |
| 169 /** @return The credit card represented by this payment instrument. */ | 160 /** @return The credit card represented by this payment instrument. */ |
| 170 public CreditCard getCard() { | 161 public CreditCard getCard() { |
| 171 return mCard; | 162 return mCard; |
| 172 } | 163 } |
| 173 } | 164 } |
| OLD | NEW |