Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
6 :
7 : #include "mozilla/dom/PaymentRequest.h"
8 : #include "mozilla/dom/PaymentResponse.h"
9 : #include "nsContentUtils.h"
10 : #include "PaymentRequestManager.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 : NS_IMPL_CYCLE_COLLECTION_CLASS(PaymentRequest)
16 :
17 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PaymentRequest,
18 : DOMEventTargetHelper)
19 : // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
20 : // DOMEventTargetHelper does it for us.
21 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_END
22 :
23 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PaymentRequest,
24 : DOMEventTargetHelper)
25 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResultPromise)
26 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAcceptPromise)
27 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAbortPromise)
28 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResponse)
29 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mShippingAddress)
30 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
31 :
32 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PaymentRequest,
33 : DOMEventTargetHelper)
34 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mResultPromise)
35 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mAcceptPromise)
36 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mAbortPromise)
37 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mResponse)
38 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mShippingAddress)
39 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
40 :
41 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PaymentRequest)
42 0 : NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
43 :
44 0 : NS_IMPL_ADDREF_INHERITED(PaymentRequest, DOMEventTargetHelper)
45 0 : NS_IMPL_RELEASE_INHERITED(PaymentRequest, DOMEventTargetHelper)
46 :
47 : bool
48 0 : PaymentRequest::PrefEnabled(JSContext* aCx, JSObject* aObj)
49 : {
50 0 : return Preferences::GetBool("dom.payments.request.enabled");
51 : }
52 :
53 : bool
54 0 : PaymentRequest::IsValidMethodData(const Sequence<PaymentMethodData>& aMethodData,
55 : nsAString& aErrorMsg)
56 : {
57 0 : if (!aMethodData.Length()) {
58 0 : aErrorMsg.AssignLiteral("At least one payment method is required.");
59 0 : return false;
60 : }
61 :
62 0 : for (const PaymentMethodData& methodData : aMethodData) {
63 0 : if (!methodData.mSupportedMethods.Length()) {
64 : aErrorMsg.AssignLiteral(
65 0 : "At least one payment method identifier is required.");
66 0 : return false;
67 : }
68 : }
69 :
70 0 : return true;
71 : }
72 :
73 : bool
74 0 : PaymentRequest::IsValidNumber(const nsAString& aItem,
75 : const nsAString& aStr,
76 : nsAString& aErrorMsg)
77 : {
78 0 : nsresult error = NS_ERROR_FAILURE;
79 :
80 0 : if (!aStr.IsEmpty()) {
81 0 : nsAutoString aValue(aStr);
82 :
83 : // If the beginning character is '-', we will check the second one.
84 0 : int beginningIndex = (aValue.First() == '-') ? 1 : 0;
85 :
86 : // Ensure
87 : // - the beginning character is a digit in [0-9], and
88 : // - the last character is not '.'
89 : // to follow spec:
90 : // https://w3c.github.io/browser-payment-api/#dfn-valid-decimal-monetary-value
91 : //
92 : // For example, ".1" is not valid for '.' is not in [0-9],
93 : // and " 0.1" either for beginning with ' '
94 0 : if (aValue.Last() != '.' &&
95 0 : aValue.CharAt(beginningIndex) >= '0' &&
96 0 : aValue.CharAt(beginningIndex) <= '9') {
97 0 : aValue.ToFloat(&error);
98 : }
99 : }
100 :
101 0 : if (NS_FAILED(error)) {
102 0 : aErrorMsg.AssignLiteral("The amount.value of \"");
103 0 : aErrorMsg.Append(aItem);
104 0 : aErrorMsg.AppendLiteral("\"(");
105 0 : aErrorMsg.Append(aStr);
106 0 : aErrorMsg.AppendLiteral(") must be a valid decimal monetary value.");
107 0 : return false;
108 : }
109 0 : return true;
110 : }
111 :
112 : bool
113 0 : PaymentRequest::IsNonNegativeNumber(const nsAString& aItem,
114 : const nsAString& aStr,
115 : nsAString& aErrorMsg)
116 : {
117 0 : nsresult error = NS_ERROR_FAILURE;
118 :
119 0 : if (!aStr.IsEmpty()) {
120 0 : nsAutoString aValue(aStr);
121 : // Ensure
122 : // - the beginning character is a digit in [0-9], and
123 : // - the last character is not '.'
124 0 : if (aValue.Last() != '.' &&
125 0 : aValue.First() >= '0' &&
126 0 : aValue.First() <= '9') {
127 0 : aValue.ToFloat(&error);
128 : }
129 : }
130 :
131 0 : if (NS_FAILED(error)) {
132 0 : aErrorMsg.AssignLiteral("The amount.value of \"");
133 0 : aErrorMsg.Append(aItem);
134 0 : aErrorMsg.AppendLiteral("\"(");
135 0 : aErrorMsg.Append(aStr);
136 0 : aErrorMsg.AppendLiteral(") must be a valid and non-negative decimal monetaryvalue.");
137 0 : return false;
138 : }
139 0 : return true;
140 : }
141 :
142 : bool
143 0 : PaymentRequest::IsValidDetailsInit(const PaymentDetailsInit& aDetails, nsAString& aErrorMsg)
144 : {
145 : // Check the amount.value of detail.total
146 0 : if (!IsNonNegativeNumber(NS_LITERAL_STRING("details.total"),
147 0 : aDetails.mTotal.mAmount.mValue, aErrorMsg)) {
148 0 : return false;
149 : }
150 :
151 0 : return IsValidDetailsBase(aDetails, aErrorMsg);
152 : }
153 :
154 : bool
155 0 : PaymentRequest::IsValidDetailsUpdate(const PaymentDetailsUpdate& aDetails)
156 : {
157 0 : nsAutoString message;
158 : // Check the amount.value of detail.total
159 0 : if (!IsNonNegativeNumber(NS_LITERAL_STRING("details.total"),
160 0 : aDetails.mTotal.mAmount.mValue, message)) {
161 0 : return false;
162 : }
163 :
164 0 : return IsValidDetailsBase(aDetails, message);
165 : }
166 :
167 : bool
168 0 : PaymentRequest::IsValidDetailsBase(const PaymentDetailsBase& aDetails, nsAString& aErrorMsg)
169 : {
170 : // Check the amount.value of each item in the display items
171 0 : if (aDetails.mDisplayItems.WasPassed()) {
172 0 : const Sequence<PaymentItem>& displayItems = aDetails.mDisplayItems.Value();
173 0 : for (const PaymentItem& displayItem : displayItems) {
174 0 : if (!IsValidNumber(displayItem.mLabel,
175 : displayItem.mAmount.mValue, aErrorMsg)) {
176 0 : return false;
177 : }
178 : }
179 : }
180 :
181 : // Check the shipping option
182 0 : if (aDetails.mShippingOptions.WasPassed()) {
183 0 : const Sequence<PaymentShippingOption>& shippingOptions = aDetails.mShippingOptions.Value();
184 0 : for (const PaymentShippingOption& shippingOption : shippingOptions) {
185 0 : if (!IsValidNumber(NS_LITERAL_STRING("details.shippingOptions"),
186 0 : shippingOption.mAmount.mValue, aErrorMsg)) {
187 0 : return false;
188 : }
189 : }
190 : }
191 :
192 : // Check payment details modifiers
193 0 : if (aDetails.mModifiers.WasPassed()) {
194 0 : const Sequence<PaymentDetailsModifier>& modifiers = aDetails.mModifiers.Value();
195 0 : for (const PaymentDetailsModifier& modifier : modifiers) {
196 0 : if (!IsNonNegativeNumber(NS_LITERAL_STRING("details.modifiers.total"),
197 0 : modifier.mTotal.mAmount.mValue, aErrorMsg)) {
198 0 : return false;
199 : }
200 0 : if (modifier.mAdditionalDisplayItems.WasPassed()) {
201 0 : const Sequence<PaymentItem>& displayItems = modifier.mAdditionalDisplayItems.Value();
202 0 : for (const PaymentItem& displayItem : displayItems) {
203 0 : if (!IsValidNumber(displayItem.mLabel,
204 : displayItem.mAmount.mValue, aErrorMsg)) {
205 0 : return false;
206 : }
207 : }
208 : }
209 : }
210 : }
211 :
212 0 : return true;
213 : }
214 :
215 : already_AddRefed<PaymentRequest>
216 0 : PaymentRequest::Constructor(const GlobalObject& aGlobal,
217 : const Sequence<PaymentMethodData>& aMethodData,
218 : const PaymentDetailsInit& aDetails,
219 : const PaymentOptions& aOptions,
220 : ErrorResult& aRv)
221 : {
222 0 : nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
223 0 : if (!window) {
224 0 : aRv.Throw(NS_ERROR_UNEXPECTED);
225 0 : return nullptr;
226 : }
227 :
228 : // [TODO] Bug 1318988 - Implement `allowPaymentRequest` on iframe
229 :
230 : // Check payment methods and details
231 0 : nsAutoString message;
232 0 : if (!IsValidMethodData(aMethodData, message) ||
233 0 : !IsValidDetailsInit(aDetails, message)) {
234 0 : aRv.ThrowTypeError<MSG_ILLEGAL_PR_CONSTRUCTOR>(message);
235 0 : return nullptr;
236 : }
237 :
238 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
239 0 : if (NS_WARN_IF(!manager)) {
240 0 : return nullptr;
241 : }
242 :
243 : // Create PaymentRequest and set its |mId|
244 0 : RefPtr<PaymentRequest> request;
245 0 : nsresult rv = manager->CreatePayment(window, aMethodData, aDetails,
246 0 : aOptions, getter_AddRefs(request));
247 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
248 0 : aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
249 0 : return nullptr;
250 : }
251 :
252 0 : return request.forget();
253 : }
254 :
255 : already_AddRefed<PaymentRequest>
256 0 : PaymentRequest::CreatePaymentRequest(nsPIDOMWindowInner* aWindow, nsresult& aRv)
257 : {
258 : // Generate a unique id for identification
259 : nsID uuid;
260 0 : aRv = nsContentUtils::GenerateUUIDInPlace(uuid);
261 0 : if (NS_WARN_IF(NS_FAILED(aRv))) {
262 0 : return nullptr;
263 : }
264 :
265 : // Build a string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format
266 : char buffer[NSID_LENGTH];
267 0 : uuid.ToProvidedString(buffer);
268 :
269 : // Remove {} and the null terminator
270 0 : nsAutoString id;
271 0 : id.AssignASCII(&buffer[1], NSID_LENGTH - 3);
272 :
273 : // Create payment request with generated id
274 0 : RefPtr<PaymentRequest> request = new PaymentRequest(aWindow, id);
275 0 : return request.forget();
276 : }
277 :
278 0 : PaymentRequest::PaymentRequest(nsPIDOMWindowInner* aWindow, const nsAString& aInternalId)
279 : : DOMEventTargetHelper(aWindow)
280 : , mInternalId(aInternalId)
281 : , mShippingAddress(nullptr)
282 : , mUpdating(false)
283 : , mUpdateError(NS_OK)
284 0 : , mState(eCreated)
285 : {
286 0 : MOZ_ASSERT(aWindow);
287 0 : }
288 :
289 : already_AddRefed<Promise>
290 0 : PaymentRequest::CanMakePayment(ErrorResult& aRv)
291 : {
292 0 : if (mState != eCreated) {
293 0 : aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
294 0 : return nullptr;
295 : }
296 :
297 0 : if (mResultPromise) {
298 0 : aRv.Throw(NS_ERROR_DOM_NOT_ALLOWED_ERR);
299 0 : return nullptr;
300 : }
301 :
302 0 : nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
303 0 : ErrorResult result;
304 0 : RefPtr<Promise> promise = Promise::Create(global, result);
305 0 : if (result.Failed()) {
306 0 : aRv.Throw(NS_ERROR_FAILURE);
307 0 : return nullptr;
308 : }
309 :
310 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
311 0 : if (NS_WARN_IF(!manager)) {
312 0 : aRv.Throw(NS_ERROR_FAILURE);
313 0 : return nullptr;
314 : }
315 0 : nsresult rv = manager->CanMakePayment(mInternalId);
316 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
317 0 : promise->MaybeReject(NS_ERROR_FAILURE);
318 0 : return promise.forget();
319 : }
320 0 : mResultPromise = promise;
321 0 : return promise.forget();
322 : }
323 :
324 : void
325 0 : PaymentRequest::RespondCanMakePayment(bool aResult)
326 : {
327 0 : MOZ_ASSERT(mResultPromise);
328 0 : mResultPromise->MaybeResolve(aResult);
329 0 : mResultPromise = nullptr;
330 0 : }
331 :
332 : already_AddRefed<Promise>
333 0 : PaymentRequest::Show(ErrorResult& aRv)
334 : {
335 0 : if (mState != eCreated) {
336 0 : aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
337 0 : return nullptr;
338 : }
339 :
340 0 : nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
341 0 : ErrorResult result;
342 0 : RefPtr<Promise> promise = Promise::Create(global, result);
343 0 : if (result.Failed()) {
344 0 : mState = eClosed;
345 0 : aRv.Throw(NS_ERROR_FAILURE);
346 0 : return nullptr;
347 : }
348 :
349 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
350 0 : if (NS_WARN_IF(!manager)) {
351 0 : mState = eClosed;
352 0 : aRv.Throw(NS_ERROR_FAILURE);
353 0 : return nullptr;
354 : }
355 0 : nsresult rv = manager->ShowPayment(mInternalId);
356 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
357 0 : promise->MaybeReject(NS_ERROR_FAILURE);
358 0 : mState = eClosed;
359 0 : return promise.forget();
360 : }
361 :
362 0 : mAcceptPromise = promise;
363 0 : mState = eInteractive;
364 0 : return promise.forget();
365 : }
366 :
367 : void
368 0 : PaymentRequest::RejectShowPayment(nsresult aRejectReason)
369 : {
370 0 : MOZ_ASSERT(mAcceptPromise);
371 0 : MOZ_ASSERT(ReadyForUpdate());
372 :
373 0 : mAcceptPromise->MaybeReject(aRejectReason);
374 0 : mState = eClosed;
375 0 : mAcceptPromise = nullptr;
376 0 : }
377 :
378 : void
379 0 : PaymentRequest::RespondShowPayment(bool aAccept,
380 : const nsAString& aMethodName,
381 : const nsAString& aDetails,
382 : const nsAString& aPayerName,
383 : const nsAString& aPayerEmail,
384 : const nsAString& aPayerPhone,
385 : nsresult aRv)
386 : {
387 0 : MOZ_ASSERT(mAcceptPromise);
388 0 : MOZ_ASSERT(ReadyForUpdate());
389 0 : MOZ_ASSERT(mState == eInteractive);
390 :
391 0 : if (!aAccept) {
392 0 : RejectShowPayment(aRv);
393 0 : return;
394 : }
395 :
396 : RefPtr<PaymentResponse> paymentResponse =
397 0 : new PaymentResponse(GetOwner(), mInternalId, mId, aMethodName,
398 : mShippingOption, mShippingAddress, aDetails,
399 0 : aPayerName, aPayerEmail, aPayerPhone);
400 0 : mResponse = paymentResponse;
401 0 : mAcceptPromise->MaybeResolve(paymentResponse);
402 :
403 0 : mState = eClosed;
404 0 : mAcceptPromise = nullptr;
405 : }
406 :
407 : void
408 0 : PaymentRequest::RespondComplete()
409 : {
410 0 : MOZ_ASSERT(mResponse);
411 0 : mResponse->RespondComplete();
412 0 : }
413 :
414 : already_AddRefed<Promise>
415 0 : PaymentRequest::Abort(ErrorResult& aRv)
416 : {
417 0 : if (mState != eInteractive) {
418 0 : aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
419 0 : return nullptr;
420 : }
421 :
422 0 : if (mAbortPromise) {
423 0 : aRv.Throw(NS_ERROR_DOM_NOT_ALLOWED_ERR);
424 0 : return nullptr;
425 : }
426 :
427 0 : nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
428 0 : ErrorResult result;
429 0 : RefPtr<Promise> promise = Promise::Create(global, result);
430 0 : if (result.Failed()) {
431 0 : aRv.Throw(NS_ERROR_FAILURE);
432 0 : return nullptr;
433 : }
434 :
435 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
436 0 : if (NS_WARN_IF(!manager)) {
437 0 : aRv.Throw(NS_ERROR_FAILURE);
438 0 : return nullptr;
439 : }
440 0 : nsresult rv = manager->AbortPayment(mInternalId);
441 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
442 0 : aRv.Throw(NS_ERROR_FAILURE);
443 0 : return nullptr;
444 : }
445 :
446 0 : mAbortPromise = promise;
447 0 : return promise.forget();
448 : }
449 :
450 : void
451 0 : PaymentRequest::RespondAbortPayment(bool aSuccess)
452 : {
453 : // Check whether we are aborting the update:
454 : //
455 : // - If |mUpdateError| is not NS_OK, we are aborting the update as
456 : // |mUpdateError| was set in method |AbortUpdate|.
457 : // => Reject |mAcceptPromise| and reset |mUpdateError| to complete
458 : // the action, regardless of |aSuccess|.
459 : //
460 : // - Otherwise, we are handling |Abort| method call from merchant.
461 : // => Resolve/Reject |mAbortPromise| based on |aSuccess|.
462 0 : if (NS_FAILED(mUpdateError)) {
463 0 : RespondShowPayment(false, EmptyString(), EmptyString(), EmptyString(),
464 0 : EmptyString(), EmptyString(), mUpdateError);
465 0 : mUpdateError = NS_OK;
466 0 : return;
467 : }
468 :
469 0 : MOZ_ASSERT(mAbortPromise);
470 0 : MOZ_ASSERT(mState == eInteractive);
471 :
472 0 : if (aSuccess) {
473 0 : mAbortPromise->MaybeResolve(JS::UndefinedHandleValue);
474 0 : mAbortPromise = nullptr;
475 0 : RejectShowPayment(NS_ERROR_DOM_ABORT_ERR);
476 : } else {
477 0 : mAbortPromise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
478 0 : mAbortPromise = nullptr;
479 : }
480 : }
481 :
482 : nsresult
483 0 : PaymentRequest::UpdatePayment(const PaymentDetailsUpdate& aDetails)
484 : {
485 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
486 0 : if (NS_WARN_IF(!manager)) {
487 0 : return NS_ERROR_FAILURE;
488 : }
489 0 : nsresult rv = manager->UpdatePayment(mInternalId, aDetails);
490 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
491 0 : return rv;
492 : }
493 0 : return NS_OK;
494 : }
495 :
496 : void
497 0 : PaymentRequest::AbortUpdate(nsresult aRv)
498 : {
499 0 : MOZ_ASSERT(NS_FAILED(aRv));
500 :
501 : // Close down any remaining user interface.
502 0 : RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
503 0 : MOZ_ASSERT(manager);
504 0 : nsresult rv = manager->AbortPayment(mInternalId);
505 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
506 0 : return;
507 : }
508 :
509 : // Remember update error |aRv| and do the following steps in RespondShowPayment.
510 : // 1. Set target.state to closed
511 : // 2. Reject the promise target.acceptPromise with exception "aRv"
512 : // 3. Abort the algorithm with update error
513 0 : mUpdateError = aRv;
514 : }
515 :
516 : void
517 0 : PaymentRequest::GetId(nsAString& aRetVal) const
518 : {
519 0 : aRetVal = mId;
520 0 : }
521 :
522 : void
523 0 : PaymentRequest::GetInternalId(nsAString& aRetVal)
524 : {
525 0 : aRetVal = mInternalId;
526 0 : }
527 :
528 : void
529 0 : PaymentRequest::SetId(const nsAString& aId)
530 : {
531 0 : mId = aId;
532 0 : }
533 :
534 : bool
535 0 : PaymentRequest::Equals(const nsAString& aInternalId) const
536 : {
537 0 : return mInternalId.Equals(aInternalId);
538 : }
539 :
540 : bool
541 0 : PaymentRequest::ReadyForUpdate()
542 : {
543 0 : return mState == eInteractive && !mUpdating;
544 : }
545 :
546 : void
547 0 : PaymentRequest::SetUpdating(bool aUpdating)
548 : {
549 0 : mUpdating = aUpdating;
550 0 : }
551 :
552 : nsresult
553 0 : PaymentRequest::DispatchUpdateEvent(const nsAString& aType)
554 : {
555 0 : MOZ_ASSERT(ReadyForUpdate());
556 :
557 0 : PaymentRequestUpdateEventInit init;
558 0 : init.mBubbles = false;
559 0 : init.mCancelable = false;
560 :
561 : RefPtr<PaymentRequestUpdateEvent> event =
562 0 : PaymentRequestUpdateEvent::Constructor(this, aType, init);
563 0 : event->SetTrusted(true);
564 :
565 0 : return DispatchDOMEvent(nullptr, event, nullptr, nullptr);
566 : }
567 :
568 : already_AddRefed<PaymentAddress>
569 0 : PaymentRequest::GetShippingAddress() const
570 : {
571 0 : RefPtr<PaymentAddress> address = mShippingAddress;
572 0 : return address.forget();
573 : }
574 :
575 : nsresult
576 0 : PaymentRequest::UpdateShippingAddress(const nsAString& aCountry,
577 : const nsTArray<nsString>& aAddressLine,
578 : const nsAString& aRegion,
579 : const nsAString& aCity,
580 : const nsAString& aDependentLocality,
581 : const nsAString& aPostalCode,
582 : const nsAString& aSortingCode,
583 : const nsAString& aLanguageCode,
584 : const nsAString& aOrganization,
585 : const nsAString& aRecipient,
586 : const nsAString& aPhone)
587 : {
588 0 : mShippingAddress = new PaymentAddress(GetOwner(), aCountry, aAddressLine,
589 : aRegion, aCity, aDependentLocality,
590 : aPostalCode, aSortingCode, aLanguageCode,
591 0 : aOrganization, aRecipient, aPhone);
592 :
593 : // Fire shippingaddresschange event
594 0 : return DispatchUpdateEvent(NS_LITERAL_STRING("shippingaddresschange"));
595 : }
596 :
597 : void
598 0 : PaymentRequest::SetShippingOption(const nsAString& aShippingOption)
599 : {
600 0 : mShippingOption = aShippingOption;
601 0 : }
602 :
603 : void
604 0 : PaymentRequest::GetShippingOption(nsAString& aRetVal) const
605 : {
606 0 : aRetVal = mShippingOption;
607 0 : }
608 :
609 : nsresult
610 0 : PaymentRequest::UpdateShippingOption(const nsAString& aShippingOption)
611 : {
612 0 : mShippingOption = aShippingOption;
613 :
614 : // Fire shippingaddresschange event
615 0 : return DispatchUpdateEvent(NS_LITERAL_STRING("shippingoptionchange"));
616 : }
617 :
618 : void
619 0 : PaymentRequest::SetShippingType(const Nullable<PaymentShippingType>& aShippingType)
620 : {
621 0 : mShippingType = aShippingType;
622 0 : }
623 :
624 : Nullable<PaymentShippingType>
625 0 : PaymentRequest::GetShippingType() const
626 : {
627 0 : return mShippingType;
628 : }
629 :
630 0 : PaymentRequest::~PaymentRequest()
631 : {
632 0 : }
633 :
634 : JSObject*
635 0 : PaymentRequest::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
636 : {
637 0 : return PaymentRequestBinding::Wrap(aCx, this, aGivenProto);
638 : }
639 :
640 : } // namespace dom
641 : } // namespace mozilla
|