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 "components/autofill/core/browser/autofill_data_util.h" | 9 #include "components/autofill/core/browser/autofill_data_util.h" |
10 #include "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
11 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
12 #include "components/autofill/core/browser/personal_data_manager.h" | 12 #include "components/autofill/core/browser/personal_data_manager.h" |
13 #include "components/payments/content/payment_request_spec.h" | 13 #include "components/payments/content/payment_request_spec.h" |
| 14 #include "components/payments/content/payment_response_helper.h" |
14 #include "components/payments/core/autofill_payment_instrument.h" | 15 #include "components/payments/core/autofill_payment_instrument.h" |
15 | 16 |
16 namespace payments { | 17 namespace payments { |
17 | 18 |
18 PaymentRequestState::PaymentRequestState( | 19 PaymentRequestState::PaymentRequestState( |
19 PaymentRequestSpec* spec, | 20 PaymentRequestSpec* spec, |
20 Delegate* delegate, | 21 Delegate* delegate, |
21 const std::string& app_locale, | 22 const std::string& app_locale, |
22 autofill::PersonalDataManager* personal_data_manager) | 23 autofill::PersonalDataManager* personal_data_manager) |
23 : is_ready_to_pay_(false), | 24 : is_ready_to_pay_(false), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New(); | 64 mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New(); |
64 | 65 |
65 // Make sure that we return the method name that the merchant specified for | 66 // Make sure that we return the method name that the merchant specified for |
66 // this instrument: cards can be either specified through their name (e.g., | 67 // this instrument: cards can be either specified through their name (e.g., |
67 // "visa") or through basic-card's supportedNetworks. | 68 // "visa") or through basic-card's supportedNetworks. |
68 payment_response->method_name = | 69 payment_response->method_name = |
69 spec_->IsMethodSupportedThroughBasicCard(method_name) | 70 spec_->IsMethodSupportedThroughBasicCard(method_name) |
70 ? kBasicCardMethodName | 71 ? kBasicCardMethodName |
71 : method_name; | 72 : method_name; |
72 payment_response->stringified_details = stringified_details; | 73 payment_response->stringified_details = stringified_details; |
| 74 |
| 75 // Shipping Address section |
| 76 if (spec_->request_shipping()) { |
| 77 payment_response->shipping_address = |
| 78 PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( |
| 79 selected_shipping_profile_, app_locale_); |
| 80 } |
| 81 |
73 delegate_->OnPaymentResponseAvailable(std::move(payment_response)); | 82 delegate_->OnPaymentResponseAvailable(std::move(payment_response)); |
74 } | 83 } |
75 | 84 |
76 void PaymentRequestState::GeneratePaymentResponse() { | 85 void PaymentRequestState::GeneratePaymentResponse() { |
77 DCHECK(is_ready_to_pay()); | 86 DCHECK(is_ready_to_pay()); |
78 // Fetch the instrument details, will call back into | 87 // Fetch the instrument details, will call back into |
79 // PaymentRequest::OnInstrumentsDetailsReady. | 88 // PaymentRequest::OnInstrumentDetailsReady. |
80 selected_instrument_->InvokePaymentApp(this); | 89 selected_instrument_->InvokePaymentApp(this); |
81 } | 90 } |
82 | 91 |
83 void PaymentRequestState::SetSelectedShippingOption( | 92 void PaymentRequestState::SetSelectedShippingOption( |
84 mojom::PaymentShippingOption* option) { | 93 mojom::PaymentShippingOption* option) { |
85 selected_shipping_option_ = option; | 94 selected_shipping_option_ = option; |
86 UpdateIsReadyToPayAndNotifyObservers(); | 95 UpdateIsReadyToPayAndNotifyObservers(); |
87 } | 96 } |
88 | 97 |
89 void PaymentRequestState::SetSelectedShippingProfile( | 98 void PaymentRequestState::SetSelectedShippingProfile( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 spec_->details().shipping_options.rend(), | 247 spec_->details().shipping_options.rend(), |
239 [](const payments::mojom::PaymentShippingOptionPtr& element) { | 248 [](const payments::mojom::PaymentShippingOptionPtr& element) { |
240 return element->selected; | 249 return element->selected; |
241 }); | 250 }); |
242 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) { | 251 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) { |
243 selected_shipping_option_ = selected_shipping_option_it->get(); | 252 selected_shipping_option_ = selected_shipping_option_it->get(); |
244 } | 253 } |
245 } | 254 } |
246 | 255 |
247 } // namespace payments | 256 } // namespace payments |
OLD | NEW |