Bug 1432952 - Send the basic-card's billing address with the response. r=jaws draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 10 Apr 2018 18:52:13 -0700
changeset 780844 e821039b7e60c2c1fe016519dccad827dc5240a5
parent 780843 97ae3457c11e3a593bb1abe163a32e7008a086b1
child 781528 8d37f6372e30cd5ab2863acb4c6cdb407847b25e
push id106139
push usermozilla@noorenberghe.ca
push dateThu, 12 Apr 2018 03:11:23 +0000
reviewersjaws
bugs1432952
milestone61.0a1
Bug 1432952 - Send the basic-card's billing address with the response. r=jaws MozReview-Commit-ID: 9tquQ0C7D91
toolkit/components/payments/content/paymentDialogWrapper.js
toolkit/components/payments/test/browser/browser_show_dialog.js
toolkit/components/payments/test/browser/head.js
--- a/toolkit/components/payments/content/paymentDialogWrapper.js
+++ b/toolkit/components/payments/content/paymentDialogWrapper.js
@@ -115,22 +115,31 @@ var paymentDialogWrapper = {
     } catch (ex) {
       if (ex.result != Cr.NS_ERROR_ABORT) {
         throw ex;
       }
       // User canceled master password entry
       return null;
     }
 
+    let billingAddressGUID = cardData.billingAddressGUID;
+    let billingAddress;
+    try {
+      billingAddress = await this._convertProfileAddressToPaymentAddress(billingAddressGUID);
+    } catch (ex) {
+      // The referenced address may not exist if it was deleted or hasn't yet synced to this profile
+      Cu.reportError(ex);
+    }
     let methodData = this.createBasicCardResponseData({
       cardholderName: cardData["cc-name"],
       cardNumber,
       expiryMonth: cardData["cc-exp-month"].toString().padStart(2, "0"),
       expiryYear: cardData["cc-exp-year"].toString(),
       cardSecurityCode,
+      billingAddress,
     });
 
     return methodData;
   },
 
   init(requestId, frame) {
     if (!requestId || typeof(requestId) != "string") {
       throw new Error("Invalid PaymentRequest ID");
--- a/toolkit/components/payments/test/browser/browser_show_dialog.js
+++ b/toolkit/components/payments/test/browser/browser_show_dialog.js
@@ -51,22 +51,23 @@ add_task(async function test_show_comple
     "street-address": "32 Vassar Street\nMIT Room 32-G524",
     "address-level2": "Cambridge",
     "address-level1": "MA",
     "postal-code": "02139",
     country: "US",
     tel: "+16172535702",
     email: "timbl@example.org",
   };
-  formAutofillStorage.addresses.add(address);
+  let addressGUID = await formAutofillStorage.addresses.add(address);
   await onChanged;
 
   onChanged = TestUtils.topicObserved("formautofill-storage-changed",
                                       (subject, data) => data == "add");
   let card = {
+    billingAddressGUID: addressGUID,
     "cc-exp-month": 1,
     "cc-exp-year": 9999,
     "cc-name": "John Doe",
     "cc-number": "999999999999",
   };
 
   formAutofillStorage.creditCards.add(card);
   await onChanged;
@@ -90,37 +91,27 @@ add_task(async function test_show_comple
     });
     info("clicking pay");
     spawnPaymentDialogTask(frame, PTU.DialogContentTasks.completePayment);
 
     // Add a handler to complete the payment above.
     info("acknowledging the completion from the merchant page");
     let result = await ContentTask.spawn(browser, {}, PTU.ContentTasks.addCompletionHandler);
 
-    let addressLines = address["street-address"].split("\n");
     let actualShippingAddress = result.response.shippingAddress;
-    is(actualShippingAddress.addressLine[0], addressLines[0], "Address line 1 should match");
-    is(actualShippingAddress.addressLine[1], addressLines[1], "Address line 2 should match");
-    is(actualShippingAddress.country, address.country, "Country should match");
-    is(actualShippingAddress.region, address["address-level1"], "Region should match");
-    is(actualShippingAddress.city, address["address-level2"], "City should match");
-    is(actualShippingAddress.postalCode, address["postal-code"], "Zip code should match");
-    is(actualShippingAddress.organization, address.organization, "Org should match");
-    is(actualShippingAddress.recipient,
-       `${address["given-name"]} ${address["additional-name"]} ${address["family-name"]}`,
-       "Recipient country should match");
-    is(actualShippingAddress.phone, address.tel, "Phone should match");
-
+    checkPaymentAddressMatchesStorageAddress(actualShippingAddress, address, "Shipping address");
     is(result.response.methodName, "basic-card", "Check methodName");
     let methodDetails = result.methodDetails;
     is(methodDetails.cardholderName, "John Doe", "Check cardholderName");
     is(methodDetails.cardNumber, "999999999999", "Check cardNumber");
     is(methodDetails.expiryMonth, "01", "Check expiryMonth");
     is(methodDetails.expiryYear, "9999", "Check expiryYear");
     is(methodDetails.cardSecurityCode, "999", "Check cardSecurityCode");
+    checkPaymentAddressMatchesStorageAddress(methodDetails.billingAddress, address,
+                                             "Billing address");
 
     is(result.response.shippingOption, "2", "Check shipping option");
 
     await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
   });
 });
 
 add_task(async function test_show_completePayment() {
--- a/toolkit/components/payments/test/browser/head.js
+++ b/toolkit/components/payments/test/browser/head.js
@@ -144,16 +144,39 @@ async function addSampleAddressesAndBasi
 
   onChanged = TestUtils.topicObserved("formautofill-storage-changed",
                                       (subject, data) => data == "add");
   formAutofillStorage.creditCards.add(PTU.BasicCards.JohnDoe);
   await onChanged;
 }
 
 /**
+ * Checks that an address from autofill storage matches a Payment Request PaymentAddress.
+ * @param {PaymentAddress} paymentAddress
+ * @param {object} storageAddress
+ * @param {string} msg to describe the check
+ */
+function checkPaymentAddressMatchesStorageAddress(paymentAddress, storageAddress, msg) {
+  info(msg);
+  let addressLines = storageAddress["street-address"].split("\n");
+  is(paymentAddress.addressLine[0], addressLines[0], "Address line 1 should match");
+  is(paymentAddress.addressLine[1], addressLines[1], "Address line 2 should match");
+  is(paymentAddress.country, storageAddress.country, "Country should match");
+  is(paymentAddress.region, storageAddress["address-level1"], "Region should match");
+  is(paymentAddress.city, storageAddress["address-level2"], "City should match");
+  is(paymentAddress.postalCode, storageAddress["postal-code"], "Zip code should match");
+  is(paymentAddress.organization, storageAddress.organization, "Org should match");
+  is(paymentAddress.recipient,
+     `${storageAddress["given-name"]} ${storageAddress["additional-name"]} ` +
+     `${storageAddress["family-name"]}`,
+     "Recipient name should match");
+  is(paymentAddress.phone, storageAddress.tel, "Phone should match");
+}
+
+/**
  * Create a PaymentRequest object with the given parameters, then
  * run the given merchantTaskFn.
  *
  * @param {Object} browser
  * @param {Object} options
  * @param {Object} options.methodData
  * @param {Object} options.details
  * @param {Object} options.options