| 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.content.Context; |
| 8 import android.os.Handler; | |
| 9 import android.text.TextUtils; | 8 import android.text.TextUtils; |
| 10 import android.util.JsonWriter; | 9 import android.util.JsonWriter; |
| 11 | 10 |
| 12 import org.chromium.base.ApiCompatibilityUtils; | 11 import org.chromium.base.ApiCompatibilityUtils; |
| 13 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ChromeActivity; | 13 import org.chromium.chrome.browser.ChromeActivity; |
| 15 import org.chromium.chrome.browser.autofill.PersonalDataManager; | 14 import org.chromium.chrome.browser.autofill.PersonalDataManager; |
| 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 17 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| 18 import org.chromium.chrome.browser.autofill.PersonalDataManager.FullCardRequestD
elegate; | 17 import org.chromium.chrome.browser.autofill.PersonalDataManager.FullCardRequestD
elegate; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Update the card's expiration date. | 118 // Update the card's expiration date. |
| 120 mCard.setMonth(updatedCard.getMonth()); | 119 mCard.setMonth(updatedCard.getMonth()); |
| 121 mCard.setYear(updatedCard.getYear()); | 120 mCard.setYear(updatedCard.getYear()); |
| 122 | 121 |
| 123 mIsWaitingForFullCardDetails = false; | 122 mIsWaitingForFullCardDetails = false; |
| 124 | 123 |
| 125 // Show the loading UI while the address gets normalized. | 124 // Show the loading UI while the address gets normalized. |
| 126 mCallback.onInstrumentDetailsLoadingWithoutUI(); | 125 mCallback.onInstrumentDetailsLoadingWithoutUI(); |
| 127 | 126 |
| 128 // Wait for the billing address normalization before sending the instrum
ent details. | 127 // Wait for the billing address normalization before sending the instrum
ent details. |
| 129 if (mIsWaitingForBillingNormalization) { | 128 if (!mIsWaitingForBillingNormalization) sendInstrumentDetails(); |
| 130 // If the normalization is not completed yet, Start a timer to cance
l it if it takes too | |
| 131 // long. | |
| 132 new Handler().postDelayed(new Runnable() { | |
| 133 @Override | |
| 134 public void run() { | |
| 135 onAddressNormalized(null); | |
| 136 } | |
| 137 }, PersonalDataManager.getInstance().getNormalizationTimeoutMS()); | |
| 138 | |
| 139 return; | |
| 140 } else { | |
| 141 sendIntrumentDetails(); | |
| 142 } | |
| 143 } | 129 } |
| 144 | 130 |
| 145 @Override | 131 @Override |
| 146 public void onAddressNormalized(AutofillProfile profile) { | 132 public void onAddressNormalized(AutofillProfile profile) { |
| 147 if (!mIsWaitingForBillingNormalization) return; | 133 if (!mIsWaitingForBillingNormalization) return; |
| 148 mIsWaitingForBillingNormalization = false; | 134 mIsWaitingForBillingNormalization = false; |
| 149 | 135 |
| 150 // If the normalization finished first, use the normalized address. | 136 // If the normalization finished first, use the normalized address. |
| 151 if (profile != null) mBillingAddress = profile; | 137 if (profile != null) mBillingAddress = profile; |
| 152 | 138 |
| 153 // Wait for the full card details before sending the instrument details. | 139 // Wait for the full card details before sending the instrument details. |
| 154 if (!mIsWaitingForFullCardDetails) sendIntrumentDetails(); | 140 if (!mIsWaitingForFullCardDetails) sendInstrumentDetails(); |
| 155 } | 141 } |
| 156 | 142 |
| 157 @Override | 143 @Override |
| 158 public void onCouldNotNormalize(AutofillProfile profile) { | 144 public void onCouldNotNormalize(AutofillProfile profile) { |
| 159 onAddressNormalized(null); | 145 onAddressNormalized(null); |
| 160 } | 146 } |
| 161 | 147 |
| 162 /** | 148 /** |
| 163 * Stringify the card details and send the resulting string and the method n
ame to the | 149 * Stringify the card details and send the resulting string and the method n
ame to the |
| 164 * registered callback. | 150 * registered callback. |
| 165 */ | 151 */ |
| 166 private void sendIntrumentDetails() { | 152 private void sendInstrumentDetails() { |
| 167 StringWriter stringWriter = new StringWriter(); | 153 StringWriter stringWriter = new StringWriter(); |
| 168 JsonWriter json = new JsonWriter(stringWriter); | 154 JsonWriter json = new JsonWriter(stringWriter); |
| 169 try { | 155 try { |
| 170 json.beginObject(); | 156 json.beginObject(); |
| 171 | 157 |
| 172 json.name("cardholderName").value(mCard.getName()); | 158 json.name("cardholderName").value(mCard.getName()); |
| 173 json.name("cardNumber").value(mCard.getNumber()); | 159 json.name("cardNumber").value(mCard.getNumber()); |
| 174 json.name("expiryMonth").value(mCard.getMonth()); | 160 json.name("expiryMonth").value(mCard.getMonth()); |
| 175 json.name("expiryYear").value(mCard.getYear()); | 161 json.name("expiryYear").value(mCard.getYear()); |
| 176 json.name("cardSecurityCode").value(mSecurityCode); | 162 json.name("cardSecurityCode").value(mSecurityCode); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 /** @return The credit card represented by this payment instrument. */ | 323 /** @return The credit card represented by this payment instrument. */ |
| 338 public CreditCard getCard() { | 324 public CreditCard getCard() { |
| 339 return mCard; | 325 return mCard; |
| 340 } | 326 } |
| 341 | 327 |
| 342 /** @return The billing address associated with this credit card. */ | 328 /** @return The billing address associated with this credit card. */ |
| 343 public AutofillProfile getBillingAddress() { | 329 public AutofillProfile getBillingAddress() { |
| 344 return mBillingAddress; | 330 return mBillingAddress; |
| 345 } | 331 } |
| 346 } | 332 } |
| OLD | NEW |