Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIWOO-349] Show notice to user if payment is not successful on the Pay for order page. #811

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Mollie\WooCommerce\Buttons\PayPalButton\PayPalButtonHandler;
use Mollie\WooCommerce\Gateway\Voucher\MaybeDisableGateway;
use Mollie\WooCommerce\Notice\AdminNotice;
use Mollie\WooCommerce\Notice\FrontendNotice;
use Mollie\WooCommerce\Notice\NoticeInterface;
use Mollie\WooCommerce\Payment\MollieObject;
use Mollie\WooCommerce\Payment\MollieOrderService;
Expand Down Expand Up @@ -495,8 +496,8 @@ public function instantiatePaymentMethodGateways(ContainerInterface $container):
{
$logger = $container->get(Logger::class);
assert($logger instanceof Logger);
$notice = $container->get(AdminNotice::class);
assert($notice instanceof AdminNotice);
$notice = $container->get(FrontendNotice::class);
assert($notice instanceof FrontendNotice);
$paymentService = $container->get(PaymentService::class);
assert($paymentService instanceof PaymentService);
$mollieOrderService = $container->get(MollieOrderService::class);
Expand Down
7 changes: 3 additions & 4 deletions src/Gateway/MolliePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,12 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string
return $this->get_return_url($order);
} else {
$this->notice->addNotice(
'notice',
'error',
__(
'You have cancelled your payment. Please complete your order with a different payment method.',
'mollie-payments-for-woocommerce'
)
);

// Return to order payment page
return $failedRedirect;
}
Expand All @@ -592,7 +591,7 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string
&& !$payment->isAuthorized()
) {
$this->notice->addNotice(
'notice',
'error',
__(
'Your payment was not successful. Please complete your order with a different payment method.',
'mollie-payments-for-woocommerce'
Expand All @@ -606,7 +605,7 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string
}
} catch (UnexpectedValueException $exc) {
$this->notice->addNotice(
'notice',
'error',
__(
'Your payment was not successful. Please complete your order with a different payment method.',
'mollie-payments-for-woocommerce'
Expand Down
13 changes: 13 additions & 0 deletions src/Notice/FrontendNotice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Mollie\WooCommerce\Notice;

class FrontendNotice implements NoticeInterface
{
public function addNotice($level, $message): void
{
wc_add_notice($message, $level);
}
}
6 changes: 3 additions & 3 deletions src/Notice/NoticeModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
use Inpsyde\Modularity\Module\ServiceModule;
use Mollie\WooCommerce\Notice\AdminNotice;
use Psr\Container\ContainerInterface;
use Mollie\WooCommerce\Notice\NoticeInterface as Notice;

class NoticeModule implements ServiceModule
{
Expand All @@ -22,6 +19,9 @@ public function services(): array
AdminNotice::class => static function (): AdminNotice {
return new AdminNotice();
},
FrontendNotice::class => static function (): FrontendNotice {
return new FrontendNotice();
},
];
}
}