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"
19 class PaymentMethodData final
: public nsIPaymentMethodData
{
22 NS_DECL_NSIPAYMENTMETHODDATA
24 static nsresult
Create(const IPCPaymentMethodData
& aIPCMethodData
,
25 nsIPaymentMethodData
** aMethodData
);
28 PaymentMethodData(const nsAString
& aSupportedMethods
, const nsAString
& aData
);
30 ~PaymentMethodData() = default;
32 nsString mSupportedMethods
;
36 class PaymentCurrencyAmount final
: public nsIPaymentCurrencyAmount
{
39 NS_DECL_NSIPAYMENTCURRENCYAMOUNT
41 static nsresult
Create(const IPCPaymentCurrencyAmount
& aIPCAmount
,
42 nsIPaymentCurrencyAmount
** aAmount
);
45 PaymentCurrencyAmount(const nsAString
& aCurrency
, const nsAString
& aValue
);
47 ~PaymentCurrencyAmount() = default;
53 class PaymentItem final
: public nsIPaymentItem
{
56 NS_DECL_NSIPAYMENTITEM
58 static nsresult
Create(const IPCPaymentItem
& aIPCItem
,
59 nsIPaymentItem
** aItem
);
62 PaymentItem(const nsAString
& aLabel
, nsIPaymentCurrencyAmount
* aAmount
,
65 ~PaymentItem() = default;
68 nsCOMPtr
<nsIPaymentCurrencyAmount
> mAmount
;
72 class PaymentDetailsModifier final
: public nsIPaymentDetailsModifier
{
75 NS_DECL_NSIPAYMENTDETAILSMODIFIER
77 static nsresult
Create(const IPCPaymentDetailsModifier
& aIPCModifier
,
78 nsIPaymentDetailsModifier
** aModifier
);
81 PaymentDetailsModifier(const nsAString
& aSupportedMethods
,
82 nsIPaymentItem
* aTotal
,
83 nsIArray
* aAdditionalDisplayItems
,
84 const nsAString
& aData
);
86 ~PaymentDetailsModifier() = default;
88 nsString mSupportedMethods
;
89 nsCOMPtr
<nsIPaymentItem
> mTotal
;
90 nsCOMPtr
<nsIArray
> mAdditionalDisplayItems
;
94 class PaymentShippingOption final
: public nsIPaymentShippingOption
{
97 NS_DECL_NSIPAYMENTSHIPPINGOPTION
99 static nsresult
Create(const IPCPaymentShippingOption
& aIPCOption
,
100 nsIPaymentShippingOption
** aOption
);
103 PaymentShippingOption(const nsAString
& aId
, const nsAString
& aLabel
,
104 nsIPaymentCurrencyAmount
* aAmount
,
105 const bool aSelected
= false);
107 ~PaymentShippingOption() = default;
111 nsCOMPtr
<nsIPaymentCurrencyAmount
> mAmount
;
115 class PaymentDetails final
: public nsIPaymentDetails
{
118 NS_DECL_NSIPAYMENTDETAILS
120 static nsresult
Create(const IPCPaymentDetails
& aIPCDetails
,
121 nsIPaymentDetails
** aDetails
);
122 nsresult
Update(nsIPaymentDetails
* aDetails
, const bool aRequestShipping
);
123 const nsString
& GetShippingAddressErrors() const;
124 const nsString
& GetPayerErrors() const;
125 const nsString
& GetPaymentMethodErrors() const;
126 nsresult
UpdateErrors(const nsAString
& aError
, const nsAString
& aPayerErrors
,
127 const nsAString
& aPaymentMethodErrors
,
128 const nsAString
& aShippingAddressErrors
);
131 PaymentDetails(const nsAString
& aId
, nsIPaymentItem
* aTotalItem
,
132 nsIArray
* aDisplayItems
, nsIArray
* aShippingOptions
,
133 nsIArray
* aModifiers
, const nsAString
& aError
,
134 const nsAString
& aShippingAddressError
,
135 const nsAString
& aPayerError
,
136 const nsAString
& aPaymentMethodError
);
138 ~PaymentDetails() = default;
141 nsCOMPtr
<nsIPaymentItem
> mTotalItem
;
142 nsCOMPtr
<nsIArray
> mDisplayItems
;
143 nsCOMPtr
<nsIArray
> mShippingOptions
;
144 nsCOMPtr
<nsIArray
> mModifiers
;
146 nsString mShippingAddressErrors
;
147 nsString mPayerErrors
;
148 nsString mPaymentMethodErrors
;
151 class PaymentOptions final
: public nsIPaymentOptions
{
154 NS_DECL_NSIPAYMENTOPTIONS
156 static nsresult
Create(const IPCPaymentOptions
& aIPCOptions
,
157 nsIPaymentOptions
** aOptions
);
160 PaymentOptions(const bool aRequestPayerName
, const bool aRequestPayerEmail
,
161 const bool aRequestPayerPhone
, const bool aRequestShipping
,
162 const bool aRequestBillingAddress
,
163 const nsAString
& aShippintType
);
164 ~PaymentOptions() = default;
166 bool mRequestPayerName
;
167 bool mRequestPayerEmail
;
168 bool mRequestPayerPhone
;
169 bool mRequestShipping
;
170 bool mRequestBillingAddress
;
171 nsString mShippingType
;
174 class PaymentRequest final
: public nsIPaymentRequest
{
177 NS_DECL_NSIPAYMENTREQUEST
179 PaymentRequest(const uint64_t aTopOuterWindowId
, const nsAString
& aRequestId
,
180 nsIPrincipal
* aPrincipal
, nsIArray
* aPaymentMethods
,
181 nsIPaymentDetails
* aPaymentDetails
,
182 nsIPaymentOptions
* aPaymentOptions
,
183 const nsAString
& aShippingOption
);
185 void SetIPC(PaymentRequestParent
* aIPC
) { mIPC
= aIPC
; }
187 PaymentRequestParent
* GetIPC() const { return mIPC
; }
189 nsresult
UpdatePaymentDetails(nsIPaymentDetails
* aPaymentDetails
,
190 const nsAString
& aShippingOption
);
192 void SetCompleteStatus(const nsAString
& aCompleteStatus
);
194 nsresult
UpdateErrors(const nsAString
& aError
, const nsAString
& aPayerErrors
,
195 const nsAString
& aPaymentMethodErrors
,
196 const nsAString
& aShippingAddressErrors
);
198 // The state represents the PaymentRequest's state in the spec. The state is
199 // not synchronized between content and parent processes.
200 // eCreated - the state means a PaymentRequest is created when new
201 // PaymentRequest() is called. This is the initial state.
202 // eInteractive - When PaymentRequest is requested to show to users, the state
203 // becomes eInteractive. Under eInteractive state, Payment UI
204 // pop up and gather the user's information until the user
205 // accepts or rejects the PaymentRequest.
206 // eClosed - When the user accepts or rejects the PaymentRequest, the
207 // state becomes eClosed. Under eClosed state, response from
208 // Payment UI would not be accepted by PaymentRequestService
209 // anymore, except the Complete response.
210 enum eState
{ eCreated
, eInteractive
, eClosed
};
212 void SetState(const eState aState
) { mState
= aState
; }
214 const eState
& GetState() const { return mState
; }
217 ~PaymentRequest() = default;
219 uint64_t mTopOuterWindowId
;
221 nsString mCompleteStatus
;
222 nsCOMPtr
<nsIPrincipal
> mTopLevelPrincipal
;
223 nsCOMPtr
<nsIArray
> mPaymentMethods
;
224 nsCOMPtr
<nsIPaymentDetails
> mPaymentDetails
;
225 nsCOMPtr
<nsIPaymentOptions
> mPaymentOptions
;
226 nsString mShippingOption
;
228 // IPC's life cycle should be controlled by IPC mechanism.
229 // PaymentRequest should not own the reference of it.
230 PaymentRequestParent
* mIPC
;
234 class PaymentAddress final
: public nsIPaymentAddress
{
237 NS_DECL_NSIPAYMENTADDRESS
239 PaymentAddress() = default;
242 ~PaymentAddress() = default;
245 nsCOMPtr
<nsIArray
> mAddressLine
;
247 nsString mRegionCode
;
249 nsString mDependentLocality
;
250 nsString mPostalCode
;
251 nsString mSortingCode
;
252 nsString mOrganization
;
257 } // namespace payments
258 } // end of namespace dom
259 } // end of namespace mozilla