| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ |
| 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" |
| 13 #include "components/payments/content/payment_request.mojom.h" |
| 14 |
| 15 namespace payments { |
| 16 |
| 17 // The spec contains all the options that the merchant has specified about this |
| 18 // Payment Request. It's a (mostly) read-only view, which can be updated in |
| 19 // certain occasions by the merchant (see API). |
| 20 class PaymentRequestSpec { |
| 21 public: |
| 22 // Any class call add itself as Observer via AddObserver() and receive |
| 23 // notification about spec events. |
| 24 class Observer { |
| 25 public: |
| 26 // Called when the provided spec (details, options, method_data) is invalid. |
| 27 virtual void OnInvalidSpecProvided() = 0; |
| 28 |
| 29 protected: |
| 30 virtual ~Observer() {} |
| 31 }; |
| 32 |
| 33 PaymentRequestSpec(mojom::PaymentOptionsPtr options, |
| 34 mojom::PaymentDetailsPtr details, |
| 35 std::vector<mojom::PaymentMethodDataPtr> method_data, |
| 36 PaymentRequestSpec::Observer* observer); |
| 37 ~PaymentRequestSpec(); |
| 38 |
| 39 void AddObserver(Observer* observer); |
| 40 void RemoveObserver(Observer* observer); |
| 41 |
| 42 bool request_shipping() const { return options_->request_shipping; } |
| 43 bool request_payer_name() const { return options_->request_payer_name; } |
| 44 bool request_payer_phone() const { return options_->request_payer_phone; } |
| 45 bool request_payer_email() const { return options_->request_payer_email; } |
| 46 |
| 47 const std::vector<std::string>& supported_card_networks() { |
| 48 return supported_card_networks_; |
| 49 } |
| 50 |
| 51 const mojom::PaymentDetails& details() const { return *details_.get(); } |
| 52 const mojom::PaymentOptions& options() const { return *options_.get(); } |
| 53 |
| 54 private: |
| 55 // Validates the |method_data| and fills |supported_card_networks_|. |
| 56 void PopulateValidatedMethodData( |
| 57 const std::vector<mojom::PaymentMethodDataPtr>& method_data); |
| 58 |
| 59 // Will notify all observers that the spec is invalid. |
| 60 void NotifyOnInvalidSpecProvided(); |
| 61 |
| 62 mojom::PaymentOptionsPtr options_; |
| 63 mojom::PaymentDetailsPtr details_; |
| 64 |
| 65 // A list of supported basic card networks, in order that they were specified |
| 66 // by the merchant. |
| 67 std::vector<std::string> supported_card_networks_; |
| 68 |
| 69 base::ObserverList<Observer> observers_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec); |
| 72 }; |
| 73 |
| 74 } // namespace payments |
| 75 |
| 76 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_ |
| OLD | NEW |