| 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/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/autofill_data_util.h" | 10 #include "components/autofill/core/browser/autofill_data_util.h" |
| 11 #include "components/autofill/core/browser/autofill_profile.h" | 11 #include "components/autofill/core/browser/autofill_profile.h" |
| 12 #include "components/autofill/core/browser/credit_card.h" | 12 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/autofill/core/browser/personal_data_manager.h" | 13 #include "components/autofill/core/browser/personal_data_manager.h" |
| 14 #include "components/autofill/core/browser/region_data_loader_impl.h" | 14 #include "components/autofill/core/browser/region_data_loader_impl.h" |
| 15 #include "components/payments/core/currency_formatter.h" | 15 #include "components/payments/core/currency_formatter.h" |
| 16 #include "components/payments/core/payment_request_data_util.h" | 16 #include "components/payments/core/payment_request_data_util.h" |
| 17 #include "components/payments/core/payments_profile_comparator.h" | |
| 18 #include "ios/chrome/browser/application_context.h" | 17 #include "ios/chrome/browser/application_context.h" |
| 19 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | 18 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" |
| 20 #include "ios/web/public/payments/payment_request.h" | 19 #include "ios/web/public/payments/payment_request.h" |
| 21 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" | 20 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" |
| 22 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" | 21 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" |
| 23 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" | 22 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" |
| 24 | 23 |
| 25 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 26 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
| 27 #endif | 26 #endif |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 autofill::CreditCard* PaymentRequest::AddCreditCard( | 174 autofill::CreditCard* PaymentRequest::AddCreditCard( |
| 176 const autofill::CreditCard& credit_card) { | 175 const autofill::CreditCard& credit_card) { |
| 177 credit_card_cache_.push_back( | 176 credit_card_cache_.push_back( |
| 178 base::MakeUnique<autofill::CreditCard>(credit_card)); | 177 base::MakeUnique<autofill::CreditCard>(credit_card)); |
| 179 | 178 |
| 180 PopulateAvailableCreditCards(); | 179 PopulateAvailableCreditCards(); |
| 181 | 180 |
| 182 return credit_card_cache_.back().get(); | 181 return credit_card_cache_.back().get(); |
| 183 } | 182 } |
| 184 | 183 |
| 184 payments::PaymentsProfileComparator* PaymentRequest::profile_comparator() { |
| 185 return &profile_comparator_; |
| 186 } |
| 187 |
| 185 bool PaymentRequest::CanMakePayment() const { | 188 bool PaymentRequest::CanMakePayment() const { |
| 186 return !credit_cards_.empty(); | 189 return !credit_cards_.empty(); |
| 187 } | 190 } |
| 188 | 191 |
| 189 void PaymentRequest::PopulateCreditCardCache() { | 192 void PaymentRequest::PopulateCreditCardCache() { |
| 190 // TODO(crbug.com/709036): Validate method data. | 193 // TODO(crbug.com/709036): Validate method data. |
| 191 payments::data_util::ParseBasicCardSupportedNetworks( | 194 payments::data_util::ParseBasicCardSupportedNetworks( |
| 192 web_payment_request_.method_data, &supported_card_networks_, | 195 web_payment_request_.method_data, &supported_card_networks_, |
| 193 &basic_card_specified_networks_); | 196 &basic_card_specified_networks_); |
| 194 | 197 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 void PaymentRequest::SetSelectedShippingOption() { | 246 void PaymentRequest::SetSelectedShippingOption() { |
| 244 // If more than one option has |selected| set, the last one in the sequence | 247 // If more than one option has |selected| set, the last one in the sequence |
| 245 // should be treated as the selected item. | 248 // should be treated as the selected item. |
| 246 for (auto* shipping_option : base::Reversed(shipping_options_)) { | 249 for (auto* shipping_option : base::Reversed(shipping_options_)) { |
| 247 if (shipping_option->selected) { | 250 if (shipping_option->selected) { |
| 248 selected_shipping_option_ = shipping_option; | 251 selected_shipping_option_ = shipping_option; |
| 249 break; | 252 break; |
| 250 } | 253 } |
| 251 } | 254 } |
| 252 } | 255 } |
| OLD | NEW |