Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: components/payments/content/payment_request_spec.h

Issue 2789093002: [Payments] Desktop: implement shipping address/option change (Closed)
Patch Set: compile fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_SPEC_H_ 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_
6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 // certain occasions by the merchant (see API). 25 // certain occasions by the merchant (see API).
26 class PaymentRequestSpec : public PaymentOptionsProvider { 26 class PaymentRequestSpec : public PaymentOptionsProvider {
27 public: 27 public:
28 // Any class call add itself as Observer via AddObserver() and receive 28 // Any class call add itself as Observer via AddObserver() and receive
29 // notification about spec events. 29 // notification about spec events.
30 class Observer { 30 class Observer {
31 public: 31 public:
32 // Called when the provided spec (details, options, method_data) is invalid. 32 // Called when the provided spec (details, options, method_data) is invalid.
33 virtual void OnInvalidSpecProvided() = 0; 33 virtual void OnInvalidSpecProvided() = 0;
34 34
35 // Called when the provided spec has changed.
36 virtual void OnSpecUpdated() = 0;
37
35 protected: 38 protected:
36 virtual ~Observer() {} 39 virtual ~Observer() {}
37 }; 40 };
38 41
39 PaymentRequestSpec(mojom::PaymentOptionsPtr options, 42 PaymentRequestSpec(mojom::PaymentOptionsPtr options,
40 mojom::PaymentDetailsPtr details, 43 mojom::PaymentDetailsPtr details,
41 std::vector<mojom::PaymentMethodDataPtr> method_data, 44 std::vector<mojom::PaymentMethodDataPtr> method_data,
42 PaymentRequestSpec::Observer* observer, 45 PaymentRequestSpec::Observer* observer,
43 const std::string& app_locale); 46 const std::string& app_locale);
44 ~PaymentRequestSpec() override; 47 ~PaymentRequestSpec() override;
45 48
49 // Called when the merchant has new PaymentDetails. Will recompute every spec
50 // state that depends on |details|.
51 void UpdateWith(mojom::PaymentDetailsPtr details);
52
46 void AddObserver(Observer* observer); 53 void AddObserver(Observer* observer);
47 void RemoveObserver(Observer* observer); 54 void RemoveObserver(Observer* observer);
48 55
49 // PaymentOptionsProvider: 56 // PaymentOptionsProvider:
50 bool request_shipping() const override; 57 bool request_shipping() const override;
51 bool request_payer_name() const override; 58 bool request_payer_name() const override;
52 bool request_payer_phone() const override; 59 bool request_payer_phone() const override;
53 bool request_payer_email() const override; 60 bool request_payer_email() const override;
54 PaymentShippingType shipping_type() const override; 61 PaymentShippingType shipping_type() const override;
55 62
(...skipping 11 matching lines...) Expand all
67 // Uses CurrencyFormatter to format |amount| with the currency symbol for this 74 // Uses CurrencyFormatter to format |amount| with the currency symbol for this
68 // request's currency. Will use currency of the "total" display item, because 75 // request's currency. Will use currency of the "total" display item, because
69 // all items are supposed to have the same currency in a given request. 76 // all items are supposed to have the same currency in a given request.
70 base::string16 GetFormattedCurrencyAmount(const std::string& amount); 77 base::string16 GetFormattedCurrencyAmount(const std::string& amount);
71 78
72 // Uses CurrencyFormatter to get the formatted currency code for this 79 // Uses CurrencyFormatter to get the formatted currency code for this
73 // request's currency. Will use currency of the "total" display item, because 80 // request's currency. Will use currency of the "total" display item, because
74 // all items are supposed to have the same currency in a given request. 81 // all items are supposed to have the same currency in a given request.
75 std::string GetFormattedCurrencyCode(); 82 std::string GetFormattedCurrencyCode();
76 83
84 mojom::PaymentShippingOption* selected_shipping_option() const {
85 return selected_shipping_option_;
86 }
87
77 const mojom::PaymentDetails& details() const { return *details_.get(); } 88 const mojom::PaymentDetails& details() const { return *details_.get(); }
78 89
79 private: 90 private:
91 friend class PaymentRequestDialogView;
92 void add_observer_for_testing(Observer* observer_for_testing) {
93 observer_for_testing_ = observer_for_testing;
94 }
95
80 // Validates the |method_data| and fills |supported_card_networks_|. 96 // Validates the |method_data| and fills |supported_card_networks_|.
81 void PopulateValidatedMethodData( 97 void PopulateValidatedMethodData(
82 const std::vector<mojom::PaymentMethodDataPtr>& method_data); 98 const std::vector<mojom::PaymentMethodDataPtr>& method_data);
83 99
100 // Updates the selected_shipping_option based on the data passed to this
101 // payment request by the website. This will set selected_shipping_option_ to
102 // the last option marked selected in the options array.
103 void UpdateSelectedShippingOption();
104
84 // Will notify all observers that the spec is invalid. 105 // Will notify all observers that the spec is invalid.
85 void NotifyOnInvalidSpecProvided(); 106 void NotifyOnInvalidSpecProvided();
107 // Will notify all observers that the spec has changed.
108 void NotifyOnSpecUpdated();
86 109
87 // Returns the CurrencyFormatter instance for this PaymentRequest. 110 // Returns the CurrencyFormatter instance for this PaymentRequest.
88 // |locale_name| should be the result of the browser's GetApplicationLocale(). 111 // |locale_name| should be the result of the browser's GetApplicationLocale().
89 // Note: Having multiple currencies per PaymentRequest is not supported; hence 112 // Note: Having multiple currencies per PaymentRequest is not supported; hence
90 // the CurrencyFormatter is cached here. 113 // the CurrencyFormatter is cached here.
91 CurrencyFormatter* GetOrCreateCurrencyFormatter( 114 CurrencyFormatter* GetOrCreateCurrencyFormatter(
92 const std::string& currency_code, 115 const std::string& currency_code,
93 const std::string& currency_system, 116 const std::string& currency_system,
94 const std::string& locale_name); 117 const std::string& locale_name);
95 118
96 mojom::PaymentOptionsPtr options_; 119 mojom::PaymentOptionsPtr options_;
97 mojom::PaymentDetailsPtr details_; 120 mojom::PaymentDetailsPtr details_;
98 const std::string app_locale_; 121 const std::string app_locale_;
122 // The currently shipping option as specified by the merchant.
123 mojom::PaymentShippingOption* selected_shipping_option_;
124
99 std::unique_ptr<CurrencyFormatter> currency_formatter_; 125 std::unique_ptr<CurrencyFormatter> currency_formatter_;
100 126
101 // A list/set of supported basic card networks. The list is used to keep the 127 // A list/set of supported basic card networks. The list is used to keep the
102 // order in which they were specified by the merchant. The set is used for 128 // order in which they were specified by the merchant. The set is used for
103 // fast lookup of supported methods. 129 // fast lookup of supported methods.
104 std::vector<std::string> supported_card_networks_; 130 std::vector<std::string> supported_card_networks_;
105 std::set<std::string> supported_card_networks_set_; 131 std::set<std::string> supported_card_networks_set_;
106 132
107 // Only the set of basic-card specified networks. NOTE: callers should use 133 // Only the set of basic-card specified networks. NOTE: callers should use
108 // |supported_card_networks_set_| to check merchant support. 134 // |supported_card_networks_set_| to check merchant support.
109 std::set<std::string> basic_card_specified_networks_; 135 std::set<std::string> basic_card_specified_networks_;
110 136
137 // The |observer_for_testing_| will fire after all the |observers_| have been
138 // notified.
111 base::ObserverList<Observer> observers_; 139 base::ObserverList<Observer> observers_;
140 Observer* observer_for_testing_;
112 141
113 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec); 142 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec);
114 }; 143 };
115 144
116 } // namespace payments 145 } // namespace payments
117 146
118 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ 147 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_
OLDNEW
« no previous file with comments | « components/payments/content/payment_request.cc ('k') | components/payments/content/payment_request_spec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698