| 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 #include "components/payments/core/payment_options_provider.h" |
| 16 | 17 |
| 17 namespace payments { | 18 namespace payments { |
| 18 | 19 |
| 19 // Identifier for the basic card payment method in the PaymentMethodData. | 20 // Identifier for the basic card payment method in the PaymentMethodData. |
| 20 extern const char kBasicCardMethodName[]; | 21 extern const char kBasicCardMethodName[]; |
| 21 | 22 |
| 22 // The spec contains all the options that the merchant has specified about this | 23 // The spec contains all the options that the merchant has specified about this |
| 23 // Payment Request. It's a (mostly) read-only view, which can be updated in | 24 // Payment Request. It's a (mostly) read-only view, which can be updated in |
| 24 // certain occasions by the merchant (see API). | 25 // certain occasions by the merchant (see API). |
| 25 class PaymentRequestSpec { | 26 class PaymentRequestSpec : public PaymentOptionsProvider { |
| 26 public: | 27 public: |
| 27 // Any class call add itself as Observer via AddObserver() and receive | 28 // Any class call add itself as Observer via AddObserver() and receive |
| 28 // notification about spec events. | 29 // notification about spec events. |
| 29 class Observer { | 30 class Observer { |
| 30 public: | 31 public: |
| 31 // Called when the provided spec (details, options, method_data) is invalid. | 32 // Called when the provided spec (details, options, method_data) is invalid. |
| 32 virtual void OnInvalidSpecProvided() = 0; | 33 virtual void OnInvalidSpecProvided() = 0; |
| 33 | 34 |
| 34 protected: | 35 protected: |
| 35 virtual ~Observer() {} | 36 virtual ~Observer() {} |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 PaymentRequestSpec(mojom::PaymentOptionsPtr options, | 39 PaymentRequestSpec(mojom::PaymentOptionsPtr options, |
| 39 mojom::PaymentDetailsPtr details, | 40 mojom::PaymentDetailsPtr details, |
| 40 std::vector<mojom::PaymentMethodDataPtr> method_data, | 41 std::vector<mojom::PaymentMethodDataPtr> method_data, |
| 41 PaymentRequestSpec::Observer* observer, | 42 PaymentRequestSpec::Observer* observer, |
| 42 const std::string& app_locale); | 43 const std::string& app_locale); |
| 43 ~PaymentRequestSpec(); | 44 ~PaymentRequestSpec() override; |
| 44 | 45 |
| 45 void AddObserver(Observer* observer); | 46 void AddObserver(Observer* observer); |
| 46 void RemoveObserver(Observer* observer); | 47 void RemoveObserver(Observer* observer); |
| 47 | 48 |
| 48 bool request_shipping() const { return options_->request_shipping; } | 49 // PaymentOptionsProvider: |
| 49 bool request_payer_name() const { return options_->request_payer_name; } | 50 bool request_shipping() const override; |
| 50 bool request_payer_phone() const { return options_->request_payer_phone; } | 51 bool request_payer_name() const override; |
| 51 bool request_payer_email() const { return options_->request_payer_email; } | 52 bool request_payer_phone() const override; |
| 53 bool request_payer_email() const override; |
| 54 PaymentShippingType shipping_type() const override; |
| 52 | 55 |
| 53 const std::vector<std::string>& supported_card_networks() const { | 56 const std::vector<std::string>& supported_card_networks() const { |
| 54 return supported_card_networks_; | 57 return supported_card_networks_; |
| 55 } | 58 } |
| 56 const std::set<std::string>& supported_card_networks_set() const { | 59 const std::set<std::string>& supported_card_networks_set() const { |
| 57 return supported_card_networks_set_; | 60 return supported_card_networks_set_; |
| 58 } | 61 } |
| 59 // Returns whether the |method_name| was specified as supported through the | 62 // 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 | 63 // "basic-card" payment method. If false, it means either the |method_name| is |
| 61 // not supported at all, or specified directly in supportedMethods. | 64 // not supported at all, or specified directly in supportedMethods. |
| 62 bool IsMethodSupportedThroughBasicCard(const std::string& method_name); | 65 bool IsMethodSupportedThroughBasicCard(const std::string& method_name); |
| 63 | 66 |
| 64 // Uses CurrencyFormatter to format |amount| with the currency symbol for this | 67 // Uses CurrencyFormatter to format |amount| with the currency symbol for this |
| 65 // request's currency. Will use currency of the "total" display item, because | 68 // request's currency. Will use currency of the "total" display item, because |
| 66 // all items are supposed to have the same currency in a given request. | 69 // all items are supposed to have the same currency in a given request. |
| 67 base::string16 GetFormattedCurrencyAmount(const std::string& amount); | 70 base::string16 GetFormattedCurrencyAmount(const std::string& amount); |
| 68 | 71 |
| 69 // Uses CurrencyFormatter to get the formatted currency code for this | 72 // Uses CurrencyFormatter to get the formatted currency code for this |
| 70 // request's currency. Will use currency of the "total" display item, because | 73 // request's currency. Will use currency of the "total" display item, because |
| 71 // all items are supposed to have the same currency in a given request. | 74 // all items are supposed to have the same currency in a given request. |
| 72 std::string GetFormattedCurrencyCode(); | 75 std::string GetFormattedCurrencyCode(); |
| 73 | 76 |
| 74 const mojom::PaymentDetails& details() const { return *details_.get(); } | 77 const mojom::PaymentDetails& details() const { return *details_.get(); } |
| 75 const mojom::PaymentOptions& options() const { return *options_.get(); } | |
| 76 | 78 |
| 77 private: | 79 private: |
| 78 // Validates the |method_data| and fills |supported_card_networks_|. | 80 // Validates the |method_data| and fills |supported_card_networks_|. |
| 79 void PopulateValidatedMethodData( | 81 void PopulateValidatedMethodData( |
| 80 const std::vector<mojom::PaymentMethodDataPtr>& method_data); | 82 const std::vector<mojom::PaymentMethodDataPtr>& method_data); |
| 81 | 83 |
| 82 // Will notify all observers that the spec is invalid. | 84 // Will notify all observers that the spec is invalid. |
| 83 void NotifyOnInvalidSpecProvided(); | 85 void NotifyOnInvalidSpecProvided(); |
| 84 | 86 |
| 85 // Returns the CurrencyFormatter instance for this PaymentRequest. | 87 // Returns the CurrencyFormatter instance for this PaymentRequest. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 107 std::set<std::string> basic_card_specified_networks_; | 109 std::set<std::string> basic_card_specified_networks_; |
| 108 | 110 |
| 109 base::ObserverList<Observer> observers_; | 111 base::ObserverList<Observer> observers_; |
| 110 | 112 |
| 111 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec); | 113 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec); |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 } // namespace payments | 116 } // namespace payments |
| 115 | 117 |
| 116 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ | 118 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ |
| OLD | NEW |