blob: 9d0ff09c0141bc370f93e4257113535d841ee5c1 [file] [log] [blame]
krb7f6421b2016-11-18 17:46:211// Copyright 2016 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
rouslan908248c2017-02-27 21:30:245#ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_
6#define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_
mathpf709499d2017-01-09 20:48:367
8#include <memory>
tmartino68c0a272017-01-19 17:44:089#include <vector>
krb7f6421b2016-11-18 17:46:2110
rouslan908248c2017-02-27 21:30:2411#include "base/macros.h"
mathpf1a7a3752017-03-15 11:23:3712#include "components/payments/content/payment_request_spec.h"
13#include "components/payments/content/payment_request_state.h"
anthonyvdd23ed702017-04-05 15:29:0014#include "components/payments/core/payment_request_delegate.h"
tobiasjsc66efdd22017-04-17 13:38:5915#include "components/payments/mojom/payment_request.mojom.h"
krb7f6421b2016-11-18 17:46:2116#include "mojo/public/cpp/bindings/binding.h"
rouslan8fdbfb242017-03-15 01:12:4917#include "mojo/public/cpp/bindings/interface_request.h"
krb7f6421b2016-11-18 17:46:2118
krb7f6421b2016-11-18 17:46:2119namespace content {
20class WebContents;
21}
22
23namespace payments {
24
mathpf709499d2017-01-09 20:48:3625class PaymentRequestWebContentsManager;
26
mathpf1a7a3752017-03-15 11:23:3727// This class manages the interaction between the renderer (through the
28// PaymentRequestClient and Mojo stub implementation) and the UI (through the
29// PaymentRequestDelegate). The API user (merchant) specification (supported
30// payment methods, required information, order details) is stored in
31// PaymentRequestSpec, and the current user selection state (and related data)
32// is stored in PaymentRequestSpec.
mathp4b85b582017-03-08 21:07:1633class PaymentRequest : public mojom::PaymentRequest,
mathpf1a7a3752017-03-15 11:23:3734 public PaymentRequestSpec::Observer,
35 public PaymentRequestState::Delegate {
krb7f6421b2016-11-18 17:46:2136 public:
mathp300fa542017-03-27 19:29:3737 class ObserverForTest {
38 public:
39 virtual void OnCanMakePaymentCalled() = 0;
rouslan6e3cf7c62017-04-17 21:23:2840 virtual void OnNotSupportedError() = 0;
mathp300fa542017-03-27 19:29:3741
42 protected:
43 virtual ~ObserverForTest() {}
44 };
45
rouslan8fdbfb242017-03-15 01:12:4946 PaymentRequest(content::WebContents* web_contents,
47 std::unique_ptr<PaymentRequestDelegate> delegate,
48 PaymentRequestWebContentsManager* manager,
mathp300fa542017-03-27 19:29:3749 mojo::InterfaceRequest<mojom::PaymentRequest> request,
50 ObserverForTest* observer_for_testing);
mathpf709499d2017-01-09 20:48:3651 ~PaymentRequest() override;
krb7f6421b2016-11-18 17:46:2152
rouslan8fdbfb242017-03-15 01:12:4953 // mojom::PaymentRequest
54 void Init(mojom::PaymentRequestClientPtr client,
55 std::vector<mojom::PaymentMethodDataPtr> method_data,
56 mojom::PaymentDetailsPtr details,
57 mojom::PaymentOptionsPtr options) override;
sanjoy.pala1f17e82016-12-15 03:39:1258 void Show() override;
mathp151bd31e2017-04-03 21:07:2459 void UpdateWith(mojom::PaymentDetailsPtr details) override;
mathpf4bc50e2017-01-24 05:17:5060 void Abort() override;
rouslan8fdbfb242017-03-15 01:12:4961 void Complete(mojom::PaymentComplete result) override;
mathp4b85b582017-03-08 21:07:1662 void CanMakePayment() override;
63
mathpf1a7a3752017-03-15 11:23:3764 // PaymentRequestSpec::Observer:
mathp151bd31e2017-04-03 21:07:2465 void OnSpecUpdated() override {}
mathpf1a7a3752017-03-15 11:23:3766
67 // PaymentRequestState::Delegate:
mathpf1a7a3752017-03-15 11:23:3768 void OnPaymentResponseAvailable(mojom::PaymentResponsePtr response) override;
mathp151bd31e2017-04-03 21:07:2469 void OnShippingOptionIdSelected(std::string shipping_option_id) override;
70 void OnShippingAddressSelected(mojom::PaymentAddressPtr address) override;
krb7f6421b2016-11-18 17:46:2171
mathpf4bc50e2017-01-24 05:17:5072 // Called when the user explicitely cancelled the flow. Will send a message
73 // to the renderer which will indirectly destroy this object (through
74 // OnConnectionTerminated).
75 void UserCancelled();
76
77 // As a result of a browser-side error or renderer-initiated mojo channel
78 // closure (e.g. there was an error on the renderer side, or payment was
79 // successful), this method is called. It is responsible for cleaning up,
80 // such as possibly closing the dialog.
81 void OnConnectionTerminated();
mathp6758be032017-01-13 04:49:5082
mathpd4be8de82017-03-01 00:51:4883 // Called when the user clicks on the "Pay" button.
84 void Pay();
85
anthonyvd3d7f9722016-12-07 18:43:5486 content::WebContents* web_contents() { return web_contents_; }
87
mathpf1a7a3752017-03-15 11:23:3788 PaymentRequestSpec* spec() { return spec_.get(); }
89 PaymentRequestState* state() { return state_.get(); }
mathpd4be8de82017-03-01 00:51:4890
krb7f6421b2016-11-18 17:46:2191 private:
krb7f6421b2016-11-18 17:46:2192 content::WebContents* web_contents_;
mathpf709499d2017-01-09 20:48:3693 std::unique_ptr<PaymentRequestDelegate> delegate_;
94 // |manager_| owns this PaymentRequest.
95 PaymentRequestWebContentsManager* manager_;
rouslan8fdbfb242017-03-15 01:12:4996 mojo::Binding<mojom::PaymentRequest> binding_;
97 mojom::PaymentRequestClientPtr client_;
mathpd4be8de82017-03-01 00:51:4898
mathpf1a7a3752017-03-15 11:23:3799 std::unique_ptr<PaymentRequestSpec> spec_;
100 std::unique_ptr<PaymentRequestState> state_;
anthonyvd3d7f9722016-12-07 18:43:54101
mathp300fa542017-03-27 19:29:37102 // May be null, must outlive this object.
103 ObserverForTest* observer_for_testing_;
104
mathpf709499d2017-01-09 20:48:36105 DISALLOW_COPY_AND_ASSIGN(PaymentRequest);
krb7f6421b2016-11-18 17:46:21106};
107
108} // namespace payments
109
rouslan908248c2017-02-27 21:30:24110#endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_