| 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_state.h" | 5 #include "components/payments/content/payment_request_state.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 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/payments/content/payment_request_delegate.h" |
| 14 #include "components/payments/content/payment_request_spec.h" | 15 #include "components/payments/content/payment_request_spec.h" |
| 15 #include "components/payments/content/payment_response_helper.h" | 16 #include "components/payments/content/payment_response_helper.h" |
| 16 #include "components/payments/core/autofill_payment_instrument.h" | 17 #include "components/payments/core/autofill_payment_instrument.h" |
| 17 | 18 |
| 18 namespace payments { | 19 namespace payments { |
| 19 | 20 |
| 20 PaymentRequestState::PaymentRequestState( | 21 PaymentRequestState::PaymentRequestState( |
| 21 PaymentRequestSpec* spec, | 22 PaymentRequestSpec* spec, |
| 22 Delegate* delegate, | 23 Delegate* delegate, |
| 23 const std::string& app_locale, | 24 const std::string& app_locale, |
| 24 autofill::PersonalDataManager* personal_data_manager) | 25 autofill::PersonalDataManager* personal_data_manager, |
| 26 AutofillPaymentInstrument::FullCardRequestDelegate* |
| 27 full_card_request_delegate) |
| 25 : is_ready_to_pay_(false), | 28 : is_ready_to_pay_(false), |
| 26 app_locale_(app_locale), | 29 app_locale_(app_locale), |
| 27 spec_(spec), | 30 spec_(spec), |
| 28 delegate_(delegate), | 31 delegate_(delegate), |
| 29 personal_data_manager_(personal_data_manager), | 32 personal_data_manager_(personal_data_manager), |
| 30 selected_shipping_profile_(nullptr), | 33 selected_shipping_profile_(nullptr), |
| 31 selected_contact_profile_(nullptr), | 34 selected_contact_profile_(nullptr), |
| 32 selected_instrument_(nullptr) { | 35 selected_instrument_(nullptr), |
| 36 full_card_request_delegate_(full_card_request_delegate) { |
| 33 PopulateProfileCache(); | 37 PopulateProfileCache(); |
| 34 SetDefaultProfileSelections(); | 38 SetDefaultProfileSelections(); |
| 35 } | 39 } |
| 36 PaymentRequestState::~PaymentRequestState() {} | 40 PaymentRequestState::~PaymentRequestState() {} |
| 37 | 41 |
| 38 bool PaymentRequestState::CanMakePayment() const { | 42 bool PaymentRequestState::CanMakePayment() const { |
| 39 for (const std::unique_ptr<PaymentInstrument>& instrument : | 43 for (const std::unique_ptr<PaymentInstrument>& instrument : |
| 40 available_instruments_) { | 44 available_instruments_) { |
| 41 if (instrument.get()->IsValid() && | 45 if (instrument.get()->IsValid() && |
| 42 spec_->supported_card_networks_set().count( | 46 spec_->supported_card_networks_set().count( |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 if (!supported_card_networks.count(basic_card_network)) | 180 if (!supported_card_networks.count(basic_card_network)) |
| 177 continue; | 181 continue; |
| 178 | 182 |
| 179 // TODO(crbug.com/701952): Should use the method name preferred by the | 183 // TODO(crbug.com/701952): Should use the method name preferred by the |
| 180 // merchant (either "basic-card" or the basic card network e.g. "visa"). | 184 // merchant (either "basic-card" or the basic card network e.g. "visa"). |
| 181 | 185 |
| 182 // Copy the credit cards as part of AutofillPaymentInstrument so they are | 186 // Copy the credit cards as part of AutofillPaymentInstrument so they are |
| 183 // indirectly owned by this object. | 187 // indirectly owned by this object. |
| 184 std::unique_ptr<PaymentInstrument> instrument = | 188 std::unique_ptr<PaymentInstrument> instrument = |
| 185 base::MakeUnique<AutofillPaymentInstrument>( | 189 base::MakeUnique<AutofillPaymentInstrument>( |
| 186 basic_card_network, *card, shipping_profiles_, app_locale_); | 190 basic_card_network, *card, shipping_profiles_, app_locale_, |
| 191 full_card_request_delegate_); |
| 187 available_instruments_.push_back(std::move(instrument)); | 192 available_instruments_.push_back(std::move(instrument)); |
| 188 } | 193 } |
| 189 } | 194 } |
| 190 | 195 |
| 191 void PaymentRequestState::SetDefaultProfileSelections() { | 196 void PaymentRequestState::SetDefaultProfileSelections() { |
| 192 // Only pre-select an address if the merchant provided at least one selected | 197 // Only pre-select an address if the merchant provided at least one selected |
| 193 // shipping option. | 198 // shipping option. |
| 194 if (!shipping_profiles().empty() && spec_->selected_shipping_option()) | 199 if (!shipping_profiles().empty() && spec_->selected_shipping_option()) |
| 195 selected_shipping_profile_ = shipping_profiles()[0]; | 200 selected_shipping_profile_ = shipping_profiles()[0]; |
| 196 | 201 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), | 265 ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), |
| 261 app_locale_) | 266 app_locale_) |
| 262 .empty())) { | 267 .empty())) { |
| 263 return false; | 268 return false; |
| 264 } | 269 } |
| 265 | 270 |
| 266 return true; | 271 return true; |
| 267 } | 272 } |
| 268 | 273 |
| 269 } // namespace payments | 274 } // namespace payments |
| OLD | NEW |