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/payment_request_data_util.h" | 5 #include "components/payments/core/payment_request_data_util.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 address.recipient = | 64 address.recipient = |
65 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale); | 65 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale); |
66 address.phone = profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); | 66 address.phone = profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); |
67 | 67 |
68 return address; | 68 return address; |
69 } | 69 } |
70 | 70 |
71 BasicCardResponse GetBasicCardResponseFromAutofillCreditCard( | 71 BasicCardResponse GetBasicCardResponseFromAutofillCreditCard( |
72 const autofill::CreditCard& card, | 72 const autofill::CreditCard& card, |
73 const base::string16& cvc, | 73 const base::string16& cvc, |
74 const std::vector<autofill::AutofillProfile*>& billing_profiles, | 74 const autofill::AutofillProfile& billing_profile, |
75 const std::string& app_locale) { | 75 const std::string& app_locale) { |
76 BasicCardResponse response; | 76 BasicCardResponse response; |
77 response.cardholder_name = card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL); | 77 response.cardholder_name = card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL); |
78 response.card_number = card.GetRawInfo(autofill::CREDIT_CARD_NUMBER); | 78 response.card_number = card.GetRawInfo(autofill::CREDIT_CARD_NUMBER); |
79 response.expiry_month = card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH); | 79 response.expiry_month = card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH); |
80 response.expiry_year = | 80 response.expiry_year = |
81 card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR); | 81 card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR); |
82 response.card_security_code = cvc; | 82 response.card_security_code = cvc; |
83 | 83 |
84 // TODO(crbug.com/602666): Ensure we reach here only if the card has a billing | 84 response.billing_address = |
85 // address. Then add DCHECK(!card->billing_address_id().empty()). | 85 GetPaymentAddressFromAutofillProfile(billing_profile, app_locale); |
| 86 |
| 87 return response; |
| 88 } |
| 89 |
| 90 BasicCardResponse GetBasicCardResponseFromAutofillCreditCard( |
| 91 const autofill::CreditCard& card, |
| 92 const base::string16& cvc, |
| 93 const std::vector<autofill::AutofillProfile*>& billing_profiles, |
| 94 const std::string& app_locale) { |
| 95 autofill::AutofillProfile billing_profile; |
| 96 |
| 97 // TODO(crbug.com/714655): This should be done in the autofill instrument. |
86 if (!card.billing_address_id().empty()) { | 98 if (!card.billing_address_id().empty()) { |
87 const autofill::AutofillProfile* billing_address = | 99 const autofill::AutofillProfile* billing_address = |
88 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( | 100 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
89 card.billing_address_id(), billing_profiles); | 101 card.billing_address_id(), billing_profiles); |
90 DCHECK(billing_address); | 102 DCHECK(billing_address); |
91 response.billing_address = | 103 billing_profile = *billing_address; |
92 GetPaymentAddressFromAutofillProfile(*billing_address, app_locale); | |
93 } | 104 } |
94 | 105 |
95 return response; | 106 return GetBasicCardResponseFromAutofillCreditCard(card, cvc, billing_profile, |
| 107 app_locale); |
96 } | 108 } |
97 | 109 |
98 void ParseBasicCardSupportedNetworks( | 110 void ParseBasicCardSupportedNetworks( |
99 const std::vector<PaymentMethodData>& method_data, | 111 const std::vector<PaymentMethodData>& method_data, |
100 std::vector<std::string>* out_supported_networks, | 112 std::vector<std::string>* out_supported_networks, |
101 std::set<std::string>* out_basic_card_specified_networks) { | 113 std::set<std::string>* out_basic_card_specified_networks) { |
102 DCHECK(out_supported_networks->empty()); | 114 DCHECK(out_supported_networks->empty()); |
103 DCHECK(out_basic_card_specified_networks->empty()); | 115 DCHECK(out_basic_card_specified_networks->empty()); |
104 | 116 |
105 std::set<std::string> card_networks{"amex", "diners", "discover", | 117 std::set<std::string> card_networks{"amex", "diners", "discover", |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 174 } |
163 | 175 |
164 std::string FormatPhoneForResponse(const std::string& phone_number, | 176 std::string FormatPhoneForResponse(const std::string& phone_number, |
165 const std::string& country_code) { | 177 const std::string& country_code) { |
166 return FormatPhoneNumber(phone_number, country_code, | 178 return FormatPhoneNumber(phone_number, country_code, |
167 PhoneNumberUtil::PhoneNumberFormat::E164); | 179 PhoneNumberUtil::PhoneNumberFormat::E164); |
168 } | 180 } |
169 | 181 |
170 } // namespace data_util | 182 } // namespace data_util |
171 } // namespace payments | 183 } // namespace payments |
OLD | NEW |