blob: 6c55cca9ae4910cb4377dfa08fdf5251239c8fc6 [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
mathpf709499d2017-01-09 20:48:365#ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_
6#define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_
7
8#include <memory>
tmartino68c0a272017-01-19 17:44:089#include <string>
10#include <vector>
krb7f6421b2016-11-18 17:46:2111
mathp6758be032017-01-13 04:49:5012#include "components/payments/currency_formatter.h"
krb7f6421b2016-11-18 17:46:2113#include "components/payments/payment_request.mojom.h"
14#include "mojo/public/cpp/bindings/binding.h"
15
anthonyvd045303a2017-01-17 22:19:1916namespace autofill {
tmartino68c0a272017-01-19 17:44:0817class AutofillProfile;
anthonyvd045303a2017-01-17 22:19:1918class CreditCard;
19}
20
krb7f6421b2016-11-18 17:46:2121namespace content {
22class WebContents;
23}
24
25namespace payments {
26
mathpf709499d2017-01-09 20:48:3627class PaymentRequestDelegate;
28class PaymentRequestWebContentsManager;
29
30class PaymentRequest : payments::mojom::PaymentRequest {
krb7f6421b2016-11-18 17:46:2131 public:
mathpf709499d2017-01-09 20:48:3632 PaymentRequest(
krb7f6421b2016-11-18 17:46:2133 content::WebContents* web_contents,
mathpf709499d2017-01-09 20:48:3634 std::unique_ptr<PaymentRequestDelegate> delegate,
35 PaymentRequestWebContentsManager* manager,
krb7f6421b2016-11-18 17:46:2136 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request);
mathpf709499d2017-01-09 20:48:3637 ~PaymentRequest() override;
krb7f6421b2016-11-18 17:46:2138
39 // payments::mojom::PaymentRequest "stub"
40 void Init(payments::mojom::PaymentRequestClientPtr client,
41 std::vector<payments::mojom::PaymentMethodDataPtr> methodData,
42 payments::mojom::PaymentDetailsPtr details,
43 payments::mojom::PaymentOptionsPtr options) override;
sanjoy.pala1f17e82016-12-15 03:39:1244 void Show() override;
krb7f6421b2016-11-18 17:46:2145 void UpdateWith(payments::mojom::PaymentDetailsPtr details) override {}
46 void Abort() override {}
47 void Complete(payments::mojom::PaymentComplete result) override {}
rob.buise3da0af2016-12-02 23:36:5748 void CanMakePayment() override {}
krb7f6421b2016-11-18 17:46:2149
anthonyvd3d7f9722016-12-07 18:43:5450 void Cancel();
krb7f6421b2016-11-18 17:46:2151 void OnError();
mathp6758be032017-01-13 04:49:5052
53 // Returns the CurrencyFormatter instance for this PaymentRequest.
54 // |locale_name| should be the result of the browser's GetApplicationLocale().
55 // Note: Having multiple currencies per PaymentRequest is not supported; hence
56 // the CurrencyFormatter is cached here.
57 CurrencyFormatter* GetOrCreateCurrencyFormatter(
58 const std::string& currency_code,
59 const base::Optional<std::string> currency_system,
60 const std::string& locale_name);
61
tmartino68c0a272017-01-19 17:44:0862 // Returns the Autofill Profile, representing the shipping address and contact
63 // information, currently selected for this PaymentRequest flow. If
64 // unpopulated, populates with and returns the 0th profile on record for this
65 // user, if it exists; or nullptr otherwise. Profile is owned by the request
66 // object, not the caller.
67 autofill::AutofillProfile* GetCurrentlySelectedProfile();
68
anthonyvd045303a2017-01-17 22:19:1969 // Returns the currently selected credit card for this PaymentRequest flow.
70 // It's not guaranteed to be complete. Returns nullptr if there is no selected
71 // card.
72 autofill::CreditCard* GetCurrentlySelectedCreditCard();
krb7f6421b2016-11-18 17:46:2173
anthonyvd045303a2017-01-17 22:19:1974 payments::mojom::PaymentDetails* details() { return details_.get(); }
anthonyvd3d7f9722016-12-07 18:43:5475 content::WebContents* web_contents() { return web_contents_; }
76
krb7f6421b2016-11-18 17:46:2177 private:
krb7f6421b2016-11-18 17:46:2178 content::WebContents* web_contents_;
mathpf709499d2017-01-09 20:48:3679 std::unique_ptr<PaymentRequestDelegate> delegate_;
80 // |manager_| owns this PaymentRequest.
81 PaymentRequestWebContentsManager* manager_;
krb7f6421b2016-11-18 17:46:2182 mojo::Binding<payments::mojom::PaymentRequest> binding_;
anthonyvd3d7f9722016-12-07 18:43:5483 payments::mojom::PaymentRequestClientPtr client_;
anthonyvddd172712017-01-06 15:21:2484 payments::mojom::PaymentDetailsPtr details_;
mathp6758be032017-01-13 04:49:5085 std::unique_ptr<CurrencyFormatter> currency_formatter_;
tmartino68c0a272017-01-19 17:44:0886 std::unique_ptr<autofill::AutofillProfile> profile_;
anthonyvd3d7f9722016-12-07 18:43:5487
mathpf709499d2017-01-09 20:48:3688 DISALLOW_COPY_AND_ASSIGN(PaymentRequest);
krb7f6421b2016-11-18 17:46:2189};
90
91} // namespace payments
92
mathpf709499d2017-01-09 20:48:3693#endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_