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_RESPONSE_HELPER_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ |
6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ | 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "components/autofill/core/browser/autofill_profile.h" | |
10 #include "components/payments/core/address_normalizer.h" | |
11 #include "components/payments/core/payment_instrument.h" | 9 #include "components/payments/core/payment_instrument.h" |
12 #include "components/payments/mojom/payment_request.mojom.h" | 10 #include "components/payments/mojom/payment_request.mojom.h" |
13 | 11 |
| 12 namespace autofill { |
| 13 class AutofillProfile; |
| 14 } // namespace autofill |
| 15 |
14 namespace payments { | 16 namespace payments { |
15 | 17 |
16 class PaymentRequestDelegate; | |
17 class PaymentRequestSpec; | 18 class PaymentRequestSpec; |
18 | 19 |
19 // TODO(sebsg): Asynchronously normalize the billing and shipping addresses | 20 // TODO(sebsg): Asynchronously normalize the billing and shipping addresses |
20 // before adding them to the PaymentResponse. | 21 // before adding them to the PaymentResponse. |
21 // A helper class to facilitate the creation of the PaymentResponse. | 22 // A helper class to facilitate the creation of the PaymentResponse. |
22 class PaymentResponseHelper : public PaymentInstrument::Delegate, | 23 class PaymentResponseHelper : public PaymentInstrument::Delegate { |
23 AddressNormalizer::Delegate { | |
24 public: | 24 public: |
25 class Delegate { | 25 class Delegate { |
26 public: | 26 public: |
27 virtual ~Delegate() {} | 27 virtual ~Delegate() {} |
28 | 28 |
29 virtual void OnPaymentResponseReady( | 29 virtual void OnPaymentResponseReady( |
30 mojom::PaymentResponsePtr payment_response) = 0; | 30 mojom::PaymentResponsePtr payment_response) = 0; |
31 }; | 31 }; |
32 | 32 |
33 // The spec, selected_instrument and delegate cannot be null. | 33 // The spec, selected_instrument and delegate cannot be null. |
34 PaymentResponseHelper(const std::string& app_locale, | 34 PaymentResponseHelper(const std::string& app_locale, |
35 PaymentRequestSpec* spec, | 35 PaymentRequestSpec* spec, |
36 PaymentInstrument* selected_instrument, | 36 PaymentInstrument* selected_instrument, |
37 PaymentRequestDelegate* payment_request_delegate, | |
38 autofill::AutofillProfile* selected_shipping_profile, | 37 autofill::AutofillProfile* selected_shipping_profile, |
39 autofill::AutofillProfile* selected_contact_profile, | 38 autofill::AutofillProfile* selected_contact_profile, |
40 Delegate* delegate); | 39 Delegate* delegate); |
41 ~PaymentResponseHelper() override; | 40 ~PaymentResponseHelper() override; |
42 | 41 |
43 // Returns a new mojo PaymentAddress based on the specified | 42 // Returns a new mojo PaymentAddress based on the specified |
44 // |profile| and |app_locale|. | 43 // |profile| and |app_locale|. |
45 static mojom::PaymentAddressPtr GetMojomPaymentAddressFromAutofillProfile( | 44 static mojom::PaymentAddressPtr GetMojomPaymentAddressFromAutofillProfile( |
46 const autofill::AutofillProfile* const profile, | 45 const autofill::AutofillProfile* const profile, |
47 const std::string& app_locale); | 46 const std::string& app_locale); |
48 | 47 |
49 // PaymentInstrument::Delegate | 48 // PaymentInstrument::Delegate |
50 void OnInstrumentDetailsReady( | 49 void OnInstrumentDetailsReady( |
51 const std::string& method_name, | 50 const std::string& method_name, |
52 const std::string& stringified_details) override; | 51 const std::string& stringified_details) override; |
53 void OnInstrumentDetailsError() override {} | 52 void OnInstrumentDetailsError() override {} |
54 | 53 |
55 // AddressNormalizer::Delegate | |
56 void OnAddressNormalized( | |
57 const autofill::AutofillProfile& normalized_profile) override; | |
58 void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override; | |
59 | |
60 private: | 54 private: |
61 // Generates the Payment Response and sends it to the delegate. | |
62 void GeneratePaymentResponse(); | |
63 | |
64 const std::string& app_locale_; | 55 const std::string& app_locale_; |
65 bool is_waiting_for_shipping_address_normalization_; | |
66 bool is_waiting_for_instrument_details_; | |
67 | 56 |
68 // Not owned, cannot be null. | 57 // Not owned, cannot be null. |
69 PaymentRequestSpec* spec_; | 58 PaymentRequestSpec* spec_; |
70 Delegate* delegate_; | 59 Delegate* delegate_; |
71 PaymentInstrument* selected_instrument_; | 60 PaymentInstrument* selected_instrument_; |
72 PaymentRequestDelegate* payment_request_delegate_; | |
73 | 61 |
74 // Not owned, can be null (dependent on the spec). | 62 // Not owned, can be null (dependent on the spec). |
| 63 autofill::AutofillProfile* selected_shipping_profile_; |
75 autofill::AutofillProfile* selected_contact_profile_; | 64 autofill::AutofillProfile* selected_contact_profile_; |
76 | 65 |
77 autofill::AutofillProfile shipping_address_; | |
78 | |
79 // Instrument Details. | |
80 std::string method_name_; | |
81 std::string stringified_details_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(PaymentResponseHelper); | 66 DISALLOW_COPY_AND_ASSIGN(PaymentResponseHelper); |
84 }; | 67 }; |
85 | 68 |
86 } // namespace payments | 69 } // namespace payments |
87 | 70 |
88 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ | 71 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_RESPONSE_HELPER_H_ |
OLD | NEW |