OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/payments/content/payment_response_helper.h" |
| 6 |
| 7 #include "base/strings/string_split.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/autofill/core/browser/autofill_profile.h" |
| 10 #include "components/autofill/core/browser/autofill_type.h" |
| 11 |
| 12 namespace payments { |
| 13 |
| 14 PaymentResponseHelper::PaymentResponseHelper(){}; |
| 15 PaymentResponseHelper::~PaymentResponseHelper(){}; |
| 16 |
| 17 // static |
| 18 mojom::PaymentAddressPtr |
| 19 PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( |
| 20 const autofill::AutofillProfile* const profile, |
| 21 const std::string& app_locale) { |
| 22 mojom::PaymentAddressPtr payment_address = mojom::PaymentAddress::New(); |
| 23 |
| 24 payment_address->country = |
| 25 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
| 26 payment_address->address_line = base::SplitString( |
| 27 base::UTF16ToUTF8(profile->GetInfo( |
| 28 autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS), |
| 29 app_locale)), |
| 30 "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 31 payment_address->region = |
| 32 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_STATE)); |
| 33 payment_address->city = |
| 34 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_CITY)); |
| 35 payment_address->dependent_locality = base::UTF16ToUTF8( |
| 36 profile->GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY)); |
| 37 payment_address->postal_code = |
| 38 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); |
| 39 payment_address->sorting_code = base::UTF16ToUTF8( |
| 40 profile->GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE)); |
| 41 payment_address->language_code = profile->language_code(); |
| 42 payment_address->organization = |
| 43 base::UTF16ToUTF8(profile->GetRawInfo(autofill::COMPANY_NAME)); |
| 44 payment_address->recipient = base::UTF16ToUTF8(profile->GetInfo( |
| 45 autofill::AutofillType(autofill::NAME_FULL), app_locale)); |
| 46 |
| 47 // TODO(crbug.com/705945): Format phone number according to spec. |
| 48 payment_address->phone = |
| 49 base::UTF16ToUTF8(profile->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); |
| 50 |
| 51 return payment_address; |
| 52 } |
| 53 |
| 54 } // namespace payments |
OLD | NEW |