| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "components/payments/core/autofill_payment_instrument.h" | 5 #include "components/payments/core/autofill_payment_instrument.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 void AutofillPaymentInstrument::InvokePaymentApp( | 48 void AutofillPaymentInstrument::InvokePaymentApp( |
| 49 PaymentInstrument::Delegate* delegate) { | 49 PaymentInstrument::Delegate* delegate) { |
| 50 DCHECK(delegate); | 50 DCHECK(delegate); |
| 51 // There can be only one FullCardRequest going on at a time. If |delegate_| is | 51 // There can be only one FullCardRequest going on at a time. If |delegate_| is |
| 52 // not null, there's already an active request, which shouldn't happen. | 52 // not null, there's already an active request, which shouldn't happen. |
| 53 // |delegate_| is reset to nullptr when the request succeeds or fails. | 53 // |delegate_| is reset to nullptr when the request succeeds or fails. |
| 54 DCHECK(!delegate_); | 54 DCHECK(!delegate_); |
| 55 delegate_ = delegate; | 55 delegate_ = delegate; |
| 56 | 56 |
| 57 // Get the billing address. | 57 // Get the billing address. |
| 58 // TODO(crbug.com/709776): Make sure the billing address is valid before | |
| 59 // getting here. | |
| 60 if (!credit_card_.billing_address_id().empty()) { | 58 if (!credit_card_.billing_address_id().empty()) { |
| 61 autofill::AutofillProfile* billing_address = | 59 autofill::AutofillProfile* billing_address = |
| 62 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( | 60 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
| 63 credit_card_.billing_address_id(), billing_profiles_); | 61 credit_card_.billing_address_id(), billing_profiles_); |
| 64 if (billing_address) | 62 if (billing_address) |
| 65 billing_address_ = *billing_address; | 63 billing_address_ = *billing_address; |
| 66 } | 64 } |
| 67 | 65 |
| 68 is_waiting_for_billing_address_normalization_ = true; | 66 is_waiting_for_billing_address_normalization_ = true; |
| 69 is_waiting_for_card_unmask_ = true; | 67 is_waiting_for_card_unmask_ = true; |
| 70 | 68 |
| 71 // Start the normalization of the billing address. | 69 // Start the normalization of the billing address. |
| 72 // Use the country code from the profile if it is set, otherwise infer it | 70 // Use the country code from the profile if it is set, otherwise infer it |
| 73 // from the |app_locale_|. | 71 // from the |app_locale_|. |
| 74 std::string country_code = base::UTF16ToUTF8( | 72 std::string country_code = base::UTF16ToUTF8( |
| 75 billing_address_.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 73 billing_address_.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
| 76 if (!autofill::data_util::IsValidCountryCode(country_code)) { | 74 if (!autofill::data_util::IsValidCountryCode(country_code)) { |
| 77 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale_); | 75 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale_); |
| 78 } | 76 } |
| 79 payment_request_delegate_->GetAddressNormalizer()->StartAddressNormalization( | 77 payment_request_delegate_->GetAddressNormalizer()->StartAddressNormalization( |
| 80 billing_address_, country_code, /*timeout_seconds=*/5, this); | 78 billing_address_, country_code, /*timeout_seconds=*/5, this); |
| 81 | 79 |
| 82 payment_request_delegate_->DoFullCardRequest(credit_card_, | 80 payment_request_delegate_->DoFullCardRequest(credit_card_, |
| 83 weak_ptr_factory_.GetWeakPtr()); | 81 weak_ptr_factory_.GetWeakPtr()); |
| 84 } | 82 } |
| 85 | 83 |
| 86 bool AutofillPaymentInstrument::IsCompleteForPayment() { | 84 bool AutofillPaymentInstrument::IsCompleteForPayment() { |
| 87 return autofill::GetCompletionStatusForCard(credit_card_, app_locale_) == | 85 return autofill::GetCompletionStatusForCard(credit_card_, app_locale_, |
| 86 billing_profiles_) == |
| 88 autofill::CREDIT_CARD_COMPLETE; | 87 autofill::CREDIT_CARD_COMPLETE; |
| 89 } | 88 } |
| 90 | 89 |
| 91 base::string16 AutofillPaymentInstrument::GetMissingInfoLabel() { | 90 base::string16 AutofillPaymentInstrument::GetMissingInfoLabel() { |
| 92 return autofill::GetCompletionMessageForCard( | 91 return autofill::GetCompletionMessageForCard( |
| 93 autofill::GetCompletionStatusForCard(credit_card_, app_locale_)); | 92 autofill::GetCompletionStatusForCard(credit_card_, app_locale_, |
| 93 billing_profiles_)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool AutofillPaymentInstrument::IsValidForCanMakePayment() { | 96 bool AutofillPaymentInstrument::IsValidForCanMakePayment() { |
| 97 autofill::CreditCardCompletionStatus status = | 97 autofill::CreditCardCompletionStatus status = |
| 98 autofill::GetCompletionStatusForCard(credit_card_, app_locale_); | 98 autofill::GetCompletionStatusForCard(credit_card_, app_locale_, |
| 99 billing_profiles_); |
| 99 // Card has to have a cardholder name and number for the purposes of | 100 // Card has to have a cardholder name and number for the purposes of |
| 100 // CanMakePayment. An expired card is still valid at this stage. | 101 // CanMakePayment. An expired card is still valid at this stage. |
| 101 return !(status & autofill::CREDIT_CARD_NO_CARDHOLDER || | 102 return !(status & autofill::CREDIT_CARD_NO_CARDHOLDER || |
| 102 status & autofill::CREDIT_CARD_NO_NUMBER); | 103 status & autofill::CREDIT_CARD_NO_NUMBER); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void AutofillPaymentInstrument::OnFullCardRequestSucceeded( | 106 void AutofillPaymentInstrument::OnFullCardRequestSucceeded( |
| 106 const autofill::CreditCard& card, | 107 const autofill::CreditCard& card, |
| 107 const base::string16& cvc) { | 108 const base::string16& cvc) { |
| 108 DCHECK(delegate_); | 109 DCHECK(delegate_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 .ToDictionaryValue(); | 151 .ToDictionaryValue(); |
| 151 std::string stringified_details; | 152 std::string stringified_details; |
| 152 base::JSONWriter::Write(*response_value, &stringified_details); | 153 base::JSONWriter::Write(*response_value, &stringified_details); |
| 153 delegate_->OnInstrumentDetailsReady(method_name(), stringified_details); | 154 delegate_->OnInstrumentDetailsReady(method_name(), stringified_details); |
| 154 | 155 |
| 155 delegate_ = nullptr; | 156 delegate_ = nullptr; |
| 156 cvc_ = base::UTF8ToUTF16(""); | 157 cvc_ = base::UTF8ToUTF16(""); |
| 157 } | 158 } |
| 158 | 159 |
| 159 } // namespace payments | 160 } // namespace payments |
| OLD | NEW |