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/content/payment_response_helper.h" | 5 #include "components/payments/content/payment_response_helper.h" |
6 | 6 |
7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/autofill/core/browser/autofill_country.h" | 9 #include "components/autofill/core/browser/autofill_country.h" |
10 #include "components/autofill/core/browser/autofill_data_util.h" | 10 #include "components/autofill/core/browser/autofill_data_util.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // Start to get the instrument details. Will call back into | 61 // Start to get the instrument details. Will call back into |
62 // OnInstrumentDetailsReady. | 62 // OnInstrumentDetailsReady. |
63 selected_instrument_->InvokePaymentApp(this); | 63 selected_instrument_->InvokePaymentApp(this); |
64 }; | 64 }; |
65 | 65 |
66 PaymentResponseHelper::~PaymentResponseHelper(){}; | 66 PaymentResponseHelper::~PaymentResponseHelper(){}; |
67 | 67 |
68 // static | 68 // static |
69 mojom::PaymentAddressPtr | 69 mojom::PaymentAddressPtr |
70 PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( | 70 PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( |
71 const autofill::AutofillProfile* const profile, | 71 const autofill::AutofillProfile& profile, |
72 const std::string& app_locale) { | 72 const std::string& app_locale) { |
73 mojom::PaymentAddressPtr payment_address = mojom::PaymentAddress::New(); | 73 mojom::PaymentAddressPtr payment_address = mojom::PaymentAddress::New(); |
74 | 74 |
75 payment_address->country = | 75 payment_address->country = |
76 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 76 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
77 payment_address->address_line = base::SplitString( | 77 payment_address->address_line = base::SplitString( |
78 base::UTF16ToUTF8(profile->GetInfo( | 78 base::UTF16ToUTF8(profile.GetInfo( |
79 autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS), | 79 autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS), |
80 app_locale)), | 80 app_locale)), |
81 "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 81 "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
82 payment_address->region = | 82 payment_address->region = |
83 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_STATE)); | 83 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_STATE)); |
84 payment_address->city = | 84 payment_address->city = |
85 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_CITY)); | 85 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_CITY)); |
86 payment_address->dependent_locality = base::UTF16ToUTF8( | 86 payment_address->dependent_locality = base::UTF16ToUTF8( |
87 profile->GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY)); | 87 profile.GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY)); |
88 payment_address->postal_code = | 88 payment_address->postal_code = |
89 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); | 89 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP)); |
90 payment_address->sorting_code = base::UTF16ToUTF8( | 90 payment_address->sorting_code = base::UTF16ToUTF8( |
91 profile->GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE)); | 91 profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE)); |
92 payment_address->language_code = profile->language_code(); | 92 payment_address->language_code = profile.language_code(); |
93 payment_address->organization = | 93 payment_address->organization = |
94 base::UTF16ToUTF8(profile->GetRawInfo(autofill::COMPANY_NAME)); | 94 base::UTF16ToUTF8(profile.GetRawInfo(autofill::COMPANY_NAME)); |
95 payment_address->recipient = base::UTF16ToUTF8(profile->GetInfo( | 95 payment_address->recipient = base::UTF16ToUTF8( |
96 autofill::AutofillType(autofill::NAME_FULL), app_locale)); | 96 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale)); |
97 | 97 |
98 // TODO(crbug.com/705945): Format phone number according to spec. | 98 // TODO(crbug.com/705945): Format phone number according to spec. |
99 payment_address->phone = | 99 payment_address->phone = |
100 base::UTF16ToUTF8(profile->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); | 100 base::UTF16ToUTF8(profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); |
101 | 101 |
102 return payment_address; | 102 return payment_address; |
103 } | 103 } |
104 | 104 |
105 void PaymentResponseHelper::OnInstrumentDetailsReady( | 105 void PaymentResponseHelper::OnInstrumentDetailsReady( |
106 const std::string& method_name, | 106 const std::string& method_name, |
107 const std::string& stringified_details) { | 107 const std::string& stringified_details) { |
108 method_name_ = method_name; | 108 method_name_ = method_name; |
109 stringified_details_ = stringified_details; | 109 stringified_details_ = stringified_details; |
110 is_waiting_for_instrument_details_ = false; | 110 is_waiting_for_instrument_details_ = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // "visa") or through basic-card's supportedNetworks. | 142 // "visa") or through basic-card's supportedNetworks. |
143 payment_response->method_name = | 143 payment_response->method_name = |
144 spec_->IsMethodSupportedThroughBasicCard(method_name_) | 144 spec_->IsMethodSupportedThroughBasicCard(method_name_) |
145 ? kBasicCardMethodName | 145 ? kBasicCardMethodName |
146 : method_name_; | 146 : method_name_; |
147 payment_response->stringified_details = stringified_details_; | 147 payment_response->stringified_details = stringified_details_; |
148 | 148 |
149 // Shipping Address section | 149 // Shipping Address section |
150 if (spec_->request_shipping()) { | 150 if (spec_->request_shipping()) { |
151 payment_response->shipping_address = | 151 payment_response->shipping_address = |
152 GetMojomPaymentAddressFromAutofillProfile(&shipping_address_, | 152 GetMojomPaymentAddressFromAutofillProfile(shipping_address_, |
153 app_locale_); | 153 app_locale_); |
154 payment_response->shipping_option = spec_->selected_shipping_option()->id; | 154 payment_response->shipping_option = spec_->selected_shipping_option()->id; |
155 } | 155 } |
156 | 156 |
157 // Contact Details section. | 157 // Contact Details section. |
158 if (spec_->request_payer_name()) { | 158 if (spec_->request_payer_name()) { |
159 DCHECK(selected_contact_profile_); | 159 DCHECK(selected_contact_profile_); |
160 payment_response->payer_name = | 160 payment_response->payer_name = |
161 base::UTF16ToUTF8(selected_contact_profile_->GetInfo( | 161 base::UTF16ToUTF8(selected_contact_profile_->GetInfo( |
162 autofill::AutofillType(autofill::NAME_FULL), app_locale_)); | 162 autofill::AutofillType(autofill::NAME_FULL), app_locale_)); |
(...skipping 18 matching lines...) Expand all Loading... |
181 const std::string default_region_code = | 181 const std::string default_region_code = |
182 autofill::AutofillCountry::CountryCodeForLocale(app_locale_); | 182 autofill::AutofillCountry::CountryCodeForLocale(app_locale_); |
183 payment_response->payer_phone = | 183 payment_response->payer_phone = |
184 data_util::FormatPhoneForResponse(original_number, default_region_code); | 184 data_util::FormatPhoneForResponse(original_number, default_region_code); |
185 } | 185 } |
186 | 186 |
187 delegate_->OnPaymentResponseReady(std::move(payment_response)); | 187 delegate_->OnPaymentResponseReady(std::move(payment_response)); |
188 } | 188 } |
189 | 189 |
190 } // namespace payments | 190 } // namespace payments |
OLD | NEW |