Skip to content

Commit

Permalink
Merge pull request #2773 from Adyen/ECP-9498
Browse files Browse the repository at this point in the history
[ECP-9498] Implement `onError` callback for the Paypal.
  • Loading branch information
khushboo-singhvi authored Oct 28, 2024
2 parents 5ff9a68 + 1a43cff commit 5c2bc8b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Helper/PaymentsDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function cleanUpPaymentDetailsPayload(array $payload): array
);

foreach (self::REQUEST_HELPER_PARAMETERS as $helperParam) {
if (array_key_exists($helperParam, $payload['details'])) {
if (isset($payload['details']) && array_key_exists($helperParam, $payload['details'])) {
unset($payload['details'][$helperParam]);
}
}
Expand Down
5 changes: 3 additions & 2 deletions view/frontend/web/js/model/adyen-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define(
) {
'use strict';
return {
buildCheckoutComponent: function (paymentMethodsResponse, handleOnAdditionalDetails, handleOnCancel = undefined, handleOnSubmit = undefined) {
buildCheckoutComponent: function (paymentMethodsResponse, handleOnAdditionalDetails, handleOnCancel = undefined, handleOnSubmit = undefined, handleOnError = undefined) {
if (!!paymentMethodsResponse.paymentMethodsResponse) {
return AdyenCheckout({
locale: adyenConfiguration.getLocale(),
Expand All @@ -28,7 +28,8 @@ define(
paymentMethodsResponse: paymentMethodsResponse.paymentMethodsResponse,
onAdditionalDetails: handleOnAdditionalDetails,
onCancel: handleOnCancel,
onSubmit: handleOnSubmit
onSubmit: handleOnSubmit,
onError: handleOnError
}
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ define(
'Magento_Checkout/js/model/quote',
'Adyen_Payment/js/view/payment/method-renderer/adyen-pm-method',
'Magento_Checkout/js/model/full-screen-loader',
'Adyen_Payment/js/model/adyen-payment-service',
'Magento_Checkout/js/model/error-processor',
'Adyen_Payment/js/model/adyen-configuration'
],
function(
quote,
adyenPaymentMethod,
fullScreenLoader
fullScreenLoader,
adyenPaymentService,
errorProcessor,
adyenConfiguration
) {
return adyenPaymentMethod.extend({
placeOrderButtonVisible: false,
token: null,
initialize: function () {
this._super();
},
Expand All @@ -32,14 +39,47 @@ define(
},
renderActionComponent: function(resultCode, action, component) {
fullScreenLoader.stopLoader();

this.token = action.sdkData.token;
this.actionComponent = component.handleAction(action);
},
handleOnFailure: function(response, component) {
this.isPlaceOrderAllowed(true);
fullScreenLoader.stopLoader();
component.handleReject(response);
},
handleOnError: function (error, component) {
if ('test' === adyenConfiguration.getCheckoutEnvironment()) {
console.log("onError:",error);
}

// call endpoint with component.paymentData if available
let request = {};
if (!!component.paymentData) {
request.paymentData = component.paymentData;
}

//Create details array for the payload
let details = {};
if(!!this.token) {
details.orderID = this.token;
}
request.details = details;

adyenPaymentService.paymentDetails(request, this.orderId).done(function() {
$.mage.redirect(
window.checkoutConfig.payment.adyen.successPage
);
}).fail(function(response) {
fullScreenLoader.stopLoader();
if (this.popupModal) {
this.closeModal(this.popupModal);
}
errorProcessor.process(response,
this.currentMessageContainer);
this.isPlaceOrderAllowed(true);
this.showErrorMessage(response);
});
}
})
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ define(
paymentMethodsResponse,
this.handleOnAdditionalDetails.bind(this),
this.handleOnCancel.bind(this),
this.handleOnSubmit.bind(this)
this.handleOnSubmit.bind(this),
this.handleOnError.bind(this)
);

if (!!this.checkoutComponent) {
Expand Down Expand Up @@ -374,15 +375,20 @@ define(

try {
const orderId = await placeOrderAction(data, self.currentMessageContainer);
self.afterPlaceOrder();
const responseJSON = await adyenPaymentService.getOrderPaymentStatus(orderId);
self.validateActionOrPlaceOrder(responseJSON, orderId, component);
} catch (response) {
self.handleOnFailure(response, component);
}
},


handleOnError: function (error, component) {
/*
* Passing false as the response to hide the actual error message from the shopper for security.
* This will show a generic error message instead of the actual error message.
*/
this.handleOnFailure(error, component);
},
handleOnFailure: function(response, component) {
this.isPlaceOrderAllowed(true);
fullScreenLoader.stopLoader();
Expand Down

0 comments on commit 5c2bc8b

Please sign in to comment.