Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / payments / PaymentRequestData.h
blobe4b9cadcd1131b1bc1a6ff20c55af7031257a4e5
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"
12 #include "nsCOMPtr.h"
13 #include "mozilla/dom/PaymentRequestParent.h"
15 namespace mozilla::dom::payments {
17 class PaymentMethodData final : public nsIPaymentMethodData {
18 public:
19 NS_DECL_ISUPPORTS
20 NS_DECL_NSIPAYMENTMETHODDATA
22 static nsresult Create(const IPCPaymentMethodData& aIPCMethodData,
23 nsIPaymentMethodData** aMethodData);
25 private:
26 PaymentMethodData(const nsAString& aSupportedMethods, const nsAString& aData);
28 ~PaymentMethodData() = default;
30 nsString mSupportedMethods;
31 nsString mData;
34 class PaymentCurrencyAmount final : public nsIPaymentCurrencyAmount {
35 public:
36 NS_DECL_ISUPPORTS
37 NS_DECL_NSIPAYMENTCURRENCYAMOUNT
39 static nsresult Create(const IPCPaymentCurrencyAmount& aIPCAmount,
40 nsIPaymentCurrencyAmount** aAmount);
42 private:
43 PaymentCurrencyAmount(const nsAString& aCurrency, const nsAString& aValue);
45 ~PaymentCurrencyAmount() = default;
47 nsString mCurrency;
48 nsString mValue;
51 class PaymentItem final : public nsIPaymentItem {
52 public:
53 NS_DECL_ISUPPORTS
54 NS_DECL_NSIPAYMENTITEM
56 static nsresult Create(const IPCPaymentItem& aIPCItem,
57 nsIPaymentItem** aItem);
59 private:
60 PaymentItem(const nsAString& aLabel, nsIPaymentCurrencyAmount* aAmount,
61 const bool aPending);
63 ~PaymentItem() = default;
65 nsString mLabel;
66 nsCOMPtr<nsIPaymentCurrencyAmount> mAmount;
67 bool mPending;
70 class PaymentDetailsModifier final : public nsIPaymentDetailsModifier {
71 public:
72 NS_DECL_ISUPPORTS
73 NS_DECL_NSIPAYMENTDETAILSMODIFIER
75 static nsresult Create(const IPCPaymentDetailsModifier& aIPCModifier,
76 nsIPaymentDetailsModifier** aModifier);
78 private:
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;
89 nsString mData;
92 class PaymentShippingOption final : public nsIPaymentShippingOption {
93 public:
94 NS_DECL_ISUPPORTS
95 NS_DECL_NSIPAYMENTSHIPPINGOPTION
97 static nsresult Create(const IPCPaymentShippingOption& aIPCOption,
98 nsIPaymentShippingOption** aOption);
100 private:
101 PaymentShippingOption(const nsAString& aId, const nsAString& aLabel,
102 nsIPaymentCurrencyAmount* aAmount,
103 const bool aSelected = false);
105 ~PaymentShippingOption() = default;
107 nsString mId;
108 nsString mLabel;
109 nsCOMPtr<nsIPaymentCurrencyAmount> mAmount;
110 bool mSelected;
113 class PaymentDetails final : public nsIPaymentDetails {
114 public:
115 NS_DECL_ISUPPORTS
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);
128 private:
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;
138 nsString mId;
139 nsCOMPtr<nsIPaymentItem> mTotalItem;
140 nsCOMPtr<nsIArray> mDisplayItems;
141 nsCOMPtr<nsIArray> mShippingOptions;
142 nsCOMPtr<nsIArray> mModifiers;
143 nsString mError;
144 nsString mShippingAddressErrors;
145 nsString mPayerErrors;
146 nsString mPaymentMethodErrors;
149 class PaymentOptions final : public nsIPaymentOptions {
150 public:
151 NS_DECL_ISUPPORTS
152 NS_DECL_NSIPAYMENTOPTIONS
154 static nsresult Create(const IPCPaymentOptions& aIPCOptions,
155 nsIPaymentOptions** aOptions);
157 private:
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 {
173 public:
174 NS_DECL_ISUPPORTS
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; }
214 private:
215 ~PaymentRequest() = default;
217 uint64_t mTopOuterWindowId;
218 nsString mRequestId;
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;
229 eState mState;
232 class PaymentAddress final : public nsIPaymentAddress {
233 public:
234 NS_DECL_ISUPPORTS
235 NS_DECL_NSIPAYMENTADDRESS
237 PaymentAddress() = default;
239 private:
240 ~PaymentAddress() = default;
242 nsString mCountry;
243 nsCOMPtr<nsIArray> mAddressLine;
244 nsString mRegion;
245 nsString mRegionCode;
246 nsString mCity;
247 nsString mDependentLocality;
248 nsString mPostalCode;
249 nsString mSortingCode;
250 nsString mOrganization;
251 nsString mRecipient;
252 nsString mPhone;
255 } // namespace mozilla::dom::payments
257 #endif