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 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "components/payments/content/payment_request_spec.h" |
14 #include "components/payments/content/payment_response_helper.h" | 15 #include "components/payments/content/payment_response_helper.h" |
| 16 #include "components/payments/core/address_normalizer.h" |
15 #include "components/payments/mojom/payment_request.mojom.h" | 17 #include "components/payments/mojom/payment_request.mojom.h" |
16 | 18 |
17 namespace autofill { | 19 namespace autofill { |
18 class AutofillProfile; | 20 class AutofillProfile; |
19 class CreditCard; | 21 class CreditCard; |
20 class PersonalDataManager; | 22 class PersonalDataManager; |
21 class RegionDataLoader; | 23 class RegionDataLoader; |
22 } // namespace autofill | 24 } // namespace autofill |
23 | 25 |
24 namespace payments { | 26 namespace payments { |
25 | 27 |
26 class PaymentInstrument; | 28 class PaymentInstrument; |
27 class PaymentRequestDelegate; | 29 class PaymentRequestDelegate; |
28 class PaymentRequestSpec; | |
29 | 30 |
30 // Keeps track of the information currently selected by the user and whether the | 31 // Keeps track of the information currently selected by the user and whether the |
31 // user is ready to pay. Uses information from the PaymentRequestSpec, which is | 32 // user is ready to pay. Uses information from the PaymentRequestSpec, which is |
32 // what the merchant has specified, as input into the "is ready to pay" | 33 // what the merchant has specified, as input into the "is ready to pay" |
33 // computation. | 34 // computation. |
34 class PaymentRequestState : public PaymentResponseHelper::Delegate { | 35 class PaymentRequestState : public PaymentResponseHelper::Delegate, |
| 36 public AddressNormalizer::Delegate, |
| 37 public PaymentRequestSpec::Observer { |
35 public: | 38 public: |
36 // Any class call add itself as Observer via AddObserver() and receive | 39 // Any class call add itself as Observer via AddObserver() and receive |
37 // notification about the state changing. | 40 // notification about the state changing. |
38 class Observer { | 41 class Observer { |
39 public: | 42 public: |
40 // Called when the information (payment method, address/contact info, | 43 // Called when the information (payment method, address/contact info, |
41 // shipping option) changes. | 44 // shipping option) changes. |
42 virtual void OnSelectedInformationChanged() = 0; | 45 virtual void OnSelectedInformationChanged() = 0; |
43 | 46 |
44 protected: | 47 protected: |
(...skipping 21 matching lines...) Expand all Loading... |
66 Delegate* delegate, | 69 Delegate* delegate, |
67 const std::string& app_locale, | 70 const std::string& app_locale, |
68 autofill::PersonalDataManager* personal_data_manager, | 71 autofill::PersonalDataManager* personal_data_manager, |
69 PaymentRequestDelegate* payment_request_delegate); | 72 PaymentRequestDelegate* payment_request_delegate); |
70 ~PaymentRequestState() override; | 73 ~PaymentRequestState() override; |
71 | 74 |
72 // PaymentResponseHelper::Delegate | 75 // PaymentResponseHelper::Delegate |
73 void OnPaymentResponseReady( | 76 void OnPaymentResponseReady( |
74 mojom::PaymentResponsePtr payment_response) override; | 77 mojom::PaymentResponsePtr payment_response) override; |
75 | 78 |
| 79 // AddressNormalizer::Delegate |
| 80 void OnAddressNormalized( |
| 81 const autofill::AutofillProfile& normalized_profile) override; |
| 82 void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override; |
| 83 |
| 84 // PaymentRequestSpec::Observer |
| 85 void OnStartUpdating(PaymentRequestSpec::UpdateReason reason) override {} |
| 86 void OnSpecUpdated() override; |
| 87 |
76 // Returns whether the user has at least one instrument that satisfies the | 88 // Returns whether the user has at least one instrument that satisfies the |
77 // specified supported payment methods. | 89 // specified supported payment methods. |
78 bool CanMakePayment() const; | 90 bool CanMakePayment() const; |
79 | 91 |
80 // Returns true if the payment methods that the merchant website have | 92 // Returns true if the payment methods that the merchant website have |
81 // requested are supported. For example, may return true for "basic-card", but | 93 // requested are supported. For example, may return true for "basic-card", but |
82 // false for "https://bobpay.com". | 94 // false for "https://bobpay.com". |
83 bool AreRequestedMethodsSupported() const; | 95 bool AreRequestedMethodsSupported() const; |
84 | 96 |
85 void AddObserver(Observer* observer); | 97 void AddObserver(Observer* observer); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 177 |
166 // Returns whether the selected data satisfies the PaymentDetails requirements | 178 // Returns whether the selected data satisfies the PaymentDetails requirements |
167 // (payment methods). | 179 // (payment methods). |
168 bool ArePaymentDetailsSatisfied(); | 180 bool ArePaymentDetailsSatisfied(); |
169 // Returns whether the selected data satisfies the PaymentOptions requirements | 181 // Returns whether the selected data satisfies the PaymentOptions requirements |
170 // (contact info, shipping address). | 182 // (contact info, shipping address). |
171 bool ArePaymentOptionsSatisfied(); | 183 bool ArePaymentOptionsSatisfied(); |
172 | 184 |
173 bool is_ready_to_pay_; | 185 bool is_ready_to_pay_; |
174 | 186 |
| 187 // Whether the data is currently being validated by the merchant. |
| 188 bool is_waiting_for_merchant_validation_; |
| 189 |
175 const std::string app_locale_; | 190 const std::string app_locale_; |
176 | 191 |
177 // Not owned. Never null. Both outlive this object. | 192 // Not owned. Never null. Both outlive this object. |
178 PaymentRequestSpec* spec_; | 193 PaymentRequestSpec* spec_; |
179 Delegate* delegate_; | 194 Delegate* delegate_; |
180 autofill::PersonalDataManager* personal_data_manager_; | 195 autofill::PersonalDataManager* personal_data_manager_; |
181 | 196 |
182 autofill::AutofillProfile* selected_shipping_profile_; | 197 autofill::AutofillProfile* selected_shipping_profile_; |
183 autofill::AutofillProfile* selected_contact_profile_; | 198 autofill::AutofillProfile* selected_contact_profile_; |
184 PaymentInstrument* selected_instrument_; | 199 PaymentInstrument* selected_instrument_; |
(...skipping 12 matching lines...) Expand all Loading... |
197 std::unique_ptr<PaymentResponseHelper> response_helper_; | 212 std::unique_ptr<PaymentResponseHelper> response_helper_; |
198 | 213 |
199 base::ObserverList<Observer> observers_; | 214 base::ObserverList<Observer> observers_; |
200 | 215 |
201 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); | 216 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); |
202 }; | 217 }; |
203 | 218 |
204 } // namespace payments | 219 } // namespace payments |
205 | 220 |
206 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 221 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
OLD | NEW |