| 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..8fb6572312222574f9e3c93a5244aca9dfe42716 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,17 @@ bool ParseBasicCardSupportedNetworks(
|
| return true;
|
| }
|
|
|
| +std::string FormatPhoneForDisplay(const std::string& phone_number,
|
| + const std::string& country_code) {
|
| + return FormatPhoneNumber(phone_number, country_code,
|
| + PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL);
|
| +}
|
| +
|
| +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
|
|
|