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_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> |
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.mojom.h" | 14 #include "components/payments/content/payment_request.mojom.h" |
15 #include "components/payments/core/currency_formatter.h" | 15 #include "components/payments/core/currency_formatter.h" |
16 | 16 |
17 namespace payments { | 17 namespace payments { |
18 | 18 |
| 19 // Identifier for the basic card payment method in the PaymentMethodData. |
| 20 extern const char kBasicCardMethodName[]; |
| 21 |
19 // The spec contains all the options that the merchant has specified about this | 22 // The spec contains all the options that the merchant has specified about this |
20 // Payment Request. It's a (mostly) read-only view, which can be updated in | 23 // Payment Request. It's a (mostly) read-only view, which can be updated in |
21 // certain occasions by the merchant (see API). | 24 // certain occasions by the merchant (see API). |
22 class PaymentRequestSpec { | 25 class PaymentRequestSpec { |
23 public: | 26 public: |
24 // Any class call add itself as Observer via AddObserver() and receive | 27 // Any class call add itself as Observer via AddObserver() and receive |
25 // notification about spec events. | 28 // notification about spec events. |
26 class Observer { | 29 class Observer { |
27 public: | 30 public: |
28 // Called when the provided spec (details, options, method_data) is invalid. | 31 // Called when the provided spec (details, options, method_data) is invalid. |
(...skipping 17 matching lines...) Expand all Loading... |
46 bool request_payer_name() const { return options_->request_payer_name; } | 49 bool request_payer_name() const { return options_->request_payer_name; } |
47 bool request_payer_phone() const { return options_->request_payer_phone; } | 50 bool request_payer_phone() const { return options_->request_payer_phone; } |
48 bool request_payer_email() const { return options_->request_payer_email; } | 51 bool request_payer_email() const { return options_->request_payer_email; } |
49 | 52 |
50 const std::vector<std::string>& supported_card_networks() const { | 53 const std::vector<std::string>& supported_card_networks() const { |
51 return supported_card_networks_; | 54 return supported_card_networks_; |
52 } | 55 } |
53 const std::set<std::string>& supported_card_networks_set() const { | 56 const std::set<std::string>& supported_card_networks_set() const { |
54 return supported_card_networks_set_; | 57 return supported_card_networks_set_; |
55 } | 58 } |
| 59 // Returns whether the |method_name| was specified as supported through the |
| 60 // "basic-card" payment method. If false, it means either the |method_name| is |
| 61 // not supported at all, or specified directly in supportedMethods. |
| 62 bool IsMethodSupportedThroughBasicCard(const std::string& method_name); |
56 | 63 |
57 // Uses CurrencyFormatter to format |amount| with the currency symbol for this | 64 // Uses CurrencyFormatter to format |amount| with the currency symbol for this |
58 // request's currency. Will use currency of the "total" display item, because | 65 // request's currency. Will use currency of the "total" display item, because |
59 // all items are supposed to have the same currency in a given request. | 66 // all items are supposed to have the same currency in a given request. |
60 base::string16 GetFormattedCurrencyAmount(const std::string& amount); | 67 base::string16 GetFormattedCurrencyAmount(const std::string& amount); |
61 | 68 |
62 // Uses CurrencyFormatter to get the formatted currency code for this | 69 // Uses CurrencyFormatter to get the formatted currency code for this |
63 // request's currency. Will use currency of the "total" display item, because | 70 // request's currency. Will use currency of the "total" display item, because |
64 // all items are supposed to have the same currency in a given request. | 71 // all items are supposed to have the same currency in a given request. |
65 std::string GetFormattedCurrencyCode(); | 72 std::string GetFormattedCurrencyCode(); |
(...skipping 22 matching lines...) Expand all Loading... |
88 mojom::PaymentDetailsPtr details_; | 95 mojom::PaymentDetailsPtr details_; |
89 const std::string app_locale_; | 96 const std::string app_locale_; |
90 std::unique_ptr<CurrencyFormatter> currency_formatter_; | 97 std::unique_ptr<CurrencyFormatter> currency_formatter_; |
91 | 98 |
92 // A list/set of supported basic card networks. The list is used to keep the | 99 // A list/set of supported basic card networks. The list is used to keep the |
93 // order in which they were specified by the merchant. The set is used for | 100 // order in which they were specified by the merchant. The set is used for |
94 // fast lookup of supported methods. | 101 // fast lookup of supported methods. |
95 std::vector<std::string> supported_card_networks_; | 102 std::vector<std::string> supported_card_networks_; |
96 std::set<std::string> supported_card_networks_set_; | 103 std::set<std::string> supported_card_networks_set_; |
97 | 104 |
| 105 // Only the set of basic-card specified networks. NOTE: callers should use |
| 106 // |supported_card_networks_set_| to check merchant support. |
| 107 std::set<std::string> basic_card_specified_networks_; |
| 108 |
98 base::ObserverList<Observer> observers_; | 109 base::ObserverList<Observer> observers_; |
99 | 110 |
100 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec); | 111 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec); |
101 }; | 112 }; |
102 | 113 |
103 } // namespace payments | 114 } // namespace payments |
104 | 115 |
105 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ | 116 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ |
OLD | NEW |