krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 1 | // 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 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 5 | #ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ |
| 6 | #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ |
| 7 | |
| 8 | #include <memory> |
tmartino | 68c0a27 | 2017-01-19 17:44:08 | [diff] [blame^] | 9 | #include <string> |
| 10 | #include <vector> |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 11 | |
mathp | 6758be03 | 2017-01-13 04:49:50 | [diff] [blame] | 12 | #include "components/payments/currency_formatter.h" |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 13 | #include "components/payments/payment_request.mojom.h" |
| 14 | #include "mojo/public/cpp/bindings/binding.h" |
| 15 | |
anthonyvd | 045303a | 2017-01-17 22:19:19 | [diff] [blame] | 16 | namespace autofill { |
tmartino | 68c0a27 | 2017-01-19 17:44:08 | [diff] [blame^] | 17 | class AutofillProfile; |
anthonyvd | 045303a | 2017-01-17 22:19:19 | [diff] [blame] | 18 | class CreditCard; |
| 19 | } |
| 20 | |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 21 | namespace content { |
| 22 | class WebContents; |
| 23 | } |
| 24 | |
| 25 | namespace payments { |
| 26 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 27 | class PaymentRequestDelegate; |
| 28 | class PaymentRequestWebContentsManager; |
| 29 | |
| 30 | class PaymentRequest : payments::mojom::PaymentRequest { |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 31 | public: |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 32 | PaymentRequest( |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 33 | content::WebContents* web_contents, |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 34 | std::unique_ptr<PaymentRequestDelegate> delegate, |
| 35 | PaymentRequestWebContentsManager* manager, |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 36 | mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 37 | ~PaymentRequest() override; |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 38 | |
| 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.pal | a1f17e8 | 2016-12-15 03:39:12 | [diff] [blame] | 44 | void Show() override; |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 45 | void UpdateWith(payments::mojom::PaymentDetailsPtr details) override {} |
| 46 | void Abort() override {} |
| 47 | void Complete(payments::mojom::PaymentComplete result) override {} |
rob.buis | e3da0af | 2016-12-02 23:36:57 | [diff] [blame] | 48 | void CanMakePayment() override {} |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 49 | |
anthonyvd | 3d7f972 | 2016-12-07 18:43:54 | [diff] [blame] | 50 | void Cancel(); |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 51 | void OnError(); |
mathp | 6758be03 | 2017-01-13 04:49:50 | [diff] [blame] | 52 | |
| 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 | |
tmartino | 68c0a27 | 2017-01-19 17:44:08 | [diff] [blame^] | 62 | // 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 | |
anthonyvd | 045303a | 2017-01-17 22:19:19 | [diff] [blame] | 69 | // 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(); |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 73 | |
anthonyvd | 045303a | 2017-01-17 22:19:19 | [diff] [blame] | 74 | payments::mojom::PaymentDetails* details() { return details_.get(); } |
anthonyvd | 3d7f972 | 2016-12-07 18:43:54 | [diff] [blame] | 75 | content::WebContents* web_contents() { return web_contents_; } |
| 76 | |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 77 | private: |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 78 | content::WebContents* web_contents_; |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 79 | std::unique_ptr<PaymentRequestDelegate> delegate_; |
| 80 | // |manager_| owns this PaymentRequest. |
| 81 | PaymentRequestWebContentsManager* manager_; |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 82 | mojo::Binding<payments::mojom::PaymentRequest> binding_; |
anthonyvd | 3d7f972 | 2016-12-07 18:43:54 | [diff] [blame] | 83 | payments::mojom::PaymentRequestClientPtr client_; |
anthonyvd | dd17271 | 2017-01-06 15:21:24 | [diff] [blame] | 84 | payments::mojom::PaymentDetailsPtr details_; |
mathp | 6758be03 | 2017-01-13 04:49:50 | [diff] [blame] | 85 | std::unique_ptr<CurrencyFormatter> currency_formatter_; |
tmartino | 68c0a27 | 2017-01-19 17:44:08 | [diff] [blame^] | 86 | std::unique_ptr<autofill::AutofillProfile> profile_; |
anthonyvd | 3d7f972 | 2016-12-07 18:43:54 | [diff] [blame] | 87 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(PaymentRequest); |
krb | 7f6421b | 2016-11-18 17:46:21 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace payments |
| 92 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 93 | #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_ |