Chromium Code Reviews| Index: components/payments/core/payment_request_data_util.cc |
| diff --git a/components/payments/core/payment_request_data_util.cc b/components/payments/core/payment_request_data_util.cc |
| index c005e14bd273d6f78399cd6c2d06458065677bcf..907f136589e2bf7b6b04f2b593226ab5b0be2f5b 100644 |
| --- a/components/payments/core/payment_request_data_util.cc |
| +++ b/components/payments/core/payment_request_data_util.cc |
| @@ -14,10 +14,34 @@ |
| #include "components/payments/core/basic_card_response.h" |
| #include "components/payments/core/payment_address.h" |
| #include "components/payments/core/payment_method_data.h" |
| +#include "third_party/libphonenumber/phonenumber_api.h" |
| namespace payments { |
| namespace data_util { |
| +namespace { |
| +using ::i18n::phonenumbers::PhoneNumber; |
| +using ::i18n::phonenumbers::PhoneNumberUtil; |
| + |
| +// Formats the |phone_number| to the specified |format|. Returns the original |
| +// number if the operation is not possible. |
| +std::string FormatPhoneNumber(const std::string& phone_number, |
| + const std::string& country_code, |
| + PhoneNumberUtil::PhoneNumberFormat format) { |
| + PhoneNumber parsed_number; |
| + PhoneNumberUtil* phone_number_util = PhoneNumberUtil::GetInstance(); |
| + if (phone_number_util->Parse(phone_number, country_code, &parsed_number) != |
| + PhoneNumberUtil::NO_PARSING_ERROR) { |
| + return phone_number; |
| + } |
| + |
| + std::string formatted_number; |
| + phone_number_util->Format(parsed_number, format, &formatted_number); |
| + return formatted_number; |
| +} |
| + |
| +} // namespace |
| + |
| PaymentAddress GetPaymentAddressFromAutofillProfile( |
| const autofill::AutofillProfile& profile, |
| const std::string& app_locale) { |
| @@ -132,5 +156,25 @@ bool ParseBasicCardSupportedNetworks( |
| return true; |
| } |
| +// Formats the given number |jphone_number| to |
|
Mathieu
2017/04/13 17:59:48
update comment
|
| +// i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL format |
| +// by using i18n::phonenumbers::PhoneNumberUtil::Format. |
| +std::string FormatPhoneForDisplay(const std::string& phone_number, |
| + const std::string& country_code) { |
| + return FormatPhoneNumber(phone_number, country_code, |
| + PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); |
| +} |
| + |
| +// Formats the given number |jphone_number| to |
|
Mathieu
2017/04/13 17:59:48
same
|
| +// i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat::E164 format by using |
| +// i18n::phonenumbers::PhoneNumberUtil::Format , as defined in the Payment |
| +// Request spec |
| +// (https://w3c.github.io/browser-payment-api/#paymentrequest-updated-algorithm) |
| +std::string FormatPhoneForResponse(const std::string& phone_number, |
| + const std::string& country_code) { |
| + return FormatPhoneNumber(phone_number, country_code, |
| + PhoneNumberUtil::PhoneNumberFormat::E164); |
| +} |
| + |
| } // namespace data_util |
| } // namespace payments |