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

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: Addressed comments 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 <algorithm>
8
7 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
8 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_country.h" 13 #include "components/autofill/core/browser/autofill_country.h"
12 #include "components/autofill/core/browser/autofill_data_util.h" 14 #include "components/autofill/core/browser/autofill_data_util.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 15 #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" 16 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/browser/personal_data_manager.h" 17 #include "components/autofill/core/browser/personal_data_manager.h"
17 #include "components/autofill/core/browser/validation.h" 18 #include "components/autofill/core/browser/validation.h"
18 #include "components/payments/core/basic_card_response.h" 19 #include "components/payments/core/basic_card_response.h"
19 #include "components/payments/core/payment_address.h" 20 #include "components/payments/core/payment_address.h"
20 #include "components/payments/core/payment_method_data.h" 21 #include "components/payments/core/payment_method_data.h"
21 #include "third_party/libphonenumber/phonenumber_api.h" 22 #include "third_party/libphonenumber/phonenumber_api.h"
22 23
23 namespace payments { 24 namespace payments {
24 namespace data_util { 25 namespace data_util {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 kBasicCardNetworks.end()) { 148 kBasicCardNetworks.end()) {
148 out_basic_card_specified_networks->insert(supported_network); 149 out_basic_card_specified_networks->insert(supported_network);
149 } 150 }
150 } 151 }
151 } 152 }
152 } 153 }
153 } 154 }
154 } 155 }
155 } 156 }
156 157
158 void ParseSupportedCardTypes(
159 const std::vector<PaymentMethodData>& method_data,
160 std::set<autofill::CreditCard::CardType>* out_supported_card_types_set) {
161 DCHECK(out_supported_card_types_set->empty());
162
163 const char kBasicCardMethodName[] = "basic-card";
164 for (const PaymentMethodData& method_data_entry : method_data) {
165 const std::vector<std::string>& supported_methods =
166 method_data_entry.supported_methods;
167 // Ignore |supported_types| if |supported_methods| does not contain
168 // "basic_card".
169 const auto method_it =
170 std::find(supported_methods.begin(), supported_methods.end(),
171 kBasicCardMethodName);
172 if (method_it == supported_methods.end())
please use gerrit instead 2017/06/30 15:49:40 if (!base::ContainsValue(supported_methods, "basic
Moe 2017/06/30 20:47:18 This is cool! Done.
173 continue;
174
175 for (const autofill::CreditCard::CardType& card_type :
176 method_data_entry.supported_types) {
177 out_supported_card_types_set->insert(card_type);
178 }
179 }
180
181 // Omitting the card types means all 3 card types are supported.
182 if (out_supported_card_types_set->empty()) {
183 out_supported_card_types_set->insert(
184 autofill::CreditCard::CARD_TYPE_CREDIT);
185 out_supported_card_types_set->insert(autofill::CreditCard::CARD_TYPE_DEBIT);
186 out_supported_card_types_set->insert(
187 autofill::CreditCard::CARD_TYPE_PREPAID);
188 }
189
190 // Let the user decide whether an unknown card type should be used.
191 out_supported_card_types_set->insert(autofill::CreditCard::CARD_TYPE_UNKNOWN);
192 }
193
157 base::string16 GetFormattedPhoneNumberForDisplay( 194 base::string16 GetFormattedPhoneNumberForDisplay(
158 const autofill::AutofillProfile& profile, 195 const autofill::AutofillProfile& profile,
159 const std::string& locale) { 196 const std::string& locale) {
160 // Since the "+" is removed for some country's phone numbers, try to add a "+" 197 // 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. 198 // 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. 199 // 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 200 // 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 201 // 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. 202 // address would be wrongly formatted as +61 1-415-123-1234 which is invalid.
166 std::string phone = base::UTF16ToUTF8(profile.GetInfo( 203 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) { 253 const std::string& app_locale) {
217 std::string country_code = 254 std::string country_code =
218 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); 255 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
219 if (!autofill::data_util::IsValidCountryCode(country_code)) 256 if (!autofill::data_util::IsValidCountryCode(country_code))
220 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale); 257 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale);
221 return country_code; 258 return country_code;
222 } 259 }
223 260
224 } // namespace data_util 261 } // namespace data_util
225 } // namespace payments 262 } // 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