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

Side by Side Diff: components/payments/core/payment_request_data_util.cc

Issue 2808983003: [Payments] Format shipping and billing phone number in normalizer. (Closed)
Patch Set: Moved phone format function to util file 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 unified diff | Download patch
OLDNEW
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
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 // Formats the given number |jphone_number| to
Mathieu 2017/04/13 17:59:48 update comment
160 // i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL format
161 // by using i18n::phonenumbers::PhoneNumberUtil::Format.
162 std::string FormatPhoneForDisplay(const std::string& phone_number,
163 const std::string& country_code) {
164 return FormatPhoneNumber(phone_number, country_code,
165 PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL);
166 }
167
168 // Formats the given number |jphone_number| to
Mathieu 2017/04/13 17:59:48 same
169 // i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat::E164 format by using
170 // i18n::phonenumbers::PhoneNumberUtil::Format , as defined in the Payment
171 // Request spec
172 // (https://w3c.github.io/browser-payment-api/#paymentrequest-updated-algorithm)
173 std::string FormatPhoneForResponse(const std::string& phone_number,
174 const std::string& country_code) {
175 return FormatPhoneNumber(phone_number, country_code,
176 PhoneNumberUtil::PhoneNumberFormat::E164);
177 }
178
135 } // namespace data_util 179 } // namespace data_util
136 } // namespace payments 180 } // namespace payments
OLDNEW
« 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