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

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

Issue 2916313002: Merge-60 [Payments] Don't show error for intl phone from other country. (Closed)
Patch Set: Created 3 years, 6 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_country.h" 10 #include "components/autofill/core/browser/autofill_country.h"
11 #include "components/autofill/core/browser/autofill_data_util.h" 11 #include "components/autofill/core/browser/autofill_data_util.h"
12 #include "components/autofill/core/browser/autofill_profile.h" 12 #include "components/autofill/core/browser/autofill_profile.h"
13 #include "components/autofill/core/browser/credit_card.h" 13 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/field_types.h" 14 #include "components/autofill/core/browser/field_types.h"
15 #include "components/autofill/core/browser/personal_data_manager.h" 15 #include "components/autofill/core/browser/personal_data_manager.h"
16 #include "components/autofill/core/browser/validation.h"
16 #include "components/payments/core/basic_card_response.h" 17 #include "components/payments/core/basic_card_response.h"
17 #include "components/payments/core/payment_address.h" 18 #include "components/payments/core/payment_address.h"
18 #include "components/payments/core/payment_method_data.h" 19 #include "components/payments/core/payment_method_data.h"
19 #include "third_party/libphonenumber/phonenumber_api.h" 20 #include "third_party/libphonenumber/phonenumber_api.h"
20 21
21 namespace payments { 22 namespace payments {
22 namespace data_util { 23 namespace data_util {
23 24
24 namespace { 25 namespace {
25 using ::i18n::phonenumbers::PhoneNumber; 26 using ::i18n::phonenumbers::PhoneNumber;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Since the "+" is removed for some country's phone numbers, try to add a "+" 159 // Since the "+" is removed for some country's phone numbers, try to add a "+"
159 // and see if it is a valid phone number for a country. 160 // and see if it is a valid phone number for a country.
160 // Having two "+" in front of a number has no effect on the formatted number. 161 // Having two "+" in front of a number has no effect on the formatted number.
161 // The reason for this is international phone numbers for another country. For 162 // The reason for this is international phone numbers for another country. For
162 // example, without adding a "+", the US number 1-415-123-1234 for an AU 163 // example, without adding a "+", the US number 1-415-123-1234 for an AU
163 // address would be wrongly formatted as +61 1-415-123-1234 which is invalid. 164 // address would be wrongly formatted as +61 1-415-123-1234 which is invalid.
164 std::string phone = base::UTF16ToUTF8(profile.GetInfo( 165 std::string phone = base::UTF16ToUTF8(profile.GetInfo(
165 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale)); 166 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale));
166 std::string tentative_intl_phone = "+" + phone; 167 std::string tentative_intl_phone = "+" + phone;
167 168
168 autofill::i18n::PhoneObject phone_obj(
169 base::UTF8ToUTF16(phone), GetCountryCodeWithFallback(&profile, locale));
170 autofill::i18n::PhoneObject tentative_intl_phone_obj(
171 base::UTF8ToUTF16(tentative_intl_phone),
172 GetCountryCodeWithFallback(&profile, locale));
173
174 // Always favor the tentative international phone number if it's determined as 169 // Always favor the tentative international phone number if it's determined as
175 // being a valid number. 170 // being a valid number.
176 if (!tentative_intl_phone_obj.region().empty()) { 171 if (autofill::IsValidPhoneNumber(
172 base::UTF8ToUTF16(tentative_intl_phone),
173 GetCountryCodeWithFallback(&profile, locale))) {
177 return base::UTF8ToUTF16(FormatPhoneForDisplay( 174 return base::UTF8ToUTF16(FormatPhoneForDisplay(
178 tentative_intl_phone, GetCountryCodeWithFallback(&profile, locale))); 175 tentative_intl_phone, GetCountryCodeWithFallback(&profile, locale)));
179 } 176 }
180 177
181 return base::UTF8ToUTF16(FormatPhoneForDisplay( 178 return base::UTF8ToUTF16(FormatPhoneForDisplay(
182 phone, GetCountryCodeWithFallback(&profile, locale))); 179 phone, GetCountryCodeWithFallback(&profile, locale)));
183 } 180 }
184 181
185 std::string FormatPhoneForDisplay(const std::string& phone_number, 182 std::string FormatPhoneForDisplay(const std::string& phone_number,
186 const std::string& country_code) { 183 const std::string& country_code) {
(...skipping 11 matching lines...) Expand all
198 const std::string& app_locale) { 195 const std::string& app_locale) {
199 std::string country_code = 196 std::string country_code =
200 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); 197 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
201 if (!autofill::data_util::IsValidCountryCode(country_code)) 198 if (!autofill::data_util::IsValidCountryCode(country_code))
202 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale); 199 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale);
203 return country_code; 200 return country_code;
204 } 201 }
205 202
206 } // namespace data_util 203 } // namespace data_util
207 } // namespace payments 204 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698