Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: components/payments/core/payment_request_data_util.cc

Issue 2808983003: [Payments] Format shipping and billing phone number in normalizer. (Closed)
Patch Set: Nits Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « components/payments/core/payment_request_data_util.h ('k') | components/payments/core/payment_request_data_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698