1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_dom_PaymentRequestService_h
8 #define mozilla_dom_PaymentRequestService_h
9 
10 #include "nsInterfaceHashtable.h"
11 #include "nsIPaymentRequestService.h"
12 #include "nsCOMPtr.h"
13 #include "nsTArray.h"
14 #include "PaymentRequestData.h"
15 
16 namespace mozilla {
17 namespace dom {
18 
19 // The implmentation of nsIPaymentRequestService
20 
21 class PaymentRequestService final : public nsIPaymentRequestService {
22  public:
23   NS_DECL_ISUPPORTS
24   NS_DECL_NSIPAYMENTREQUESTSERVICE
25 
26   PaymentRequestService() = default;
27 
28   static already_AddRefed<PaymentRequestService> GetSingleton();
29 
30   already_AddRefed<payments::PaymentRequest> GetPaymentRequestByIndex(
31       const uint32_t index);
32 
33   uint32_t NumPayments() const;
34 
35   nsresult RequestPayment(const nsAString& aRequestId,
36                           const IPCPaymentActionRequest& aAction,
37                           PaymentRequestParent* aCallback);
38 
39  private:
40   ~PaymentRequestService() = default;
41 
42   nsresult GetPaymentRequestById(const nsAString& aRequestId,
43                                  payments::PaymentRequest** aRequest);
44 
45   nsresult LaunchUIAction(const nsAString& aRequestId, uint32_t aActionType);
46 
47   bool CanMakePayment(const nsAString& aRequestId);
48 
49   nsresult ShowPayment(const nsAString& aRequestId, bool aIsUpdating);
50 
51   bool IsBasicCardPayment(const nsAString& aRequestId);
52 
53   FallibleTArray<RefPtr<payments::PaymentRequest>> mRequestQueue;
54 
55   nsCOMPtr<nsIPaymentUIService> mTestingUIService;
56 
57   RefPtr<payments::PaymentRequest> mShowingRequest;
58 };
59 
60 }  // end of namespace dom
61 }  // end of namespace mozilla
62 
63 #endif
64