Skip to content

Commit

Permalink
- Expired payments no longer result in a 500 error on the webhook call
Browse files Browse the repository at this point in the history
- Fixed a bug in completing an Apple Pay payment
  • Loading branch information
Reinder committed Mar 26, 2020
1 parent b4ab804 commit 87de92d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Components/MollieApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 19 additions & 16 deletions Components/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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);

Expand Down
19 changes: 7 additions & 12 deletions Controllers/Frontend/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -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 */
Expand All @@ -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;
}
}
Expand Down
12 changes: 11 additions & 1 deletion Resources/views/frontend/_public/src/js/applepay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/frontend/checkout/change_payment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{block name='frontend_checkout_payment_fieldset_input_radio'}
{if $payment_mean.name|lower == 'mollie_applepay'}
<div class="method--input">
<input type="radio" name="payment" class="radio auto_submit payment-mean-{$payment_mean.name|lower|replace:"_":"-"}" disabled="disabled" value="{$payment_mean.id}" id="payment_mean{$payment_mean.id}" />
<input type="radio" name="payment" class="radio auto_submit payment-mean-{$payment_mean.name|lower|replace:"_":"-"}" value="{$payment_mean.id}" id="payment_mean{$payment_mean.id}"{if $payment_mean.id eq $sFormData.payment or (!$sFormData && !$smarty.foreach.register_payment_mean.index)} checked="checked"{/if} />
</div>
{else}
{$smarty.block.parent}
Expand All @@ -15,7 +15,7 @@
{block name='frontend_checkout_payment_fieldset_input_label'}
{if $payment_mean.name|lower == 'mollie_applepay'}
<div class="method--label is--first">
<label class="method--name is--strong is--soft payment-mean-{$payment_mean.name|lower|replace:"_":"-"}-label" for="payment_mean{$payment_mean.id}" id="payment_mean{$payment_mean.id}_label">{$payment_mean.description}</label>
<label class="method--name is--strong payment-mean-{$payment_mean.name|lower|replace:"_":"-"}-label" for="payment_mean{$payment_mean.id}" id="payment_mean{$payment_mean.id}_label">{$payment_mean.description}</label>
</div>
{else}
{$smarty.block.parent}
Expand Down
8 changes: 4 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<label lang="de">Mollie</label>
<label lang="nl">Mollie</label>

<version>1.5.8</version>
<version>1.5.9</version>
<copyright>(c) Mollie B.V.</copyright>
<author>Kiener E-commerce</author>
<link>https://www.kiener.nl</link>

<description lang="en">Plugin to allow iDeal payments using the Mollie API (1.5.8)</description>
<description lang="nl">Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.8)</description>
<description lang="de">Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.8)</description>
<description lang="en">Plugin to allow iDeal payments using the Mollie API (1.5.9)</description>
<description lang="nl">Plugin die iDealbetalingen via de Mollie API doorgeeft (1.5.9)</description>
<description lang="de">Plugin um Zahlungen mit der Mollie API zu ermöglichen (1.5.9)</description>

<compatibility minVersion="5.3.0"/>
</plugin>

0 comments on commit 87de92d

Please sign in to comment.