| 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 "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "components/autofill/core/browser/autofill_data_util.h" | 10 #include "components/autofill/core/browser/autofill_data_util.h" |
| 11 #include "components/payments/core/basic_card_response.h" | 11 #include "components/payments/core/basic_card_response.h" |
| 12 #include "components/payments/core/payment_request_data_util.h" | 12 #include "components/payments/core/payment_request_data_util.h" |
| 13 | 13 |
| 14 namespace payments { | 14 namespace payments { |
| 15 | 15 |
| 16 AutofillPaymentInstrument::AutofillPaymentInstrument( | 16 AutofillPaymentInstrument::AutofillPaymentInstrument( |
| 17 const std::string& method_name, | 17 const std::string& method_name, |
| 18 const autofill::CreditCard& credit_card, | 18 const autofill::CreditCard& card, |
| 19 const std::vector<autofill::AutofillProfile*>& billing_profiles, | 19 const std::vector<autofill::AutofillProfile*>& billing_profiles, |
| 20 const std::string& app_locale) | 20 const std::string& app_locale) |
| 21 : PaymentInstrument(method_name), | 21 : PaymentInstrument( |
| 22 credit_card_(credit_card), | 22 method_name, |
| 23 /* label= */ card.TypeAndLastFourDigits(), |
| 24 /* sublabel= */ |
| 25 card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
| 26 app_locale), |
| 27 autofill::data_util::GetPaymentRequestData(card.type()) |
| 28 .icon_resource_id), |
| 29 credit_card_(card), |
| 23 billing_profiles_(billing_profiles), | 30 billing_profiles_(billing_profiles), |
| 24 app_locale_(app_locale) {} | 31 app_locale_(app_locale) {} |
| 25 AutofillPaymentInstrument::~AutofillPaymentInstrument() {} | 32 AutofillPaymentInstrument::~AutofillPaymentInstrument() {} |
| 26 | 33 |
| 27 void AutofillPaymentInstrument::InvokePaymentApp( | 34 void AutofillPaymentInstrument::InvokePaymentApp( |
| 28 PaymentInstrument::Delegate* delegate) { | 35 PaymentInstrument::Delegate* delegate) { |
| 29 DCHECK(delegate); | 36 DCHECK(delegate); |
| 30 std::string stringified_details; | 37 std::string stringified_details; |
| 31 // TODO(mathp): Show the CVC dialog and use the data instead of the | 38 // TODO(mathp): Show the CVC dialog and use the data instead of the |
| 32 // placeholder string. | 39 // placeholder string. |
| 33 std::unique_ptr<base::DictionaryValue> response_value = | 40 std::unique_ptr<base::DictionaryValue> response_value = |
| 34 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( | 41 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( |
| 35 credit_card_, base::ASCIIToUTF16("123"), billing_profiles_, | 42 credit_card_, base::ASCIIToUTF16("123"), billing_profiles_, |
| 36 app_locale_) | 43 app_locale_) |
| 37 .ToDictionaryValue(); | 44 .ToDictionaryValue(); |
| 38 base::JSONWriter::Write(*response_value, &stringified_details); | 45 base::JSONWriter::Write(*response_value, &stringified_details); |
| 39 delegate->OnInstrumentDetailsReady(method_name(), stringified_details); | 46 delegate->OnInstrumentDetailsReady(method_name(), stringified_details); |
| 40 } | 47 } |
| 41 | 48 |
| 49 bool AutofillPaymentInstrument::IsValid() { |
| 50 return credit_card_.IsValid(); |
| 51 } |
| 52 |
| 42 } // namespace payments | 53 } // namespace payments |
| OLD | NEW |