Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vegimcarkaxhija committed Sep 27, 2024
1 parent 1d5cc5e commit aee788e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ define(
subTextStyle: checkoutCommon.getSubtextStyle('creditcards'),

oauthTokenError: ko.observable(''),
paymentError: ko.observable(''),

initialize: function (options) {
this._super(options);
Expand Down Expand Up @@ -93,6 +94,7 @@ define(

// Re-fetch the OAuth token and reinitialize the hosted fields
this.getOAuthToken();
this.paymentError('');

// Re-enable the submit button
let payButton = document.getElementById("pay");
Expand Down Expand Up @@ -190,8 +192,8 @@ define(
this.service = sdkClient.getService();
this.finalizePlaceOrder(event);
} catch (error) {
console.error("Error during payment submission:", error);
payButton.disabled = false; // Re-enable button if there's an error
this.paymentError("Payment processing failed. Please try again.");
payButton.disabled = false;
}
}.bind(this));
}
Expand All @@ -215,7 +217,7 @@ define(
}

if (!this.encryptedCardData) {
console.error("Payment token is missing. Please try again.");
this.paymentError("Payment token is missing. Please try again.");
return;
}

Expand All @@ -226,6 +228,7 @@ define(
$.when(placeOrder).fail(
function () {
self.isPlaceOrderActionAllowed(true);
self.paymentError("Payment token is missing. Please try again.");
}
).done(self.afterPlaceOrder.bind(self));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
</div>

<div class="field oauth-token-error text-red-500" data-bind="text: oauthTokenError, visible: oauthTokenError"></div>
<div class="field payment-error text-red-500" data-bind="text: paymentError, visible: paymentError"></div>

<div class="flex items-center justify-between">
<button id="pay"
Expand Down

0 comments on commit aee788e

Please sign in to comment.