Skip to content

Commit

Permalink
Merge branch 'MPGS-430' into 'master'
Browse files Browse the repository at this point in the history
MPGS-430: Fix the following issue: The payment was declined, but error message isn't shown

See merge request mpgs/simplify-prestashop!7
  • Loading branch information
OnTapKristjan committed Jul 23, 2021
2 parents 40259a3 + 66e0dfc commit 2c8df86
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
15 changes: 12 additions & 3 deletions simplifycommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,12 @@ public function processPayment()
}

if ($payment_status != 'APPROVED') {
$this->failPayment('The transaction was ' . $payment_status);
$this->failPayment(
sprintf(
"The payment was %s",
$payment_status
)
);
}

// Log the transaction
Expand Down Expand Up @@ -780,8 +785,12 @@ private function failPayment($message)

$controller = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc.php' : 'order.php';
error_log($message);
$location = $this->context->link->getPageLink($controller) . (strpos($controller, '?') !== false ? '&' : '?') .
'step=3&simplify_error=There was a problem with your payment: ' . $message . '#simplify_error';
$location = sprintf(
"%s%sstep=3&simplify_error=There was a problem with your payment: %s.#simplify_error",
$this->context->link->getPageLink($controller),
strpos($controller, '?') !== false ? '&' : '?',
$message
);
Tools::redirect($location);
exit;
}
Expand Down
1 change: 1 addition & 0 deletions views/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ i.simplifyFormContainer mg.enable {
font-size: 0.875rem;
background: #ffcccc;
margin-top: 1rem;
display: block;
}

.simplify-form-container .simplify-payment-errors.hidden {
Expand Down
61 changes: 55 additions & 6 deletions views/js/simplify.embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,31 @@ $(function () {
})
});

elements.deleteSavedCardAction.on('click', function(e) {
elements.deleteSavedCardAction.on('click', function (e) {
e.stopPropagation();
setState({
isCardDeletionInProgress: true,
isCardDeleted: false,
})
});

elements.savedCardDeletionUndoAction.on('click', function(e) {
elements.savedCardDeletionUndoAction.on('click', function (e) {
e.stopPropagation();
setState({
isCardDeletionInProgress: false,
isCardDeleted: false,
})
});

elements.savedCardCancelDeletionAction.on('click', function(e) {
elements.savedCardCancelDeletionAction.on('click', function (e) {
e.stopPropagation();
setState({
isCardDeletionInProgress: false,
isCardDeleted: false,
})
});

elements.savedCardConfirmDeletionAction.on('click', function(e) {
elements.savedCardConfirmDeletionAction.on('click', function (e) {
e.stopPropagation();
setState({
isCardDeletionInProgress: true,
Expand All @@ -147,7 +147,7 @@ $(function () {
})
});

elements.paymentSubmitAction.on('click', function(e) {
elements.paymentSubmitAction.on('click', function (e) {
e.stopPropagation();
setState({
isRequestSubmitted: true,
Expand Down Expand Up @@ -191,9 +191,14 @@ $(function () {
}

elements.errorsContainer.html(errorList)
} else if (state.paymentError.code === "gateway") {
elements.errorsContainer.html(state.paymentError.message);
} else {
elements.errorsContainer.html("Error occurred while processing payment, please contact support.");
elements.errorsContainer.html(
"An error occurred while processing payment. Please get in touch with support."
);
}

elements.errorsContainer.removeClass('hidden');
} else {
elements.errorsContainer.addClass('hidden');
Expand Down Expand Up @@ -323,6 +328,50 @@ $(function () {
}
}

/**
* Function to get url get parameter from window's location
* @returns {*}
* @param name
* @param url
*/
function getUrlParam(name, url) {
var results, res;

if (!url) {
url = window.location.href;
}
results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url);
res = (results && results[1]) || undefined;
return res;
}

/**
* This function should be used in the case of error happened with Payment on Backend
*/
function showSimplifyPaymentForm() {

var id = elements.paymentForm.parents(".js-payment-option-form").attr("id");
var match = id && id.match("pay-with-payment-option-([0-9]+)-form");
var number = match && match[1];
$("#payment-option-" + number).click();

elements.conditionApproveElement.prop('checked', true);
setState({
conditionsApproved: elements.conditionApproveElement.is(":checked")
})
}

var simplifyError = getUrlParam('simplify_error');
if (simplifyError) {
showSimplifyPaymentForm();
setState({
paymentError: {
code: "gateway",
message: decodeURI(simplifyError)
}
});
}

/**
* View initialization
*/
Expand Down
1 change: 0 additions & 1 deletion views/js/simplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@
* @param url
* @returns {*}
*/

function urlParam(name, url) {
if (!url) {
url = window.location.href;
Expand Down

0 comments on commit 2c8df86

Please sign in to comment.