blob: c831cb916e8f89f96dfae69fddd7527ca1e4966f [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"
sebsg20b49d7b2017-05-04 20:23:1714#include "components/payments/core/journey_logger.h"
anthonyvdd23ed702017-04-05 15:29:0015#include "components/payments/core/payment_request_delegate.h"
tobiasjsc66efdd22017-04-17 13:38:5916#include "components/payments/mojom/payment_request.mojom.h"
krb7f6421b2016-11-18 17:46:2117#include "mojo/public/cpp/bindings/binding.h"
rouslan8fdbfb242017-03-15 01:12:4918#include "mojo/public/cpp/bindings/interface_request.h"
krb7f6421b2016-11-18 17:46:2119
krb7f6421b2016-11-18 17:46:2120namespace content {
21class WebContents;
22}
23
24namespace payments {
25
mathpf709499d2017-01-09 20:48:3626class PaymentRequestWebContentsManager;
27
mathpf1a7a3752017-03-15 11:23:3728// This class manages the interaction between the renderer (through the
29// PaymentRequestClient and Mojo stub implementation) and the UI (through the
30// PaymentRequestDelegate). The API user (merchant) specification (supported
31// payment methods, required information, order details) is stored in
32// PaymentRequestSpec, and the current user selection state (and related data)
33// is stored in PaymentRequestSpec.
mathp4b85b582017-03-08 21:07:1634class PaymentRequest : public mojom::PaymentRequest,
mathpf1a7a3752017-03-15 11:23:3735 public PaymentRequestSpec::Observer,
36 public PaymentRequestState::Delegate {
krb7f6421b2016-11-18 17:46:2137 public:
mathp300fa542017-03-27 19:29:3738 class ObserverForTest {
39 public:
40 virtual void OnCanMakePaymentCalled() = 0;
rouslan6e3cf7c62017-04-17 21:23:2841 virtual void OnNotSupportedError() = 0;
mathp300fa542017-03-27 19:29:3742
43 protected:
44 virtual ~ObserverForTest() {}
45 };
46
rouslan8fdbfb242017-03-15 01:12:4947 PaymentRequest(content::WebContents* web_contents,
48 std::unique_ptr<PaymentRequestDelegate> delegate,
49 PaymentRequestWebContentsManager* manager,
mathp300fa542017-03-27 19:29:3750 mojo::InterfaceRequest<mojom::PaymentRequest> request,
51 ObserverForTest* observer_for_testing);
mathpf709499d2017-01-09 20:48:3652 ~PaymentRequest() override;
krb7f6421b2016-11-18 17:46:2153
rouslan8fdbfb242017-03-15 01:12:4954 // mojom::PaymentRequest
55 void Init(mojom::PaymentRequestClientPtr client,
56 std::vector<mojom::PaymentMethodDataPtr> method_data,
57 mojom::PaymentDetailsPtr details,
58 mojom::PaymentOptionsPtr options) override;
sanjoy.pala1f17e82016-12-15 03:39:1259 void Show() override;
mathp151bd31e2017-04-03 21:07:2460 void UpdateWith(mojom::PaymentDetailsPtr details) override;
mathpf4bc50e2017-01-24 05:17:5061 void Abort() override;
rouslan8fdbfb242017-03-15 01:12:4962 void Complete(mojom::PaymentComplete result) override;
mathp4b85b582017-03-08 21:07:1663 void CanMakePayment() override;
64
mathpf1a7a3752017-03-15 11:23:3765 // PaymentRequestSpec::Observer:
mathp151bd31e2017-04-03 21:07:2466 void OnSpecUpdated() override {}
mathpf1a7a3752017-03-15 11:23:3767
68 // PaymentRequestState::Delegate:
mathpf1a7a3752017-03-15 11:23:3769 void OnPaymentResponseAvailable(mojom::PaymentResponsePtr response) override;
mathp151bd31e2017-04-03 21:07:2470 void OnShippingOptionIdSelected(std::string shipping_option_id) override;
71 void OnShippingAddressSelected(mojom::PaymentAddressPtr address) override;
krb7f6421b2016-11-18 17:46:2172
mathpf4bc50e2017-01-24 05:17:5073 // Called when the user explicitely cancelled the flow. Will send a message
74 // to the renderer which will indirectly destroy this object (through
75 // OnConnectionTerminated).
76 void UserCancelled();
77
78 // As a result of a browser-side error or renderer-initiated mojo channel
79 // closure (e.g. there was an error on the renderer side, or payment was
80 // successful), this method is called. It is responsible for cleaning up,
81 // such as possibly closing the dialog.
82 void OnConnectionTerminated();
mathp6758be032017-01-13 04:49:5083
mathpd4be8de82017-03-01 00:51:4884 // Called when the user clicks on the "Pay" button.
85 void Pay();
86
anthonyvd3d7f9722016-12-07 18:43:5487 content::WebContents* web_contents() { return web_contents_; }
88
mathpf1a7a3752017-03-15 11:23:3789 PaymentRequestSpec* spec() { return spec_.get(); }
90 PaymentRequestState* state() { return state_.get(); }
mathpd4be8de82017-03-01 00:51:4891
krb7f6421b2016-11-18 17:46:2192 private:
krb7f6421b2016-11-18 17:46:2193 content::WebContents* web_contents_;
mathpf709499d2017-01-09 20:48:3694 std::unique_ptr<PaymentRequestDelegate> delegate_;
95 // |manager_| owns this PaymentRequest.
96 PaymentRequestWebContentsManager* manager_;
rouslan8fdbfb242017-03-15 01:12:4997 mojo::Binding<mojom::PaymentRequest> binding_;
98 mojom::PaymentRequestClientPtr client_;
mathpd4be8de82017-03-01 00:51:4899
mathpf1a7a3752017-03-15 11:23:37100 std::unique_ptr<PaymentRequestSpec> spec_;
101 std::unique_ptr<PaymentRequestState> state_;
anthonyvd3d7f9722016-12-07 18:43:54102
mathp300fa542017-03-27 19:29:37103 // May be null, must outlive this object.
104 ObserverForTest* observer_for_testing_;
105
sebsg20b49d7b2017-05-04 20:23:17106 JourneyLogger journey_logger_;
107
mathpf709499d2017-01-09 20:48:36108 DISALLOW_COPY_AND_ASSIGN(PaymentRequest);
krb7f6421b2016-11-18 17:46:21109};
110
111} // namespace payments
112
rouslan908248c2017-02-27 21:30:24113#endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_