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