| 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" |
| 11 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
| 12 #include "components/autofill/core/browser/field_types.h" | 12 #include "components/autofill/core/browser/field_types.h" |
| 13 #include "components/autofill/core/browser/personal_data_manager.h" | 13 #include "components/autofill/core/browser/personal_data_manager.h" |
| 14 #include "components/payments/core/basic_card_response.h" | 14 #include "components/payments/core/basic_card_response.h" |
| 15 #include "components/payments/core/payment_address.h" | 15 #include "components/payments/core/payment_address.h" |
| 16 #include "components/payments/core/payment_method_data.h" | 16 #include "components/payments/core/payment_method_data.h" |
| 17 #include "third_party/libphonenumber/phonenumber_api.h" |
| 17 | 18 |
| 18 namespace payments { | 19 namespace payments { |
| 19 namespace data_util { | 20 namespace data_util { |
| 20 | 21 |
| 22 namespace { |
| 23 using ::i18n::phonenumbers::PhoneNumber; |
| 24 using ::i18n::phonenumbers::PhoneNumberUtil; |
| 25 |
| 26 // Formats the |phone_number| to the specified |format|. Returns the original |
| 27 // number if the operation is not possible. |
| 28 std::string FormatPhoneNumber(const std::string& phone_number, |
| 29 const std::string& country_code, |
| 30 PhoneNumberUtil::PhoneNumberFormat format) { |
| 31 PhoneNumber parsed_number; |
| 32 PhoneNumberUtil* phone_number_util = PhoneNumberUtil::GetInstance(); |
| 33 if (phone_number_util->Parse(phone_number, country_code, &parsed_number) != |
| 34 PhoneNumberUtil::NO_PARSING_ERROR) { |
| 35 return phone_number; |
| 36 } |
| 37 |
| 38 std::string formatted_number; |
| 39 phone_number_util->Format(parsed_number, format, &formatted_number); |
| 40 return formatted_number; |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
| 21 PaymentAddress GetPaymentAddressFromAutofillProfile( | 45 PaymentAddress GetPaymentAddressFromAutofillProfile( |
| 22 const autofill::AutofillProfile& profile, | 46 const autofill::AutofillProfile& profile, |
| 23 const std::string& app_locale) { | 47 const std::string& app_locale) { |
| 24 PaymentAddress address; | 48 PaymentAddress address; |
| 25 address.country = profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY); | 49 address.country = profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY); |
| 26 address.address_line = base::SplitString( | 50 address.address_line = base::SplitString( |
| 27 profile.GetInfo( | 51 profile.GetInfo( |
| 28 autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS), | 52 autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS), |
| 29 app_locale), | 53 app_locale), |
| 30 base::ASCIIToUTF16("\n"), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 54 base::ASCIIToUTF16("\n"), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 card_networks.erase(it); | 149 card_networks.erase(it); |
| 126 } | 150 } |
| 127 } | 151 } |
| 128 } | 152 } |
| 129 } | 153 } |
| 130 } | 154 } |
| 131 } | 155 } |
| 132 return true; | 156 return true; |
| 133 } | 157 } |
| 134 | 158 |
| 159 std::string FormatPhoneForDisplay(const std::string& phone_number, |
| 160 const std::string& country_code) { |
| 161 return FormatPhoneNumber(phone_number, country_code, |
| 162 PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); |
| 163 } |
| 164 |
| 165 std::string FormatPhoneForResponse(const std::string& phone_number, |
| 166 const std::string& country_code) { |
| 167 return FormatPhoneNumber(phone_number, country_code, |
| 168 PhoneNumberUtil::PhoneNumberFormat::E164); |
| 169 } |
| 170 |
| 135 } // namespace data_util | 171 } // namespace data_util |
| 136 } // namespace payments | 172 } // namespace payments |
| OLD | NEW |