From 87de92d736d8dc319f736c7aaefd2c3912d1cc79 Mon Sep 17 00:00:00 2001 From: Reinder Date: Thu, 26 Mar 2020 08:52:28 +0100 Subject: [PATCH] - Expired payments no longer result in a 500 error on the webhook call - Fixed a bug in completing an Apple Pay payment --- Components/MollieApiFactory.php | 2 +- Components/Notifier.php | 35 ++++++++++--------- Controllers/Frontend/Mollie.php | 19 ++++------ .../views/frontend/_public/src/js/applepay.js | 12 ++++++- .../frontend/checkout/change_payment.tpl | 4 +-- plugin.xml | 8 ++--- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/Components/MollieApiFactory.php b/Components/MollieApiFactory.php index 8c28ee53..f48c1a5f 100644 --- a/Components/MollieApiFactory.php +++ b/Components/MollieApiFactory.php @@ -49,7 +49,7 @@ public function create() // add plugin name and version $this->apiClient->addVersionString( - 'MollieShopware/1.5.8' + 'MollieShopware/1.5.9' ); } catch (\Exception $ex) { diff --git a/Components/Notifier.php b/Components/Notifier.php index 33a6d037..9f7214de 100644 --- a/Components/Notifier.php +++ b/Components/Notifier.php @@ -5,10 +5,10 @@ class Notifier { /** - * Shows a JSON exception for the given request. Also sends - * a 500 server error. + * Shows a JSON exception for the given request. * * @param $error + * @param null $exception * @throws \Exception */ public static function notifyException($error, $exception = null) { @@ -19,20 +19,11 @@ public static function notifyException($error, $exception = null) { $exception ); - // return the error json - header('HTTP/1.0 500 Server Error'); - header('Content-Type: text/json'); - - echo json_encode([ - 'success' => false, - 'message' => $error - ], JSON_PRETTY_PRINT); - - die(); + self::notify(false, $error, '500 Server Error'); } /** - * Shows a JSON thank you message, with a 200 HTTP ok. + * Shows a JSON success message. * * @param $message * @throws \Exception @@ -44,12 +35,24 @@ public static function notifyOk($message) { $message ); - // return the success json - header('HTTP/1.0 200 Ok'); + self::notify(true, $message); + } + + /** + * Notify a message as json. + * + * @param bool $success + * @param string $message + * @param string $header + */ + private static function notify($success, $message = '', $header = '200 Ok') + { + // return the json + header('HTTP/1.0 ' . $header); header('Content-Type: text/json'); echo json_encode([ - 'success' => true, + 'success' => $success, 'message' => $message ], JSON_PRETTY_PRINT); diff --git a/Controllers/Frontend/Mollie.php b/Controllers/Frontend/Mollie.php index 97170694..e1712dec 100644 --- a/Controllers/Frontend/Mollie.php +++ b/Controllers/Frontend/Mollie.php @@ -1350,12 +1350,11 @@ private function getOrderCanceledOrFailed($transaction) // } - if ($molliePayment !== null) { - if ($molliePayment->isCanceled() === true || - $molliePayment->isFailed() === true || - $molliePayment->isExpired() === true) { - return true; - } + if ( + $molliePayment !== null + && ($molliePayment->isCanceled() === true || $molliePayment->isFailed() === true) + ) { + return true; } } } @@ -1372,7 +1371,6 @@ private function getPaymentCollectionCanceledOrFailed(\Mollie\Api\Resources\Paym $paymentsTotal = $payments->count(); $canceledPayments = 0; $failedPayments = 0; - $expiredPayments = 0; if ($paymentsTotal > 0) { /** @var \Mollie\Api\Resources\Payment $payment */ @@ -1383,13 +1381,10 @@ private function getPaymentCollectionCanceledOrFailed(\Mollie\Api\Resources\Paym if ($payment->isFailed() === true) { $failedPayments++; } - if ($payment->isExpired() === true) { - $expiredPayments++; - } } - if ($canceledPayments > 0 || $failedPayments > 0 || $expiredPayments > 0) { - if (($canceledPayments + $failedPayments + $expiredPayments) === $paymentsTotal) { + if ($canceledPayments > 0 || $failedPayments > 0) { + if (($canceledPayments + $failedPayments) === $paymentsTotal) { return true; } } diff --git a/Resources/views/frontend/_public/src/js/applepay.js b/Resources/views/frontend/_public/src/js/applepay.js index 667c0c10..6170a67d 100644 --- a/Resources/views/frontend/_public/src/js/applepay.js +++ b/Resources/views/frontend/_public/src/js/applepay.js @@ -14,15 +14,25 @@ var applePayInput = document.getElementsByClassName('payment-mean-mollie-applepay'); var applePayLabel = document.getElementsByClassName('payment-mean-mollie-applepay-label'); + // Create a disabled attribute + var disabledItem = document.createAttribute('disabled'); + disabledItem.value = 'disabled'; + if (!window.ApplePaySession || !ApplePaySession.canMakePayments()) { // Apple Pay is not available if (typeof applePayInput !== 'undefined' && applePayInput.length) { + applePayInput[0].checked = false; + applePayInput[0].attributes.setNamedItem(disabledItem); applePayInput[0].parentNode.parentNode.classList.add('is--hidden'); } } else { // Show Apple Pay option if (typeof applePayInput !== 'undefined' && applePayInput.length) { - applePayInput[0].attributes.removeNamedItem('disabled'); + if (applePayInput[0].attributes.getNamedItem('disabled') !== null) { + applePayInput[0].attributes.removeNamedItem('disabled'); + } + + applePayInput[0].parentNode.parentNode.classList.remove('is--hidden'); } if (typeof applePayLabel !== 'undefined' && applePayLabel.length) { diff --git a/Resources/views/frontend/checkout/change_payment.tpl b/Resources/views/frontend/checkout/change_payment.tpl index cc468e99..1c56eb34 100644 --- a/Resources/views/frontend/checkout/change_payment.tpl +++ b/Resources/views/frontend/checkout/change_payment.tpl @@ -4,7 +4,7 @@ {block name='frontend_checkout_payment_fieldset_input_radio'} {if $payment_mean.name|lower == 'mollie_applepay'}
- +
{else} {$smarty.block.parent} @@ -15,7 +15,7 @@ {block name='frontend_checkout_payment_fieldset_input_label'} {if $payment_mean.name|lower == 'mollie_applepay'}
- +
{else} {$smarty.block.parent} diff --git a/plugin.xml b/plugin.xml index ac693d3d..7a77b2a1 100644 --- a/plugin.xml +++ b/plugin.xml @@ -6,14 +6,14 @@ - 1.5.8 + 1.5.9 (c) Mollie B.V. Kiener E-commerce https://www.kiener.nl - Plugin to allow iDeal payments using the Mollie API (1.5.8) - Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.8) - Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.8) + Plugin to allow iDeal payments using the Mollie API (1.5.9) + Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.9) + Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.9) \ No newline at end of file