Bug 1435161 - Part 3 support error fields in PaymentDetailsUpdate. r=baku
authorEden Chuang <echuang@mozilla.com>
Tue, 04 Sep 2018 16:00:33 +0200
changeset 435644 d3e7d6d6e0d565564575071bfae0abd63e046c77
parent 435643 e65bec7e01c82025e19af0f9c11a492788d816df
child 435645 bef9c20b995274f5989c979b8eae6cc091a568a5
push id34616
push usercsabou@mozilla.com
push dateTue, 11 Sep 2018 10:07:11 +0000
treeherdermozilla-central@423bdf7a802b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1435161
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435161 - Part 3 support error fields in PaymentDetailsUpdate. r=baku To support merchants providing the payment details with errors by PaymentRequestUpdateEvent.updateWith() during PaymentResponse.retry(), PaymentDetailsUpdate needs to add more two attributes in webidl. dictionary PaymentDetailsUpdate { ... PayerErrorFields payerErrors; object paymentMethodErrors; }; And transfer these error field to UI component
dom/payments/PaymentRequestData.cpp
dom/payments/PaymentRequestData.h
dom/payments/PaymentRequestManager.cpp
dom/payments/ipc/PPaymentRequest.ipdl
dom/webidl/PaymentRequest.webidl
--- a/dom/payments/PaymentRequestData.cpp
+++ b/dom/payments/PaymentRequestData.cpp
@@ -336,24 +336,28 @@ NS_IMPL_ISUPPORTS(PaymentDetails,
                   nsIPaymentDetails)
 
 PaymentDetails::PaymentDetails(const nsAString& aId,
                                nsIPaymentItem* aTotalItem,
                                nsIArray* aDisplayItems,
                                nsIArray* aShippingOptions,
                                nsIArray* aModifiers,
                                const nsAString& aError,
-                               const nsAString& aShippingAddressErrors)
+                               const nsAString& aShippingAddressErrors,
+                               const nsAString& aPayerErrors,
+                               const nsAString& aPaymentMethodErrors)
   : mId(aId)
   , mTotalItem(aTotalItem)
   , mDisplayItems(aDisplayItems)
   , mShippingOptions(aShippingOptions)
   , mModifiers(aModifiers)
   , mError(aError)
   , mShippingAddressErrors(aShippingAddressErrors)
+  , mPayerErrors(aPayerErrors)
+  , mPaymentMethodErrors(aPaymentMethodErrors)
 {
 }
 
 nsresult
 PaymentDetails::Create(const IPCPaymentDetails& aIPCDetails,
                        nsIPaymentDetails** aDetails)
 {
   NS_ENSURE_ARG_POINTER(aDetails);
@@ -410,17 +414,19 @@ PaymentDetails::Create(const IPCPaymentD
       return rv;
     }
   }
   modifiers = detailsModifiers.forget();
 
   nsCOMPtr<nsIPaymentDetails> details =
     new PaymentDetails(aIPCDetails.id(), total, displayItems, shippingOptions,
                        modifiers, aIPCDetails.error(),
-                       aIPCDetails.shippingAddressErrors());
+                       aIPCDetails.shippingAddressErrors(),
+                       aIPCDetails.payerErrors(),
+                       aIPCDetails.paymentMethodErrors());
 
   details.forget(aDetails);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PaymentDetails::GetId(nsAString& aId)
 {
@@ -556,27 +562,41 @@ PaymentDetails::Update(nsIPaymentDetails
   rv = aDetails->GetError(mError);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   PaymentDetails* rowDetails = static_cast<PaymentDetails*>(aDetails);
   MOZ_ASSERT(rowDetails);
   mShippingAddressErrors = rowDetails->GetShippingAddressErrors();
+  mPayerErrors = rowDetails->GetPayer();
+  mPaymentMethodErrors = rowDetails->GetPaymentMethod();
 
   return NS_OK;
 
 }
 
-nsString
+const nsString&
 PaymentDetails::GetShippingAddressErrors() const
 {
   return mShippingAddressErrors;
 }
 
+const nsString&
+PaymentDetails::GetPayer() const
+{
+  return mPayerErrors;
+}
+
+const nsString&
+PaymentDetails::GetPaymentMethod() const
+{
+  return mPaymentMethodErrors;
+}
+
 nsresult
 PaymentDetails::UpdateErrors(const nsAString& aError,
                              const nsAString& aPayerErrors,
                              const nsAString& aPaymentMethodErrors,
                              const nsAString& aShippingAddressErrors)
 {
   mError = aError;
   mPayerErrors = aPayerErrors;
--- a/dom/payments/PaymentRequestData.h
+++ b/dom/payments/PaymentRequestData.h
@@ -127,30 +127,34 @@ class PaymentDetails final : public nsIP
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPAYMENTDETAILS
 
 
   static nsresult Create(const IPCPaymentDetails& aIPCDetails,
                          nsIPaymentDetails** aDetails);
   nsresult Update(nsIPaymentDetails* aDetails, const bool aRequestShipping);
-  nsString GetShippingAddressErrors() const;
+  const nsString& GetShippingAddressErrors() const;
+  const nsString& GetPayer() const;
+  const nsString& GetPaymentMethod() const;
   nsresult UpdateErrors(const nsAString& aError,
                         const nsAString& aPayerErrors,
                         const nsAString& aPaymentMethodErrors,
                         const nsAString& aShippingAddressErrors);
 
 private:
   PaymentDetails(const nsAString& aId,
                  nsIPaymentItem* aTotalItem,
                  nsIArray* aDisplayItems,
                  nsIArray* aShippingOptions,
                  nsIArray* aModifiers,
                  const nsAString& aError,
-                 const nsAString& aShippingAddressError);
+                 const nsAString& aShippingAddressError,
+                 const nsAString& aPayerError,
+                 const nsAString& aPaymentMethodError);
 
   ~PaymentDetails() = default;
 
   nsString mId;
   nsCOMPtr<nsIPaymentItem> mTotalItem;
   nsCOMPtr<nsIArray> mDisplayItems;
   nsCOMPtr<nsIArray> mShippingOptions;
   nsCOMPtr<nsIArray> mModifiers;
--- a/dom/payments/PaymentRequestManager.cpp
+++ b/dom/payments/PaymentRequestManager.cpp
@@ -158,32 +158,34 @@ ConvertDetailsInit(JSContext* aCx,
   nsTArray<IPCPaymentDetailsModifier> modifiers;
   nsresult rv = ConvertDetailsBase(aCx, aDetails, displayItems, shippingOptions,
                                    modifiers, aRequestShipping);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Convert |id|
-  nsString id(EmptyString());
+  nsAutoString id;
   if (aDetails.mId.WasPassed()) {
     id = aDetails.mId.Value();
   }
 
   // Convert required |total|
   IPCPaymentItem total;
   ConvertItem(aDetails.mTotal, total);
 
   aIPCDetails = IPCPaymentDetails(id,
                                   total,
                                   displayItems,
                                   shippingOptions,
                                   modifiers,
                                   EmptyString(), // error message
-                                  EmptyString()); // shippingAddressErrors
+                                  EmptyString(), // shippingAddressErrors
+                                  EmptyString(), // payerErrors
+                                  EmptyString()); // paymentMethodErrors
   return NS_OK;
 }
 
 nsresult
 ConvertDetailsUpdate(JSContext* aCx,
                      const PaymentDetailsUpdate& aDetails,
                      IPCPaymentDetails& aIPCDetails,
                      bool aRequestShipping)
@@ -199,33 +201,49 @@ ConvertDetailsUpdate(JSContext* aCx,
     return rv;
   }
 
   // Convert required |total|
   IPCPaymentItem total;
   ConvertItem(aDetails.mTotal, total);
 
   // Convert |error|
-  nsString error(EmptyString());
+  nsAutoString error;
   if (aDetails.mError.WasPassed()) {
     error = aDetails.mError.Value();
   }
 
-  nsString shippingAddressErrors(EmptyString());
+  nsAutoString shippingAddressErrors;
   if (!aDetails.mShippingAddressErrors.ToJSON(shippingAddressErrors)) {
     return NS_ERROR_FAILURE;
   }
 
+  nsAutoString payerErrors;
+  if (!aDetails.mPayerErrors.ToJSON(payerErrors)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsAutoString paymentMethodErrors;
+  if (aDetails.mPaymentMethodErrors.WasPassed()) {
+    JS::RootedObject object(aCx, aDetails.mPaymentMethodErrors.Value());
+    nsresult rv = SerializeFromJSObject(aCx, object, paymentMethodErrors);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  }
+
   aIPCDetails = IPCPaymentDetails(EmptyString(), // id
                                   total,
                                   displayItems,
                                   shippingOptions,
                                   modifiers,
                                   error,
-                                  shippingAddressErrors);
+                                  shippingAddressErrors,
+                                  payerErrors,
+                                  paymentMethodErrors);
   return NS_OK;
 }
 
 void
 ConvertOptions(const PaymentOptions& aOptions,
                IPCPaymentOptions& aIPCOption)
 {
   uint8_t shippingTypeIndex = static_cast<uint8_t>(aOptions.mShippingType);
@@ -545,28 +563,28 @@ PaymentRequestManager::RetryPayment(JSCo
                                     const PaymentValidationErrors& aErrors)
 {
   NS_ENSURE_ARG_POINTER(aCx);
   NS_ENSURE_ARG_POINTER(aRequest);
 
   nsAutoString requestId;
   aRequest->GetInternalId(requestId);
 
-  nsAutoString error(EmptyString());
+  nsAutoString error;
   if (aErrors.mError.WasPassed()) {
     error = aErrors.mError.Value();
   }
 
-  nsAutoString shippingAddressErrors(EmptyString());
+  nsAutoString shippingAddressErrors;
   aErrors.mShippingAddress.ToJSON(shippingAddressErrors);
 
-  nsAutoString payerErrors(EmptyString());
+  nsAutoString payerErrors;
   aErrors.mPayer.ToJSON(payerErrors);
 
-  nsAutoString paymentMethodErrors(EmptyString());
+  nsAutoString paymentMethodErrors;
   if (aErrors.mPaymentMethod.WasPassed()) {
     JS::RootedObject object(aCx, aErrors.mPaymentMethod.Value());
     nsresult rv = SerializeFromJSObject(aCx, object, paymentMethodErrors);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
   IPCPaymentRetryActionRequest action(requestId,
--- a/dom/payments/ipc/PPaymentRequest.ipdl
+++ b/dom/payments/ipc/PPaymentRequest.ipdl
@@ -51,16 +51,18 @@ struct IPCPaymentDetails
 {
   nsString id;
   IPCPaymentItem total;
   IPCPaymentItem[] displayItems;
   IPCPaymentShippingOption[] shippingOptions;
   IPCPaymentDetailsModifier[] modifiers;
   nsString error;
   nsString shippingAddressErrors;
+  nsString payerErrors;
+  nsString paymentMethodErrors;
 };
 
 struct IPCPaymentOptions
 {
   bool requestPayerName;
   bool requestPayerEmail;
   bool requestPayerPhone;
   bool requestShipping;
--- a/dom/webidl/PaymentRequest.webidl
+++ b/dom/webidl/PaymentRequest.webidl
@@ -79,16 +79,18 @@ dictionary PayerErrorFields {
   DOMString email;
   DOMString name;
   DOMString phone;
 };
 
 dictionary PaymentDetailsUpdate : PaymentDetailsBase {
   DOMString     error;
   AddressErrors shippingAddressErrors;
+  PayerErrorFields payerErrors;
+  object paymentMethodErrors;
   PaymentItem   total;
 };
 
 enum PaymentShippingType {
   "shipping",
   "delivery",
   "pickup"
 };