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/. */
7 #ifndef mozilla_dom_PaymentRequestData_h
8 #define mozilla_dom_PaymentRequestData_h
10 #include "nsIPaymentAddress.h"
11 #include "nsIPaymentRequest.h"
13 #include "mozilla/dom/PaymentRequestParent.h"
15 namespace mozilla::dom::payments
{
17 class PaymentMethodData final
: public nsIPaymentMethodData
{
20 NS_DECL_NSIPAYMENTMETHODDATA
22 static nsresult
Create(const IPCPaymentMethodData
& aIPCMethodData
,
23 nsIPaymentMethodData
** aMethodData
);
26 PaymentMethodData(const nsAString
& aSupportedMethods
, const nsAString
& aData
);
28 ~PaymentMethodData() = default;
30 nsString mSupportedMethods
;
34 class PaymentCurrencyAmount final
: public nsIPaymentCurrencyAmount
{
37 NS_DECL_NSIPAYMENTCURRENCYAMOUNT
39 static nsresult
Create(const IPCPaymentCurrencyAmount
& aIPCAmount
,
40 nsIPaymentCurrencyAmount
** aAmount
);
43 PaymentCurrencyAmount(const nsAString
& aCurrency
, const nsAString
& aValue
);
45 ~PaymentCurrencyAmount() = default;
51 class PaymentItem final
: public nsIPaymentItem
{
54 NS_DECL_NSIPAYMENTITEM
56 static nsresult
Create(const IPCPaymentItem
& aIPCItem
,
57 nsIPaymentItem
** aItem
);
60 PaymentItem(const nsAString
& aLabel
, nsIPaymentCurrencyAmount
* aAmount
,
63 ~PaymentItem() = default;
66 nsCOMPtr
<nsIPaymentCurrencyAmount
> mAmount
;
70 class PaymentDetailsModifier final
: public nsIPaymentDetailsModifier
{
73 NS_DECL_NSIPAYMENTDETAILSMODIFIER
75 static nsresult
Create(const IPCPaymentDetailsModifier
& aIPCModifier
,
76 nsIPaymentDetailsModifier
** aModifier
);
79 PaymentDetailsModifier(const nsAString
& aSupportedMethods
,
80 nsIPaymentItem
* aTotal
,
81 nsIArray
* aAdditionalDisplayItems
,
82 const nsAString
& aData
);
84 ~PaymentDetailsModifier() = default;
86 nsString mSupportedMethods
;
87 nsCOMPtr
<nsIPaymentItem
> mTotal
;
88 nsCOMPtr
<nsIArray
> mAdditionalDisplayItems
;
92 class PaymentShippingOption final
: public nsIPaymentShippingOption
{
95 NS_DECL_NSIPAYMENTSHIPPINGOPTION
97 static nsresult
Create(const IPCPaymentShippingOption
& aIPCOption
,
98 nsIPaymentShippingOption
** aOption
);
101 PaymentShippingOption(const nsAString
& aId
, const nsAString
& aLabel
,
102 nsIPaymentCurrencyAmount
* aAmount
,
103 const bool aSelected
= false);
105 ~PaymentShippingOption() = default;
109 nsCOMPtr
<nsIPaymentCurrencyAmount
> mAmount
;
113 class PaymentDetails final
: public nsIPaymentDetails
{
116 NS_DECL_NSIPAYMENTDETAILS
118 static nsresult
Create(const IPCPaymentDetails
& aIPCDetails
,
119 nsIPaymentDetails
** aDetails
);
120 nsresult
Update(nsIPaymentDetails
* aDetails
, const bool aRequestShipping
);
121 const nsString
& GetShippingAddressErrors() const;
122 const nsString
& GetPayerErrors() const;
123 const nsString
& GetPaymentMethodErrors() const;
124 nsresult
UpdateErrors(const nsAString
& aError
, const nsAString
& aPayerErrors
,
125 const nsAString
& aPaymentMethodErrors
,
126 const nsAString
& aShippingAddressErrors
);
129 PaymentDetails(const nsAString
& aId
, nsIPaymentItem
* aTotalItem
,
130 nsIArray
* aDisplayItems
, nsIArray
* aShippingOptions
,
131 nsIArray
* aModifiers
, const nsAString
& aError
,
132 const nsAString
& aShippingAddressError
,
133 const nsAString
& aPayerError
,
134 const nsAString
& aPaymentMethodError
);
136 ~PaymentDetails() = default;
139 nsCOMPtr
<nsIPaymentItem
> mTotalItem
;
140 nsCOMPtr
<nsIArray
> mDisplayItems
;
141 nsCOMPtr
<nsIArray
> mShippingOptions
;
142 nsCOMPtr
<nsIArray
> mModifiers
;
144 nsString mShippingAddressErrors
;
145 nsString mPayerErrors
;
146 nsString mPaymentMethodErrors
;
149 class PaymentOptions final
: public nsIPaymentOptions
{
152 NS_DECL_NSIPAYMENTOPTIONS
154 static nsresult
Create(const IPCPaymentOptions
& aIPCOptions
,
155 nsIPaymentOptions
** aOptions
);
158 PaymentOptions(const bool aRequestPayerName
, const bool aRequestPayerEmail
,
159 const bool aRequestPayerPhone
, const bool aRequestShipping
,
160 const bool aRequestBillingAddress
,
161 const nsAString
& aShippintType
);
162 ~PaymentOptions() = default;
164 bool mRequestPayerName
;
165 bool mRequestPayerEmail
;
166 bool mRequestPayerPhone
;
167 bool mRequestShipping
;
168 bool mRequestBillingAddress
;
169 nsString mShippingType
;
172 class PaymentRequest final
: public nsIPaymentRequest
{
175 NS_DECL_NSIPAYMENTREQUEST
177 PaymentRequest(const uint64_t aTopOuterWindowId
, const nsAString
& aRequestId
,
178 nsIPrincipal
* aPrincipal
, nsIArray
* aPaymentMethods
,
179 nsIPaymentDetails
* aPaymentDetails
,
180 nsIPaymentOptions
* aPaymentOptions
,
181 const nsAString
& aShippingOption
);
183 void SetIPC(PaymentRequestParent
* aIPC
) { mIPC
= aIPC
; }
185 PaymentRequestParent
* GetIPC() const { return mIPC
; }
187 nsresult
UpdatePaymentDetails(nsIPaymentDetails
* aPaymentDetails
,
188 const nsAString
& aShippingOption
);
190 void SetCompleteStatus(const nsAString
& aCompleteStatus
);
192 nsresult
UpdateErrors(const nsAString
& aError
, const nsAString
& aPayerErrors
,
193 const nsAString
& aPaymentMethodErrors
,
194 const nsAString
& aShippingAddressErrors
);
196 // The state represents the PaymentRequest's state in the spec. The state is
197 // not synchronized between content and parent processes.
198 // eCreated - the state means a PaymentRequest is created when new
199 // PaymentRequest() is called. This is the initial state.
200 // eInteractive - When PaymentRequest is requested to show to users, the state
201 // becomes eInteractive. Under eInteractive state, Payment UI
202 // pop up and gather the user's information until the user
203 // accepts or rejects the PaymentRequest.
204 // eClosed - When the user accepts or rejects the PaymentRequest, the
205 // state becomes eClosed. Under eClosed state, response from
206 // Payment UI would not be accepted by PaymentRequestService
207 // anymore, except the Complete response.
208 enum eState
{ eCreated
, eInteractive
, eClosed
};
210 void SetState(const eState aState
) { mState
= aState
; }
212 const eState
& GetState() const { return mState
; }
215 ~PaymentRequest() = default;
217 uint64_t mTopOuterWindowId
;
219 nsString mCompleteStatus
;
220 nsCOMPtr
<nsIPrincipal
> mTopLevelPrincipal
;
221 nsCOMPtr
<nsIArray
> mPaymentMethods
;
222 nsCOMPtr
<nsIPaymentDetails
> mPaymentDetails
;
223 nsCOMPtr
<nsIPaymentOptions
> mPaymentOptions
;
224 nsString mShippingOption
;
226 // IPC's life cycle should be controlled by IPC mechanism.
227 // PaymentRequest should not own the reference of it.
228 PaymentRequestParent
* mIPC
;
232 class PaymentAddress final
: public nsIPaymentAddress
{
235 NS_DECL_NSIPAYMENTADDRESS
237 PaymentAddress() = default;
240 ~PaymentAddress() = default;
243 nsCOMPtr
<nsIArray
> mAddressLine
;
245 nsString mRegionCode
;
247 nsString mDependentLocality
;
248 nsString mPostalCode
;
249 nsString mSortingCode
;
250 nsString mOrganization
;
255 } // namespace mozilla::dom::payments