OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/content/payment_request_spec.h" | 5 #include "components/payments/content/payment_request_spec.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "components/payments/core/payment_method_data.h" | 10 #include "components/payments/core/payment_method_data.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 &supported_card_networks_, | 159 &supported_card_networks_, |
160 &basic_card_specified_networks_); | 160 &basic_card_specified_networks_); |
161 supported_card_networks_set_.insert(supported_card_networks_.begin(), | 161 supported_card_networks_set_.insert(supported_card_networks_.begin(), |
162 supported_card_networks_.end()); | 162 supported_card_networks_.end()); |
163 } | 163 } |
164 | 164 |
165 void PaymentRequestSpec::UpdateSelectedShippingOption() { | 165 void PaymentRequestSpec::UpdateSelectedShippingOption() { |
166 if (!request_shipping()) | 166 if (!request_shipping()) |
167 return; | 167 return; |
168 | 168 |
| 169 selected_shipping_option_error_.clear(); |
169 // As per the spec, the selected shipping option should initially be the last | 170 // As per the spec, the selected shipping option should initially be the last |
170 // one in the array that has its selected field set to true. | 171 // one in the array that has its selected field set to true. |
171 auto selected_shipping_option_it = std::find_if( | 172 auto selected_shipping_option_it = std::find_if( |
172 details().shipping_options.rbegin(), details().shipping_options.rend(), | 173 details().shipping_options.rbegin(), details().shipping_options.rend(), |
173 [](const payments::mojom::PaymentShippingOptionPtr& element) { | 174 [](const payments::mojom::PaymentShippingOptionPtr& element) { |
174 return element->selected; | 175 return element->selected; |
175 }); | 176 }); |
176 if (selected_shipping_option_it != details().shipping_options.rend()) { | 177 if (selected_shipping_option_it != details().shipping_options.rend()) { |
177 selected_shipping_option_ = selected_shipping_option_it->get(); | 178 selected_shipping_option_ = selected_shipping_option_it->get(); |
178 } else { | 179 } else { |
179 // It's possible that there is no selected shipping option. | 180 // It's possible that there is no selected shipping option. |
180 // TODO(crbug.com/710004): Show an error in this case. | 181 if (!details().error.empty()) |
| 182 selected_shipping_option_error_ = details().error; |
181 selected_shipping_option_ = nullptr; | 183 selected_shipping_option_ = nullptr; |
182 } | 184 } |
183 } | 185 } |
184 | 186 |
185 void PaymentRequestSpec::NotifyOnSpecUpdated() { | 187 void PaymentRequestSpec::NotifyOnSpecUpdated() { |
186 for (auto& observer : observers_) | 188 for (auto& observer : observers_) |
187 observer.OnSpecUpdated(); | 189 observer.OnSpecUpdated(); |
188 if (observer_for_testing_) | 190 if (observer_for_testing_) |
189 observer_for_testing_->OnSpecUpdated(); | 191 observer_for_testing_->OnSpecUpdated(); |
190 } | 192 } |
191 | 193 |
192 CurrencyFormatter* PaymentRequestSpec::GetOrCreateCurrencyFormatter( | 194 CurrencyFormatter* PaymentRequestSpec::GetOrCreateCurrencyFormatter( |
193 const std::string& currency_code, | 195 const std::string& currency_code, |
194 const std::string& currency_system, | 196 const std::string& currency_system, |
195 const std::string& locale_name) { | 197 const std::string& locale_name) { |
196 if (!currency_formatter_) { | 198 if (!currency_formatter_) { |
197 currency_formatter_.reset( | 199 currency_formatter_.reset( |
198 new CurrencyFormatter(currency_code, currency_system, locale_name)); | 200 new CurrencyFormatter(currency_code, currency_system, locale_name)); |
199 } | 201 } |
200 return currency_formatter_.get(); | 202 return currency_formatter_.get(); |
201 } | 203 } |
202 | 204 |
203 } // namespace payments | 205 } // namespace payments |
OLD | NEW |