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
);
36 PaymentMethodData::GetSupportedMethods(nsAString
& aSupportedMethods
) {
37 aSupportedMethods
= mSupportedMethods
;
42 PaymentMethodData::GetData(JSContext
* aCx
, JS::MutableHandleValue aData
) {
43 if (mData
.IsEmpty()) {
44 aData
.set(JS::NullValue());
47 nsresult rv
= DeserializeToJSValue(mData
, aCx
, aData
);
48 if (NS_WARN_IF(NS_FAILED(rv
))) {
54 /* PaymentCurrencyAmount */
56 NS_IMPL_ISUPPORTS(PaymentCurrencyAmount
, nsIPaymentCurrencyAmount
)
58 PaymentCurrencyAmount::PaymentCurrencyAmount(const nsAString
& aCurrency
,
59 const nsAString
& 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
);
80 PaymentCurrencyAmount::GetCurrency(nsAString
& aCurrency
) {
81 aCurrency
= mCurrency
;
86 PaymentCurrencyAmount::GetValue(nsAString
& aValue
) {
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
;
104 PaymentCurrencyAmount::Create(aIPCItem
.amount(), getter_AddRefs(amount
));
105 if (NS_WARN_IF(NS_FAILED(rv
))) {
108 nsCOMPtr
<nsIPaymentItem
> item
=
109 new PaymentItem(aIPCItem
.label(), amount
, aIPCItem
.pending());
115 PaymentItem::GetLabel(nsAString
& aLabel
) {
121 PaymentItem::GetAmount(nsIPaymentCurrencyAmount
** aAmount
) {
122 NS_ENSURE_ARG_POINTER(aAmount
);
124 nsCOMPtr
<nsIPaymentCurrencyAmount
> amount
= mAmount
;
125 amount
.forget(aAmount
);
130 PaymentItem::GetPending(bool* aPending
) {
131 NS_ENSURE_ARG_POINTER(aPending
);
132 *aPending
= mPending
;
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
),
145 mAdditionalDisplayItems(aAdditionalDisplayItems
),
148 nsresult
PaymentDetailsModifier::Create(
149 const IPCPaymentDetailsModifier
& aIPCModifier
,
150 nsIPaymentDetailsModifier
** aModifier
) {
151 NS_ENSURE_ARG_POINTER(aModifier
);
152 nsCOMPtr
<nsIPaymentItem
> total
;
154 PaymentItem::Create(aIPCModifier
.total(), getter_AddRefs(total
));
155 if (NS_WARN_IF(NS_FAILED(rv
))) {
159 nsCOMPtr
<nsIArray
> displayItems
;
160 if (aIPCModifier
.additionalDisplayItemsPassed()) {
161 nsCOMPtr
<nsIMutableArray
> items
= do_CreateInstance(NS_ARRAY_CONTRACTID
);
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
))) {
169 rv
= items
->AppendElement(additionalItem
);
170 if (NS_WARN_IF(NS_FAILED(rv
))) {
174 displayItems
= std::move(items
);
176 nsCOMPtr
<nsIPaymentDetailsModifier
> modifier
=
177 new PaymentDetailsModifier(aIPCModifier
.supportedMethods(), total
,
178 displayItems
, aIPCModifier
.data());
179 modifier
.forget(aModifier
);
184 PaymentDetailsModifier::GetSupportedMethods(nsAString
& aSupportedMethods
) {
185 aSupportedMethods
= mSupportedMethods
;
190 PaymentDetailsModifier::GetTotal(nsIPaymentItem
** aTotal
) {
191 NS_ENSURE_ARG_POINTER(aTotal
);
193 nsCOMPtr
<nsIPaymentItem
> total
= mTotal
;
194 total
.forget(aTotal
);
199 PaymentDetailsModifier::GetAdditionalDisplayItems(
200 nsIArray
** aAdditionalDisplayItems
) {
201 NS_ENSURE_ARG_POINTER(aAdditionalDisplayItems
);
202 nsCOMPtr
<nsIArray
> additionalItems
= mAdditionalDisplayItems
;
203 additionalItems
.forget(aAdditionalDisplayItems
);
208 PaymentDetailsModifier::GetData(JSContext
* aCx
, JS::MutableHandleValue aData
) {
209 if (mData
.IsEmpty()) {
210 aData
.set(JS::NullValue());
213 nsresult rv
= DeserializeToJSValue(mData
, aCx
, aData
);
214 if (NS_WARN_IF(NS_FAILED(rv
))) {
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
))) {
240 nsCOMPtr
<nsIPaymentShippingOption
> option
= new PaymentShippingOption(
241 aIPCOption
.id(), aIPCOption
.label(), amount
, aIPCOption
.selected());
242 option
.forget(aOption
);
247 PaymentShippingOption::GetId(nsAString
& aId
) {
253 PaymentShippingOption::GetLabel(nsAString
& aLabel
) {
259 PaymentShippingOption::GetAmount(nsIPaymentCurrencyAmount
** aAmount
) {
260 NS_ENSURE_ARG_POINTER(aAmount
);
262 nsCOMPtr
<nsIPaymentCurrencyAmount
> amount
= mAmount
;
263 amount
.forget(aAmount
);
268 PaymentShippingOption::GetSelected(bool* aSelected
) {
269 NS_ENSURE_ARG_POINTER(aSelected
);
270 *aSelected
= mSelected
;
275 PaymentShippingOption::SetSelected(bool aSelected
) {
276 mSelected
= aSelected
;
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
)
292 mTotalItem(aTotalItem
),
293 mDisplayItems(aDisplayItems
),
294 mShippingOptions(aShippingOptions
),
295 mModifiers(aModifiers
),
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
))) {
311 nsCOMPtr
<nsIArray
> displayItems
;
312 nsCOMPtr
<nsIMutableArray
> items
= do_CreateInstance(NS_ARRAY_CONTRACTID
);
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
))) {
320 rv
= items
->AppendElement(item
);
321 if (NS_WARN_IF(NS_FAILED(rv
))) {
325 displayItems
= std::move(items
);
327 nsCOMPtr
<nsIArray
> shippingOptions
;
328 nsCOMPtr
<nsIMutableArray
> options
= do_CreateInstance(NS_ARRAY_CONTRACTID
);
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
))) {
337 rv
= options
->AppendElement(option
);
338 if (NS_WARN_IF(NS_FAILED(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
))) {
355 rv
= detailsModifiers
->AppendElement(detailsModifier
);
356 if (NS_WARN_IF(NS_FAILED(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
);
372 PaymentDetails::GetId(nsAString
& aId
) {
378 PaymentDetails::GetTotalItem(nsIPaymentItem
** aTotalItem
) {
379 NS_ENSURE_ARG_POINTER(aTotalItem
);
380 MOZ_ASSERT(mTotalItem
);
381 nsCOMPtr
<nsIPaymentItem
> total
= mTotalItem
;
382 total
.forget(aTotalItem
);
387 PaymentDetails::GetDisplayItems(nsIArray
** aDisplayItems
) {
388 NS_ENSURE_ARG_POINTER(aDisplayItems
);
389 nsCOMPtr
<nsIArray
> displayItems
= mDisplayItems
;
390 displayItems
.forget(aDisplayItems
);
395 PaymentDetails::GetShippingOptions(nsIArray
** aShippingOptions
) {
396 NS_ENSURE_ARG_POINTER(aShippingOptions
);
397 nsCOMPtr
<nsIArray
> options
= mShippingOptions
;
398 options
.forget(aShippingOptions
);
403 PaymentDetails::GetModifiers(nsIArray
** aModifiers
) {
404 NS_ENSURE_ARG_POINTER(aModifiers
);
405 nsCOMPtr
<nsIArray
> modifiers
= mModifiers
;
406 modifiers
.forget(aModifiers
);
411 PaymentDetails::GetError(nsAString
& aError
) {
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
;
428 PaymentDetails::GetPayerErrors(JSContext
* aCx
, JS::MutableHandleValue aErrors
) {
430 errors
.Init(mPayerErrors
);
431 if (!ToJSValue(aCx
, errors
, aErrors
)) {
432 return NS_ERROR_FAILURE
;
438 PaymentDetails::GetPaymentMethodErrors(JSContext
* aCx
,
439 JS::MutableHandleValue aErrors
) {
440 if (mPaymentMethodErrors
.IsEmpty()) {
441 aErrors
.set(JS::NullValue());
444 nsresult rv
= DeserializeToJSValue(mPaymentMethodErrors
, aCx
, aErrors
);
445 if (NS_WARN_IF(NS_FAILED(rv
))) {
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
))) {
468 nsCOMPtr
<nsIArray
> displayItems
;
469 rv
= aDetails
->GetDisplayItems(getter_AddRefs(displayItems
));
470 if (NS_WARN_IF(NS_FAILED(rv
))) {
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
))) {
483 mShippingOptions
= shippingOptions
;
486 nsCOMPtr
<nsIArray
> modifiers
;
487 rv
= aDetails
->GetModifiers(getter_AddRefs(modifiers
));
488 if (NS_WARN_IF(NS_FAILED(rv
))) {
492 mModifiers
= modifiers
;
495 rv
= aDetails
->GetError(mError
);
496 if (NS_WARN_IF(NS_FAILED(rv
))) {
500 PaymentDetails
* rowDetails
= static_cast<PaymentDetails
*>(aDetails
);
501 MOZ_ASSERT(rowDetails
);
502 mShippingAddressErrors
= rowDetails
->GetShippingAddressErrors();
503 mPayerErrors
= rowDetails
->GetPayerErrors();
504 mPaymentMethodErrors
= rowDetails
->GetPaymentMethodErrors();
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
) {
524 mPayerErrors
= aPayerErrors
;
525 mPaymentMethodErrors
= aPaymentMethodErrors
;
526 mShippingAddressErrors
= aShippingAddressErrors
;
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
);
560 PaymentOptions::GetRequestPayerName(bool* aRequestPayerName
) {
561 NS_ENSURE_ARG_POINTER(aRequestPayerName
);
562 *aRequestPayerName
= mRequestPayerName
;
567 PaymentOptions::GetRequestPayerEmail(bool* aRequestPayerEmail
) {
568 NS_ENSURE_ARG_POINTER(aRequestPayerEmail
);
569 *aRequestPayerEmail
= mRequestPayerEmail
;
574 PaymentOptions::GetRequestPayerPhone(bool* aRequestPayerPhone
) {
575 NS_ENSURE_ARG_POINTER(aRequestPayerPhone
);
576 *aRequestPayerPhone
= mRequestPayerPhone
;
581 PaymentOptions::GetRequestShipping(bool* aRequestShipping
) {
582 NS_ENSURE_ARG_POINTER(aRequestShipping
);
583 *aRequestShipping
= mRequestShipping
;
588 PaymentOptions::GetRequestBillingAddress(bool* aRequestBillingAddress
) {
589 NS_ENSURE_ARG_POINTER(aRequestBillingAddress
);
590 *aRequestBillingAddress
= mRequestBillingAddress
;
595 PaymentOptions::GetShippingType(nsAString
& aShippingType
) {
596 aShippingType
= mShippingType
;
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
),
621 PaymentRequest::GetTopOuterWindowId(uint64_t* aTopOuterWindowId
) {
622 NS_ENSURE_ARG_POINTER(aTopOuterWindowId
);
623 *aTopOuterWindowId
= mTopOuterWindowId
;
628 PaymentRequest::GetTopLevelPrincipal(nsIPrincipal
** aTopLevelPrincipal
) {
629 NS_ENSURE_ARG_POINTER(aTopLevelPrincipal
);
630 MOZ_ASSERT(mTopLevelPrincipal
);
631 nsCOMPtr
<nsIPrincipal
> principal
= mTopLevelPrincipal
;
632 principal
.forget(aTopLevelPrincipal
);
637 PaymentRequest::GetRequestId(nsAString
& aRequestId
) {
638 aRequestId
= mRequestId
;
643 PaymentRequest::GetPaymentMethods(nsIArray
** aPaymentMethods
) {
644 NS_ENSURE_ARG_POINTER(aPaymentMethods
);
645 MOZ_ASSERT(mPaymentMethods
);
646 nsCOMPtr
<nsIArray
> methods
= mPaymentMethods
;
647 methods
.forget(aPaymentMethods
);
652 PaymentRequest::GetPaymentDetails(nsIPaymentDetails
** aPaymentDetails
) {
653 NS_ENSURE_ARG_POINTER(aPaymentDetails
);
654 MOZ_ASSERT(mPaymentDetails
);
655 nsCOMPtr
<nsIPaymentDetails
> details
= mPaymentDetails
;
656 details
.forget(aPaymentDetails
);
661 PaymentRequest::GetPaymentOptions(nsIPaymentOptions
** aPaymentOptions
) {
662 NS_ENSURE_ARG_POINTER(aPaymentOptions
);
663 MOZ_ASSERT(mPaymentOptions
);
664 nsCOMPtr
<nsIPaymentOptions
> options
= mPaymentOptions
;
665 options
.forget(aPaymentOptions
);
670 PaymentRequest::GetShippingOption(nsAString
& aShippingOption
) {
671 aShippingOption
= mShippingOption
;
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
))) {
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
);
707 PaymentRequest::GetCompleteStatus(nsAString
& aCompleteStatus
) {
708 aCompleteStatus
= mCompleteStatus
;
714 NS_IMPL_ISUPPORTS(PaymentAddress
, nsIPaymentAddress
)
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
) {
726 mAddressLine
= aAddressLine
;
728 mRegionCode
= aRegionCode
;
730 mDependentLocality
= aDependentLocality
;
731 mPostalCode
= aPostalCode
;
732 mSortingCode
= aSortingCode
;
733 mOrganization
= aOrganization
;
734 mRecipient
= aRecipient
;
740 PaymentAddress::GetCountry(nsAString
& aCountry
) {
746 PaymentAddress::GetAddressLine(nsIArray
** aAddressLine
) {
747 NS_ENSURE_ARG_POINTER(aAddressLine
);
748 nsCOMPtr
<nsIArray
> addressLine
= mAddressLine
;
749 addressLine
.forget(aAddressLine
);
754 PaymentAddress::GetRegion(nsAString
& aRegion
) {
760 PaymentAddress::GetRegionCode(nsAString
& aRegionCode
) {
761 aRegionCode
= mRegionCode
;
766 PaymentAddress::GetCity(nsAString
& aCity
) {
772 PaymentAddress::GetDependentLocality(nsAString
& aDependentLocality
) {
773 aDependentLocality
= mDependentLocality
;
778 PaymentAddress::GetPostalCode(nsAString
& aPostalCode
) {
779 aPostalCode
= mPostalCode
;
784 PaymentAddress::GetSortingCode(nsAString
& aSortingCode
) {
785 aSortingCode
= mSortingCode
;
790 PaymentAddress::GetOrganization(nsAString
& aOrganization
) {
791 aOrganization
= mOrganization
;
796 PaymentAddress::GetRecipient(nsAString
& aRecipient
) {
797 aRecipient
= mRecipient
;
802 PaymentAddress::GetPhone(nsAString
& aPhone
) {
807 } // namespace mozilla::dom::payments