Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / payments / PaymentRequestData.cpp
blobc4c8a3228fd9d0b780ebf0f0b7a47813d0aa32da
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 #include "mozilla/dom/PaymentRequestBinding.h"
8 #include "mozilla/dom/ToJSValue.h"
9 #include "nsArrayUtils.h"
10 #include "nsComponentManagerUtils.h"
11 #include "nsIMutableArray.h"
12 #include "nsUnicharUtils.h"
13 #include "PaymentRequestData.h"
14 #include "PaymentRequestUtils.h"
16 namespace mozilla::dom::payments {
18 /* PaymentMethodData */
20 NS_IMPL_ISUPPORTS(PaymentMethodData, nsIPaymentMethodData)
22 PaymentMethodData::PaymentMethodData(const nsAString& aSupportedMethods,
23 const nsAString& aData)
24 : mSupportedMethods(aSupportedMethods), mData(aData) {}
26 nsresult PaymentMethodData::Create(const IPCPaymentMethodData& aIPCMethodData,
27 nsIPaymentMethodData** aMethodData) {
28 NS_ENSURE_ARG_POINTER(aMethodData);
29 nsCOMPtr<nsIPaymentMethodData> methodData = new PaymentMethodData(
30 aIPCMethodData.supportedMethods(), aIPCMethodData.data());
31 methodData.forget(aMethodData);
32 return NS_OK;
35 NS_IMETHODIMP
36 PaymentMethodData::GetSupportedMethods(nsAString& aSupportedMethods) {
37 aSupportedMethods = mSupportedMethods;
38 return NS_OK;
41 NS_IMETHODIMP
42 PaymentMethodData::GetData(JSContext* aCx, JS::MutableHandleValue aData) {
43 if (mData.IsEmpty()) {
44 aData.set(JS::NullValue());
45 return NS_OK;
47 nsresult rv = DeserializeToJSValue(mData, aCx, aData);
48 if (NS_WARN_IF(NS_FAILED(rv))) {
49 return rv;
51 return NS_OK;
54 /* PaymentCurrencyAmount */
56 NS_IMPL_ISUPPORTS(PaymentCurrencyAmount, nsIPaymentCurrencyAmount)
58 PaymentCurrencyAmount::PaymentCurrencyAmount(const nsAString& aCurrency,
59 const nsAString& aValue)
60 : mValue(aValue) {
62 * According to the spec
63 * https://w3c.github.io/payment-request/#validity-checkers
64 * Set amount.currency to the result of ASCII uppercasing amount.currency.
66 ToUpperCase(aCurrency, mCurrency);
69 nsresult PaymentCurrencyAmount::Create(
70 const IPCPaymentCurrencyAmount& aIPCAmount,
71 nsIPaymentCurrencyAmount** aAmount) {
72 NS_ENSURE_ARG_POINTER(aAmount);
73 nsCOMPtr<nsIPaymentCurrencyAmount> amount =
74 new PaymentCurrencyAmount(aIPCAmount.currency(), aIPCAmount.value());
75 amount.forget(aAmount);
76 return NS_OK;
79 NS_IMETHODIMP
80 PaymentCurrencyAmount::GetCurrency(nsAString& aCurrency) {
81 aCurrency = mCurrency;
82 return NS_OK;
85 NS_IMETHODIMP
86 PaymentCurrencyAmount::GetValue(nsAString& aValue) {
87 aValue = mValue;
88 return NS_OK;
91 /* PaymentItem */
93 NS_IMPL_ISUPPORTS(PaymentItem, nsIPaymentItem)
95 PaymentItem::PaymentItem(const nsAString& aLabel,
96 nsIPaymentCurrencyAmount* aAmount, const bool aPending)
97 : mLabel(aLabel), mAmount(aAmount), mPending(aPending) {}
99 nsresult PaymentItem::Create(const IPCPaymentItem& aIPCItem,
100 nsIPaymentItem** aItem) {
101 NS_ENSURE_ARG_POINTER(aItem);
102 nsCOMPtr<nsIPaymentCurrencyAmount> amount;
103 nsresult rv =
104 PaymentCurrencyAmount::Create(aIPCItem.amount(), getter_AddRefs(amount));
105 if (NS_WARN_IF(NS_FAILED(rv))) {
106 return rv;
108 nsCOMPtr<nsIPaymentItem> item =
109 new PaymentItem(aIPCItem.label(), amount, aIPCItem.pending());
110 item.forget(aItem);
111 return NS_OK;
114 NS_IMETHODIMP
115 PaymentItem::GetLabel(nsAString& aLabel) {
116 aLabel = mLabel;
117 return NS_OK;
120 NS_IMETHODIMP
121 PaymentItem::GetAmount(nsIPaymentCurrencyAmount** aAmount) {
122 NS_ENSURE_ARG_POINTER(aAmount);
123 MOZ_ASSERT(mAmount);
124 nsCOMPtr<nsIPaymentCurrencyAmount> amount = mAmount;
125 amount.forget(aAmount);
126 return NS_OK;
129 NS_IMETHODIMP
130 PaymentItem::GetPending(bool* aPending) {
131 NS_ENSURE_ARG_POINTER(aPending);
132 *aPending = mPending;
133 return NS_OK;
136 /* PaymentDetailsModifier */
138 NS_IMPL_ISUPPORTS(PaymentDetailsModifier, nsIPaymentDetailsModifier)
140 PaymentDetailsModifier::PaymentDetailsModifier(
141 const nsAString& aSupportedMethods, nsIPaymentItem* aTotal,
142 nsIArray* aAdditionalDisplayItems, const nsAString& aData)
143 : mSupportedMethods(aSupportedMethods),
144 mTotal(aTotal),
145 mAdditionalDisplayItems(aAdditionalDisplayItems),
146 mData(aData) {}
148 nsresult PaymentDetailsModifier::Create(
149 const IPCPaymentDetailsModifier& aIPCModifier,
150 nsIPaymentDetailsModifier** aModifier) {
151 NS_ENSURE_ARG_POINTER(aModifier);
152 nsCOMPtr<nsIPaymentItem> total;
153 nsresult rv =
154 PaymentItem::Create(aIPCModifier.total(), getter_AddRefs(total));
155 if (NS_WARN_IF(NS_FAILED(rv))) {
156 return rv;
159 nsCOMPtr<nsIArray> displayItems;
160 if (aIPCModifier.additionalDisplayItemsPassed()) {
161 nsCOMPtr<nsIMutableArray> items = do_CreateInstance(NS_ARRAY_CONTRACTID);
162 MOZ_ASSERT(items);
163 for (const IPCPaymentItem& item : aIPCModifier.additionalDisplayItems()) {
164 nsCOMPtr<nsIPaymentItem> additionalItem;
165 rv = PaymentItem::Create(item, getter_AddRefs(additionalItem));
166 if (NS_WARN_IF(NS_FAILED(rv))) {
167 return rv;
169 rv = items->AppendElement(additionalItem);
170 if (NS_WARN_IF(NS_FAILED(rv))) {
171 return rv;
174 displayItems = std::move(items);
176 nsCOMPtr<nsIPaymentDetailsModifier> modifier =
177 new PaymentDetailsModifier(aIPCModifier.supportedMethods(), total,
178 displayItems, aIPCModifier.data());
179 modifier.forget(aModifier);
180 return NS_OK;
183 NS_IMETHODIMP
184 PaymentDetailsModifier::GetSupportedMethods(nsAString& aSupportedMethods) {
185 aSupportedMethods = mSupportedMethods;
186 return NS_OK;
189 NS_IMETHODIMP
190 PaymentDetailsModifier::GetTotal(nsIPaymentItem** aTotal) {
191 NS_ENSURE_ARG_POINTER(aTotal);
192 MOZ_ASSERT(mTotal);
193 nsCOMPtr<nsIPaymentItem> total = mTotal;
194 total.forget(aTotal);
195 return NS_OK;
198 NS_IMETHODIMP
199 PaymentDetailsModifier::GetAdditionalDisplayItems(
200 nsIArray** aAdditionalDisplayItems) {
201 NS_ENSURE_ARG_POINTER(aAdditionalDisplayItems);
202 nsCOMPtr<nsIArray> additionalItems = mAdditionalDisplayItems;
203 additionalItems.forget(aAdditionalDisplayItems);
204 return NS_OK;
207 NS_IMETHODIMP
208 PaymentDetailsModifier::GetData(JSContext* aCx, JS::MutableHandleValue aData) {
209 if (mData.IsEmpty()) {
210 aData.set(JS::NullValue());
211 return NS_OK;
213 nsresult rv = DeserializeToJSValue(mData, aCx, aData);
214 if (NS_WARN_IF(NS_FAILED(rv))) {
215 return rv;
217 return NS_OK;
220 /* PaymentShippingOption */
222 NS_IMPL_ISUPPORTS(PaymentShippingOption, nsIPaymentShippingOption)
224 PaymentShippingOption::PaymentShippingOption(const nsAString& aId,
225 const nsAString& aLabel,
226 nsIPaymentCurrencyAmount* aAmount,
227 const bool aSelected)
228 : mId(aId), mLabel(aLabel), mAmount(aAmount), mSelected(aSelected) {}
230 nsresult PaymentShippingOption::Create(
231 const IPCPaymentShippingOption& aIPCOption,
232 nsIPaymentShippingOption** aOption) {
233 NS_ENSURE_ARG_POINTER(aOption);
234 nsCOMPtr<nsIPaymentCurrencyAmount> amount;
235 nsresult rv = PaymentCurrencyAmount::Create(aIPCOption.amount(),
236 getter_AddRefs(amount));
237 if (NS_WARN_IF(NS_FAILED(rv))) {
238 return rv;
240 nsCOMPtr<nsIPaymentShippingOption> option = new PaymentShippingOption(
241 aIPCOption.id(), aIPCOption.label(), amount, aIPCOption.selected());
242 option.forget(aOption);
243 return NS_OK;
246 NS_IMETHODIMP
247 PaymentShippingOption::GetId(nsAString& aId) {
248 aId = mId;
249 return NS_OK;
252 NS_IMETHODIMP
253 PaymentShippingOption::GetLabel(nsAString& aLabel) {
254 aLabel = mLabel;
255 return NS_OK;
258 NS_IMETHODIMP
259 PaymentShippingOption::GetAmount(nsIPaymentCurrencyAmount** aAmount) {
260 NS_ENSURE_ARG_POINTER(aAmount);
261 MOZ_ASSERT(mAmount);
262 nsCOMPtr<nsIPaymentCurrencyAmount> amount = mAmount;
263 amount.forget(aAmount);
264 return NS_OK;
267 NS_IMETHODIMP
268 PaymentShippingOption::GetSelected(bool* aSelected) {
269 NS_ENSURE_ARG_POINTER(aSelected);
270 *aSelected = mSelected;
271 return NS_OK;
274 NS_IMETHODIMP
275 PaymentShippingOption::SetSelected(bool aSelected) {
276 mSelected = aSelected;
277 return NS_OK;
280 /* PaymentDetails */
282 NS_IMPL_ISUPPORTS(PaymentDetails, nsIPaymentDetails)
284 PaymentDetails::PaymentDetails(const nsAString& aId, nsIPaymentItem* aTotalItem,
285 nsIArray* aDisplayItems,
286 nsIArray* aShippingOptions, nsIArray* aModifiers,
287 const nsAString& aError,
288 const nsAString& aShippingAddressErrors,
289 const nsAString& aPayerErrors,
290 const nsAString& aPaymentMethodErrors)
291 : mId(aId),
292 mTotalItem(aTotalItem),
293 mDisplayItems(aDisplayItems),
294 mShippingOptions(aShippingOptions),
295 mModifiers(aModifiers),
296 mError(aError),
297 mShippingAddressErrors(aShippingAddressErrors),
298 mPayerErrors(aPayerErrors),
299 mPaymentMethodErrors(aPaymentMethodErrors) {}
301 nsresult PaymentDetails::Create(const IPCPaymentDetails& aIPCDetails,
302 nsIPaymentDetails** aDetails) {
303 NS_ENSURE_ARG_POINTER(aDetails);
305 nsCOMPtr<nsIPaymentItem> total;
306 nsresult rv = PaymentItem::Create(aIPCDetails.total(), getter_AddRefs(total));
307 if (NS_WARN_IF(NS_FAILED(rv))) {
308 return rv;
311 nsCOMPtr<nsIArray> displayItems;
312 nsCOMPtr<nsIMutableArray> items = do_CreateInstance(NS_ARRAY_CONTRACTID);
313 MOZ_ASSERT(items);
314 for (const IPCPaymentItem& displayItem : aIPCDetails.displayItems()) {
315 nsCOMPtr<nsIPaymentItem> item;
316 rv = PaymentItem::Create(displayItem, getter_AddRefs(item));
317 if (NS_WARN_IF(NS_FAILED(rv))) {
318 return rv;
320 rv = items->AppendElement(item);
321 if (NS_WARN_IF(NS_FAILED(rv))) {
322 return rv;
325 displayItems = std::move(items);
327 nsCOMPtr<nsIArray> shippingOptions;
328 nsCOMPtr<nsIMutableArray> options = do_CreateInstance(NS_ARRAY_CONTRACTID);
329 MOZ_ASSERT(options);
330 for (const IPCPaymentShippingOption& shippingOption :
331 aIPCDetails.shippingOptions()) {
332 nsCOMPtr<nsIPaymentShippingOption> option;
333 rv = PaymentShippingOption::Create(shippingOption, getter_AddRefs(option));
334 if (NS_WARN_IF(NS_FAILED(rv))) {
335 return rv;
337 rv = options->AppendElement(option);
338 if (NS_WARN_IF(NS_FAILED(rv))) {
339 return rv;
342 shippingOptions = std::move(options);
344 nsCOMPtr<nsIArray> modifiers;
345 nsCOMPtr<nsIMutableArray> detailsModifiers =
346 do_CreateInstance(NS_ARRAY_CONTRACTID);
347 MOZ_ASSERT(detailsModifiers);
348 for (const IPCPaymentDetailsModifier& modifier : aIPCDetails.modifiers()) {
349 nsCOMPtr<nsIPaymentDetailsModifier> detailsModifier;
350 rv = PaymentDetailsModifier::Create(modifier,
351 getter_AddRefs(detailsModifier));
352 if (NS_WARN_IF(NS_FAILED(rv))) {
353 return rv;
355 rv = detailsModifiers->AppendElement(detailsModifier);
356 if (NS_WARN_IF(NS_FAILED(rv))) {
357 return rv;
360 modifiers = std::move(detailsModifiers);
362 nsCOMPtr<nsIPaymentDetails> details = new PaymentDetails(
363 aIPCDetails.id(), total, displayItems, shippingOptions, modifiers,
364 aIPCDetails.error(), aIPCDetails.shippingAddressErrors(),
365 aIPCDetails.payerErrors(), aIPCDetails.paymentMethodErrors());
367 details.forget(aDetails);
368 return NS_OK;
371 NS_IMETHODIMP
372 PaymentDetails::GetId(nsAString& aId) {
373 aId = mId;
374 return NS_OK;
377 NS_IMETHODIMP
378 PaymentDetails::GetTotalItem(nsIPaymentItem** aTotalItem) {
379 NS_ENSURE_ARG_POINTER(aTotalItem);
380 MOZ_ASSERT(mTotalItem);
381 nsCOMPtr<nsIPaymentItem> total = mTotalItem;
382 total.forget(aTotalItem);
383 return NS_OK;
386 NS_IMETHODIMP
387 PaymentDetails::GetDisplayItems(nsIArray** aDisplayItems) {
388 NS_ENSURE_ARG_POINTER(aDisplayItems);
389 nsCOMPtr<nsIArray> displayItems = mDisplayItems;
390 displayItems.forget(aDisplayItems);
391 return NS_OK;
394 NS_IMETHODIMP
395 PaymentDetails::GetShippingOptions(nsIArray** aShippingOptions) {
396 NS_ENSURE_ARG_POINTER(aShippingOptions);
397 nsCOMPtr<nsIArray> options = mShippingOptions;
398 options.forget(aShippingOptions);
399 return NS_OK;
402 NS_IMETHODIMP
403 PaymentDetails::GetModifiers(nsIArray** aModifiers) {
404 NS_ENSURE_ARG_POINTER(aModifiers);
405 nsCOMPtr<nsIArray> modifiers = mModifiers;
406 modifiers.forget(aModifiers);
407 return NS_OK;
410 NS_IMETHODIMP
411 PaymentDetails::GetError(nsAString& aError) {
412 aError = mError;
413 return NS_OK;
416 NS_IMETHODIMP
417 PaymentDetails::GetShippingAddressErrors(JSContext* aCx,
418 JS::MutableHandleValue aErrors) {
419 AddressErrors errors;
420 errors.Init(mShippingAddressErrors);
421 if (!ToJSValue(aCx, errors, aErrors)) {
422 return NS_ERROR_FAILURE;
424 return NS_OK;
427 NS_IMETHODIMP
428 PaymentDetails::GetPayerErrors(JSContext* aCx, JS::MutableHandleValue aErrors) {
429 PayerErrors errors;
430 errors.Init(mPayerErrors);
431 if (!ToJSValue(aCx, errors, aErrors)) {
432 return NS_ERROR_FAILURE;
434 return NS_OK;
437 NS_IMETHODIMP
438 PaymentDetails::GetPaymentMethodErrors(JSContext* aCx,
439 JS::MutableHandleValue aErrors) {
440 if (mPaymentMethodErrors.IsEmpty()) {
441 aErrors.set(JS::NullValue());
442 return NS_OK;
444 nsresult rv = DeserializeToJSValue(mPaymentMethodErrors, aCx, aErrors);
445 if (NS_WARN_IF(NS_FAILED(rv))) {
446 return rv;
448 return NS_OK;
451 nsresult PaymentDetails::Update(nsIPaymentDetails* aDetails,
452 const bool aRequestShipping) {
453 MOZ_ASSERT(aDetails);
455 * According to the spec [1], update the attributes if they present in new
456 * details (i.e., PaymentDetailsUpdate); otherwise, keep original value.
457 * Note |id| comes only from initial details (i.e., PaymentDetailsInit) and
458 * |error| only from new details.
460 * [1] https://www.w3.org/TR/payment-request/#updatewith-method
463 nsresult rv = aDetails->GetTotalItem(getter_AddRefs(mTotalItem));
464 if (NS_WARN_IF(NS_FAILED(rv))) {
465 return rv;
468 nsCOMPtr<nsIArray> displayItems;
469 rv = aDetails->GetDisplayItems(getter_AddRefs(displayItems));
470 if (NS_WARN_IF(NS_FAILED(rv))) {
471 return rv;
473 if (displayItems) {
474 mDisplayItems = displayItems;
477 if (aRequestShipping) {
478 nsCOMPtr<nsIArray> shippingOptions;
479 rv = aDetails->GetShippingOptions(getter_AddRefs(shippingOptions));
480 if (NS_WARN_IF(NS_FAILED(rv))) {
481 return rv;
483 mShippingOptions = shippingOptions;
486 nsCOMPtr<nsIArray> modifiers;
487 rv = aDetails->GetModifiers(getter_AddRefs(modifiers));
488 if (NS_WARN_IF(NS_FAILED(rv))) {
489 return rv;
491 if (modifiers) {
492 mModifiers = modifiers;
495 rv = aDetails->GetError(mError);
496 if (NS_WARN_IF(NS_FAILED(rv))) {
497 return rv;
500 PaymentDetails* rowDetails = static_cast<PaymentDetails*>(aDetails);
501 MOZ_ASSERT(rowDetails);
502 mShippingAddressErrors = rowDetails->GetShippingAddressErrors();
503 mPayerErrors = rowDetails->GetPayerErrors();
504 mPaymentMethodErrors = rowDetails->GetPaymentMethodErrors();
506 return NS_OK;
509 const nsString& PaymentDetails::GetShippingAddressErrors() const {
510 return mShippingAddressErrors;
513 const nsString& PaymentDetails::GetPayerErrors() const { return mPayerErrors; }
515 const nsString& PaymentDetails::GetPaymentMethodErrors() const {
516 return mPaymentMethodErrors;
519 nsresult PaymentDetails::UpdateErrors(const nsAString& aError,
520 const nsAString& aPayerErrors,
521 const nsAString& aPaymentMethodErrors,
522 const nsAString& aShippingAddressErrors) {
523 mError = aError;
524 mPayerErrors = aPayerErrors;
525 mPaymentMethodErrors = aPaymentMethodErrors;
526 mShippingAddressErrors = aShippingAddressErrors;
527 return NS_OK;
530 /* PaymentOptions */
532 NS_IMPL_ISUPPORTS(PaymentOptions, nsIPaymentOptions)
534 PaymentOptions::PaymentOptions(const bool aRequestPayerName,
535 const bool aRequestPayerEmail,
536 const bool aRequestPayerPhone,
537 const bool aRequestShipping,
538 const bool aRequestBillingAddress,
539 const nsAString& aShippingType)
540 : mRequestPayerName(aRequestPayerName),
541 mRequestPayerEmail(aRequestPayerEmail),
542 mRequestPayerPhone(aRequestPayerPhone),
543 mRequestShipping(aRequestShipping),
544 mRequestBillingAddress(aRequestBillingAddress),
545 mShippingType(aShippingType) {}
547 nsresult PaymentOptions::Create(const IPCPaymentOptions& aIPCOptions,
548 nsIPaymentOptions** aOptions) {
549 NS_ENSURE_ARG_POINTER(aOptions);
551 nsCOMPtr<nsIPaymentOptions> options = new PaymentOptions(
552 aIPCOptions.requestPayerName(), aIPCOptions.requestPayerEmail(),
553 aIPCOptions.requestPayerPhone(), aIPCOptions.requestShipping(),
554 aIPCOptions.requestBillingAddress(), aIPCOptions.shippingType());
555 options.forget(aOptions);
556 return NS_OK;
559 NS_IMETHODIMP
560 PaymentOptions::GetRequestPayerName(bool* aRequestPayerName) {
561 NS_ENSURE_ARG_POINTER(aRequestPayerName);
562 *aRequestPayerName = mRequestPayerName;
563 return NS_OK;
566 NS_IMETHODIMP
567 PaymentOptions::GetRequestPayerEmail(bool* aRequestPayerEmail) {
568 NS_ENSURE_ARG_POINTER(aRequestPayerEmail);
569 *aRequestPayerEmail = mRequestPayerEmail;
570 return NS_OK;
573 NS_IMETHODIMP
574 PaymentOptions::GetRequestPayerPhone(bool* aRequestPayerPhone) {
575 NS_ENSURE_ARG_POINTER(aRequestPayerPhone);
576 *aRequestPayerPhone = mRequestPayerPhone;
577 return NS_OK;
580 NS_IMETHODIMP
581 PaymentOptions::GetRequestShipping(bool* aRequestShipping) {
582 NS_ENSURE_ARG_POINTER(aRequestShipping);
583 *aRequestShipping = mRequestShipping;
584 return NS_OK;
587 NS_IMETHODIMP
588 PaymentOptions::GetRequestBillingAddress(bool* aRequestBillingAddress) {
589 NS_ENSURE_ARG_POINTER(aRequestBillingAddress);
590 *aRequestBillingAddress = mRequestBillingAddress;
591 return NS_OK;
594 NS_IMETHODIMP
595 PaymentOptions::GetShippingType(nsAString& aShippingType) {
596 aShippingType = mShippingType;
597 return NS_OK;
600 /* PaymentReqeust */
602 NS_IMPL_ISUPPORTS(PaymentRequest, nsIPaymentRequest)
604 PaymentRequest::PaymentRequest(const uint64_t aTopOuterWindowId,
605 const nsAString& aRequestId,
606 nsIPrincipal* aTopLevelPrincipal,
607 nsIArray* aPaymentMethods,
608 nsIPaymentDetails* aPaymentDetails,
609 nsIPaymentOptions* aPaymentOptions,
610 const nsAString& aShippingOption)
611 : mTopOuterWindowId(aTopOuterWindowId),
612 mRequestId(aRequestId),
613 mTopLevelPrincipal(aTopLevelPrincipal),
614 mPaymentMethods(aPaymentMethods),
615 mPaymentDetails(aPaymentDetails),
616 mPaymentOptions(aPaymentOptions),
617 mShippingOption(aShippingOption),
618 mState(eCreated) {}
620 NS_IMETHODIMP
621 PaymentRequest::GetTopOuterWindowId(uint64_t* aTopOuterWindowId) {
622 NS_ENSURE_ARG_POINTER(aTopOuterWindowId);
623 *aTopOuterWindowId = mTopOuterWindowId;
624 return NS_OK;
627 NS_IMETHODIMP
628 PaymentRequest::GetTopLevelPrincipal(nsIPrincipal** aTopLevelPrincipal) {
629 NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
630 MOZ_ASSERT(mTopLevelPrincipal);
631 nsCOMPtr<nsIPrincipal> principal = mTopLevelPrincipal;
632 principal.forget(aTopLevelPrincipal);
633 return NS_OK;
636 NS_IMETHODIMP
637 PaymentRequest::GetRequestId(nsAString& aRequestId) {
638 aRequestId = mRequestId;
639 return NS_OK;
642 NS_IMETHODIMP
643 PaymentRequest::GetPaymentMethods(nsIArray** aPaymentMethods) {
644 NS_ENSURE_ARG_POINTER(aPaymentMethods);
645 MOZ_ASSERT(mPaymentMethods);
646 nsCOMPtr<nsIArray> methods = mPaymentMethods;
647 methods.forget(aPaymentMethods);
648 return NS_OK;
651 NS_IMETHODIMP
652 PaymentRequest::GetPaymentDetails(nsIPaymentDetails** aPaymentDetails) {
653 NS_ENSURE_ARG_POINTER(aPaymentDetails);
654 MOZ_ASSERT(mPaymentDetails);
655 nsCOMPtr<nsIPaymentDetails> details = mPaymentDetails;
656 details.forget(aPaymentDetails);
657 return NS_OK;
660 NS_IMETHODIMP
661 PaymentRequest::GetPaymentOptions(nsIPaymentOptions** aPaymentOptions) {
662 NS_ENSURE_ARG_POINTER(aPaymentOptions);
663 MOZ_ASSERT(mPaymentOptions);
664 nsCOMPtr<nsIPaymentOptions> options = mPaymentOptions;
665 options.forget(aPaymentOptions);
666 return NS_OK;
669 NS_IMETHODIMP
670 PaymentRequest::GetShippingOption(nsAString& aShippingOption) {
671 aShippingOption = mShippingOption;
672 return NS_OK;
675 nsresult PaymentRequest::UpdatePaymentDetails(
676 nsIPaymentDetails* aPaymentDetails, const nsAString& aShippingOption) {
677 MOZ_ASSERT(aPaymentDetails);
678 bool requestShipping;
679 nsresult rv = mPaymentOptions->GetRequestShipping(&requestShipping);
680 if (NS_WARN_IF(NS_FAILED(rv))) {
681 return rv;
683 mShippingOption = aShippingOption;
685 PaymentDetails* rowDetails =
686 static_cast<PaymentDetails*>(mPaymentDetails.get());
687 MOZ_ASSERT(rowDetails);
688 return rowDetails->Update(aPaymentDetails, requestShipping);
691 void PaymentRequest::SetCompleteStatus(const nsAString& aCompleteStatus) {
692 mCompleteStatus = aCompleteStatus;
695 nsresult PaymentRequest::UpdateErrors(const nsAString& aError,
696 const nsAString& aPayerErrors,
697 const nsAString& aPaymentMethodErrors,
698 const nsAString& aShippingAddressErrors) {
699 PaymentDetails* rowDetails =
700 static_cast<PaymentDetails*>(mPaymentDetails.get());
701 MOZ_ASSERT(rowDetails);
702 return rowDetails->UpdateErrors(aError, aPayerErrors, aPaymentMethodErrors,
703 aShippingAddressErrors);
706 NS_IMETHODIMP
707 PaymentRequest::GetCompleteStatus(nsAString& aCompleteStatus) {
708 aCompleteStatus = mCompleteStatus;
709 return NS_OK;
712 /* PaymentAddress */
714 NS_IMPL_ISUPPORTS(PaymentAddress, nsIPaymentAddress)
716 NS_IMETHODIMP
717 PaymentAddress::Init(const nsAString& aCountry, nsIArray* aAddressLine,
718 const nsAString& aRegion, const nsAString& aRegionCode,
719 const nsAString& aCity,
720 const nsAString& aDependentLocality,
721 const nsAString& aPostalCode,
722 const nsAString& aSortingCode,
723 const nsAString& aOrganization,
724 const nsAString& aRecipient, const nsAString& aPhone) {
725 mCountry = aCountry;
726 mAddressLine = aAddressLine;
727 mRegion = aRegion;
728 mRegionCode = aRegionCode;
729 mCity = aCity;
730 mDependentLocality = aDependentLocality;
731 mPostalCode = aPostalCode;
732 mSortingCode = aSortingCode;
733 mOrganization = aOrganization;
734 mRecipient = aRecipient;
735 mPhone = aPhone;
736 return NS_OK;
739 NS_IMETHODIMP
740 PaymentAddress::GetCountry(nsAString& aCountry) {
741 aCountry = mCountry;
742 return NS_OK;
745 NS_IMETHODIMP
746 PaymentAddress::GetAddressLine(nsIArray** aAddressLine) {
747 NS_ENSURE_ARG_POINTER(aAddressLine);
748 nsCOMPtr<nsIArray> addressLine = mAddressLine;
749 addressLine.forget(aAddressLine);
750 return NS_OK;
753 NS_IMETHODIMP
754 PaymentAddress::GetRegion(nsAString& aRegion) {
755 aRegion = mRegion;
756 return NS_OK;
759 NS_IMETHODIMP
760 PaymentAddress::GetRegionCode(nsAString& aRegionCode) {
761 aRegionCode = mRegionCode;
762 return NS_OK;
765 NS_IMETHODIMP
766 PaymentAddress::GetCity(nsAString& aCity) {
767 aCity = mCity;
768 return NS_OK;
771 NS_IMETHODIMP
772 PaymentAddress::GetDependentLocality(nsAString& aDependentLocality) {
773 aDependentLocality = mDependentLocality;
774 return NS_OK;
777 NS_IMETHODIMP
778 PaymentAddress::GetPostalCode(nsAString& aPostalCode) {
779 aPostalCode = mPostalCode;
780 return NS_OK;
783 NS_IMETHODIMP
784 PaymentAddress::GetSortingCode(nsAString& aSortingCode) {
785 aSortingCode = mSortingCode;
786 return NS_OK;
789 NS_IMETHODIMP
790 PaymentAddress::GetOrganization(nsAString& aOrganization) {
791 aOrganization = mOrganization;
792 return NS_OK;
795 NS_IMETHODIMP
796 PaymentAddress::GetRecipient(nsAString& aRecipient) {
797 aRecipient = mRecipient;
798 return NS_OK;
801 NS_IMETHODIMP
802 PaymentAddress::GetPhone(nsAString& aPhone) {
803 aPhone = mPhone;
804 return NS_OK;
807 } // namespace mozilla::dom::payments