From 66a1567f229de6b28791e3abf68b78e562dae4a2 Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Wed, 21 Feb 2018 14:16:35 -0800 Subject: [PATCH] Bug 1429189 - Show shipping address errors on the summary screen. r=mattn MozReview-Commit-ID: LaXrvWliWna --HG-- extra : rebase_source : 6b0639a39a92192dc0c4cbc9392d97e16717adfc --- .../payments/content/paymentDialogWrapper.js | 16 ++++ .../components/payments/paymentUIService.js | 22 ++++- .../payments/res/containers/payment-dialog.js | 5 +- .../payments/res/paymentRequest.xhtml | 1 + .../payments/test/PaymentTestUtils.jsm | 67 ++++++++++++- .../payments/test/browser/browser.ini | 1 + .../browser_shippingaddresschange_error.js | 93 +++++++++++++++++++ .../test/browser/browser_show_dialog.js | 2 +- .../components/payments/test/browser/head.js | 17 ++++ 9 files changed, 217 insertions(+), 7 deletions(-) create mode 100644 toolkit/components/payments/test/browser/browser_shippingaddresschange_error.js diff --git a/toolkit/components/payments/content/paymentDialogWrapper.js b/toolkit/components/payments/content/paymentDialogWrapper.js index c007ac83cc14..97ffb7793cb9 100644 --- a/toolkit/components/payments/content/paymentDialogWrapper.js +++ b/toolkit/components/payments/content/paymentDialogWrapper.js @@ -108,6 +108,9 @@ var paymentDialogWrapper = { if (!requestId || typeof(requestId) != "string") { throw new Error("Invalid PaymentRequest ID"); } + + // The Request object returned by the Payment Service is live and + // will automatically get updated if event.updateWith is used. this.request = paymentSrv.getPaymentRequestById(requestId); if (!this.request) { @@ -250,6 +253,19 @@ var paymentDialogWrapper = { }); }, + updateRequest() { + // There is no need to update this.request since the object is live + // and will automatically get updated if event.updateWith is used. + let requestSerialized = this._serializeRequest(this.request); + + this.mm.sendAsyncMessage("paymentChromeToContent", { + messageType: "updateState", + data: { + request: requestSerialized, + }, + }); + }, + /** * Recursively convert and filter input to the subset of data types supported by JSON * diff --git a/toolkit/components/payments/paymentUIService.js b/toolkit/components/payments/paymentUIService.js index ae64cbc92589..e9d57d1f99cb 100644 --- a/toolkit/components/payments/paymentUIService.js +++ b/toolkit/components/payments/paymentUIService.js @@ -80,7 +80,13 @@ PaymentUIService.prototype = { }, updatePayment(requestId) { + let dialog = this.findDialog(requestId); this.log.debug("updatePayment:", requestId); + if (!dialog) { + this.log.error("updatePayment: no dialog found"); + return; + } + dialog.paymentDialogWrapper.updateRequest(); }, // other helper methods @@ -90,17 +96,25 @@ PaymentUIService.prototype = { * @returns {boolean} whether the specified dialog was closed. */ closeDialog(requestId) { + let win = this.findDialog(requestId); + if (!win) { + return false; + } + this.log.debug(`closing: ${win.name}`); + win.close(); + return true; + }, + + findDialog(requestId) { let enu = Services.wm.getEnumerator(null); let win; while ((win = enu.getNext())) { if (win.name == `${this.REQUEST_ID_PREFIX}${requestId}`) { - this.log.debug(`closing: ${win.name}`); - win.close(); - return true; + return win; } } - return false; + return null; }, requestIdForWindow(window) { diff --git a/toolkit/components/payments/res/containers/payment-dialog.js b/toolkit/components/payments/res/containers/payment-dialog.js index 5caf5f3005be..2f82ac513ce2 100644 --- a/toolkit/components/payments/res/containers/payment-dialog.js +++ b/toolkit/components/payments/res/containers/payment-dialog.js @@ -32,6 +32,7 @@ class PaymentDialog extends PaymentStateSubscriberMixin(HTMLElement) { this._orderDetailsOverlay = contents.querySelector("#order-details-overlay"); this._shippingRequestedEls = contents.querySelectorAll(".shippingRequested"); + this._errorText = contents.querySelector("#error-text"); this._disabledOverlay = contents.getElementById("disabled-overlay"); @@ -178,14 +179,16 @@ class PaymentDialog extends PaymentStateSubscriberMixin(HTMLElement) { render(state) { let request = state.request; + let paymentDetails = request.paymentDetails; this._hostNameEl.textContent = request.topLevelPrincipal.URI.displayHost; - let totalItem = request.paymentDetails.totalItem; + let totalItem = paymentDetails.totalItem; let totalAmountEl = this.querySelector("#total > currency-amount"); totalAmountEl.value = totalItem.amount.value; totalAmountEl.currency = totalItem.amount.currency; this._orderDetailsOverlay.hidden = !state.orderDetailsShowing; + this._errorText.textContent = paymentDetails.error; for (let element of this._shippingRequestedEls) { element.hidden = !request.paymentOptions.requestShipping; } diff --git a/toolkit/components/payments/res/paymentRequest.xhtml b/toolkit/components/payments/res/paymentRequest.xhtml index bf2c3fc67e23..07e727384b4d 100644 --- a/toolkit/components/payments/res/paymentRequest.xhtml +++ b/toolkit/components/payments/res/paymentRequest.xhtml @@ -71,6 +71,7 @@
+