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

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

Issue 2963163002: [Payment Request] Displays accepted card types (credit, debit, etc) in iOS (Closed)
Patch Set: Created 3 years, 5 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/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_country.h" 11 #include "components/autofill/core/browser/autofill_country.h"
12 #include "components/autofill/core/browser/autofill_data_util.h" 12 #include "components/autofill/core/browser/autofill_data_util.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 13 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/autofill/core/browser/field_types.h" 14 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/browser/personal_data_manager.h" 15 #include "components/autofill/core/browser/personal_data_manager.h"
17 #include "components/autofill/core/browser/validation.h" 16 #include "components/autofill/core/browser/validation.h"
18 #include "components/payments/core/basic_card_response.h" 17 #include "components/payments/core/basic_card_response.h"
19 #include "components/payments/core/payment_address.h" 18 #include "components/payments/core/payment_address.h"
20 #include "components/payments/core/payment_method_data.h" 19 #include "components/payments/core/payment_method_data.h"
21 #include "third_party/libphonenumber/phonenumber_api.h" 20 #include "third_party/libphonenumber/phonenumber_api.h"
22 21
23 namespace payments { 22 namespace payments {
24 namespace data_util { 23 namespace data_util {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 kBasicCardNetworks.end()) { 146 kBasicCardNetworks.end()) {
148 out_basic_card_specified_networks->insert(supported_network); 147 out_basic_card_specified_networks->insert(supported_network);
149 } 148 }
150 } 149 }
151 } 150 }
152 } 151 }
153 } 152 }
154 } 153 }
155 } 154 }
156 155
156 void ParseSupportedCardTypes(
157 const std::vector<PaymentMethodData>& method_data,
158 std::set<autofill::CreditCard::CardType>* out_supported_card_types_set) {
159 DCHECK(out_supported_card_types_set->empty());
160
161 for (const PaymentMethodData& method_data_entry : method_data) {
please use gerrit instead 2017/06/29 19:31:49 You should ignore all |method_data_entry| items wh
Moe 2017/06/30 15:44:57 Done.
162 for (const autofill::CreditCard::CardType& card_type :
163 method_data_entry.supported_types) {
164 out_supported_card_types_set->insert(card_type);
165 }
166
please use gerrit instead 2017/06/29 19:31:49 The outer for loop should stop here.
Moe 2017/06/30 15:44:57 My bad. Done.
167 // Omitting the card types means all 3 card types are supported.
168 if (out_supported_card_types_set->empty()) {
169 out_supported_card_types_set->insert(
170 autofill::CreditCard::CARD_TYPE_CREDIT);
171 out_supported_card_types_set->insert(
172 autofill::CreditCard::CARD_TYPE_DEBIT);
173 out_supported_card_types_set->insert(
174 autofill::CreditCard::CARD_TYPE_PREPAID);
175 }
176
177 // Let the user decide whether an unknown card type should be used.
178 out_supported_card_types_set->insert(
179 autofill::CreditCard::CARD_TYPE_UNKNOWN);
180 }
181 }
182
157 base::string16 GetFormattedPhoneNumberForDisplay( 183 base::string16 GetFormattedPhoneNumberForDisplay(
158 const autofill::AutofillProfile& profile, 184 const autofill::AutofillProfile& profile,
159 const std::string& locale) { 185 const std::string& locale) {
160 // Since the "+" is removed for some country's phone numbers, try to add a "+" 186 // Since the "+" is removed for some country's phone numbers, try to add a "+"
161 // and see if it is a valid phone number for a country. 187 // and see if it is a valid phone number for a country.
162 // Having two "+" in front of a number has no effect on the formatted number. 188 // Having two "+" in front of a number has no effect on the formatted number.
163 // The reason for this is international phone numbers for another country. For 189 // The reason for this is international phone numbers for another country. For
164 // example, without adding a "+", the US number 1-415-123-1234 for an AU 190 // example, without adding a "+", the US number 1-415-123-1234 for an AU
165 // address would be wrongly formatted as +61 1-415-123-1234 which is invalid. 191 // address would be wrongly formatted as +61 1-415-123-1234 which is invalid.
166 std::string phone = base::UTF16ToUTF8(profile.GetInfo( 192 std::string phone = base::UTF16ToUTF8(profile.GetInfo(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 const std::string& app_locale) { 242 const std::string& app_locale) {
217 std::string country_code = 243 std::string country_code =
218 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); 244 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
219 if (!autofill::data_util::IsValidCountryCode(country_code)) 245 if (!autofill::data_util::IsValidCountryCode(country_code))
220 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale); 246 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale);
221 return country_code; 247 return country_code;
222 } 248 }
223 249
224 } // namespace data_util 250 } // namespace data_util
225 } // namespace payments 251 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/payment_request_data_util.h ('k') | ios/chrome/browser/payments/payment_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698