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 "ios/chrome/browser/payments/payment_request.h" | 5 #include "ios/chrome/browser/payments/payment_request.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/browser/autofill_data_util.h" | 8 #include "components/autofill/core/browser/autofill_data_util.h" |
9 #include "components/autofill/core/browser/autofill_profile.h" | 9 #include "components/autofill/core/browser/autofill_profile.h" |
10 #include "components/autofill/core/browser/credit_card.h" | 10 #include "components/autofill/core/browser/credit_card.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 contact_profiles_, GetApplicationContext()->GetApplicationLocale(), | 101 contact_profiles_, GetApplicationContext()->GetApplicationLocale(), |
102 *this); | 102 *this); |
103 | 103 |
104 if (!shipping_profiles_.empty()) | 104 if (!shipping_profiles_.empty()) |
105 selected_shipping_profile_ = shipping_profiles_[0]; | 105 selected_shipping_profile_ = shipping_profiles_[0]; |
106 if (!contact_profiles_.empty()) | 106 if (!contact_profiles_.empty()) |
107 selected_contact_profile_ = contact_profiles_[0]; | 107 selected_contact_profile_ = contact_profiles_[0]; |
108 } | 108 } |
109 | 109 |
110 void PaymentRequest::PopulateCreditCardCache() { | 110 void PaymentRequest::PopulateCreditCardCache() { |
111 if (!payments::data_util::ParseBasicCardSupportedNetworks( | 111 // TODO(crbug.com/709036): Validate method data. |
112 web_payment_request_.method_data, &supported_card_networks_, | 112 payments::data_util::ParseBasicCardSupportedNetworks( |
113 &basic_card_specified_networks_)) { | 113 web_payment_request_.method_data, &supported_card_networks_, |
114 // TODO(crbug.com/709036): close the UI and reject the promise since the | 114 &basic_card_specified_networks_); |
115 // data is invalid. | |
116 return; | |
117 } | |
118 | 115 |
119 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest = | 116 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest = |
120 personal_data_manager_->GetCreditCardsToSuggest(); | 117 personal_data_manager_->GetCreditCardsToSuggest(); |
121 credit_card_cache_.reserve(credit_cards_to_suggest.size()); | 118 credit_card_cache_.reserve(credit_cards_to_suggest.size()); |
122 | 119 |
123 for (const auto* credit_card : credit_cards_to_suggest) { | 120 for (const auto* credit_card : credit_cards_to_suggest) { |
124 std::string spec_card_type = | 121 std::string spec_card_type = |
125 autofill::data_util::GetPaymentRequestData(credit_card->type()) | 122 autofill::data_util::GetPaymentRequestData(credit_card->type()) |
126 .basic_card_payment_type; | 123 .basic_card_payment_type; |
127 if (std::find(supported_card_networks_.begin(), | 124 if (std::find(supported_card_networks_.begin(), |
(...skipping 21 matching lines...) Expand all Loading... |
149 | 146 |
150 selected_shipping_option_ = nullptr; | 147 selected_shipping_option_ = nullptr; |
151 for (auto* shipping_option : shipping_options_) { | 148 for (auto* shipping_option : shipping_options_) { |
152 if (shipping_option->selected) { | 149 if (shipping_option->selected) { |
153 // If more than one option has |selected| set, the last one in the | 150 // If more than one option has |selected| set, the last one in the |
154 // sequence should be treated as the selected item. | 151 // sequence should be treated as the selected item. |
155 selected_shipping_option_ = shipping_option; | 152 selected_shipping_option_ = shipping_option; |
156 } | 153 } |
157 } | 154 } |
158 } | 155 } |
OLD | NEW |