| 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/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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( | 88 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
| 89 card.billing_address_id(), billing_profiles); | 89 card.billing_address_id(), billing_profiles); |
| 90 DCHECK(billing_address); | 90 DCHECK(billing_address); |
| 91 response.billing_address = | 91 response.billing_address = |
| 92 GetPaymentAddressFromAutofillProfile(*billing_address, app_locale); | 92 GetPaymentAddressFromAutofillProfile(*billing_address, app_locale); |
| 93 } | 93 } |
| 94 | 94 |
| 95 return response; | 95 return response; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool ParseBasicCardSupportedNetworks( | 98 void ParseBasicCardSupportedNetworks( |
| 99 const std::vector<PaymentMethodData>& method_data, | 99 const std::vector<PaymentMethodData>& method_data, |
| 100 std::vector<std::string>* out_supported_networks, | 100 std::vector<std::string>* out_supported_networks, |
| 101 std::set<std::string>* out_basic_card_specified_networks) { | 101 std::set<std::string>* out_basic_card_specified_networks) { |
| 102 DCHECK(out_supported_networks->empty()); | 102 DCHECK(out_supported_networks->empty()); |
| 103 DCHECK(out_basic_card_specified_networks->empty()); | 103 DCHECK(out_basic_card_specified_networks->empty()); |
| 104 | 104 |
| 105 std::set<std::string> card_networks{"amex", "diners", "discover", | 105 std::set<std::string> card_networks{"amex", "diners", "discover", |
| 106 "jcb", "mastercard", "mir", | 106 "jcb", "mastercard", "mir", |
| 107 "unionpay", "visa"}; | 107 "unionpay", "visa"}; |
| 108 for (const PaymentMethodData& method_data_entry : method_data) { | 108 for (const PaymentMethodData& method_data_entry : method_data) { |
| 109 if (method_data_entry.supported_methods.empty()) | 109 if (method_data_entry.supported_methods.empty()) |
| 110 return false; | 110 return; |
| 111 | 111 |
| 112 for (const std::string& method : method_data_entry.supported_methods) { | 112 for (const std::string& method : method_data_entry.supported_methods) { |
| 113 if (method.empty()) | 113 if (method.empty()) |
| 114 continue; | 114 continue; |
| 115 | 115 |
| 116 // If a card network is specified right in "supportedMethods", add it. | 116 // If a card network is specified right in "supportedMethods", add it. |
| 117 const char kBasicCardMethodName[] = "basic-card"; | 117 const char kBasicCardMethodName[] = "basic-card"; |
| 118 auto card_it = card_networks.find(method); | 118 auto card_it = card_networks.find(method); |
| 119 if (card_it != card_networks.end()) { | 119 if (card_it != card_networks.end()) { |
| 120 out_supported_networks->push_back(method); | 120 out_supported_networks->push_back(method); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 146 if (it != card_networks.end()) { | 146 if (it != card_networks.end()) { |
| 147 out_supported_networks->push_back(supported_network); | 147 out_supported_networks->push_back(supported_network); |
| 148 out_basic_card_specified_networks->insert(supported_network); | 148 out_basic_card_specified_networks->insert(supported_network); |
| 149 card_networks.erase(it); | 149 card_networks.erase(it); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 return true; | |
| 157 } | 156 } |
| 158 | 157 |
| 159 std::string FormatPhoneForDisplay(const std::string& phone_number, | 158 std::string FormatPhoneForDisplay(const std::string& phone_number, |
| 160 const std::string& country_code) { | 159 const std::string& country_code) { |
| 161 return FormatPhoneNumber(phone_number, country_code, | 160 return FormatPhoneNumber(phone_number, country_code, |
| 162 PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); | 161 PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); |
| 163 } | 162 } |
| 164 | 163 |
| 165 std::string FormatPhoneForResponse(const std::string& phone_number, | 164 std::string FormatPhoneForResponse(const std::string& phone_number, |
| 166 const std::string& country_code) { | 165 const std::string& country_code) { |
| 167 return FormatPhoneNumber(phone_number, country_code, | 166 return FormatPhoneNumber(phone_number, country_code, |
| 168 PhoneNumberUtil::PhoneNumberFormat::E164); | 167 PhoneNumberUtil::PhoneNumberFormat::E164); |
| 169 } | 168 } |
| 170 | 169 |
| 171 } // namespace data_util | 170 } // namespace data_util |
| 172 } // namespace payments | 171 } // namespace payments |
| OLD | NEW |