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