diff --git a/PayrexxPaymentGatewaySW6/CHANGELOG.md b/PayrexxPaymentGatewaySW6/CHANGELOG.md
new file mode 100644
index 0000000..9ca7203
--- /dev/null
+++ b/PayrexxPaymentGatewaySW6/CHANGELOG.md
@@ -0,0 +1,8 @@
+# Changelog
+
+## [1.0.44]
+### Fixed
+- Bug fix: Resolved an issue where deleting a payment gateway for transition change.
+
+### Added
+- Added support for a new URL to handle unexpected errors.
\ No newline at end of file
diff --git a/PayrexxPaymentGatewaySW6/composer.json b/PayrexxPaymentGatewaySW6/composer.json
index 51de7a4..5b4e0b2 100644
--- a/PayrexxPaymentGatewaySW6/composer.json
+++ b/PayrexxPaymentGatewaySW6/composer.json
@@ -1,7 +1,7 @@
{
"name": "payrexx/payment",
"description": "A Shopware plugin to accept payments with Payrexx",
- "version": "1.0.43",
+ "version": "1.0.44",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [
diff --git a/PayrexxPaymentGatewaySW6/src/Handler/PaymentHandler.php b/PayrexxPaymentGatewaySW6/src/Handler/PaymentHandler.php
index 22cce41..c1a7896 100644
--- a/PayrexxPaymentGatewaySW6/src/Handler/PaymentHandler.php
+++ b/PayrexxPaymentGatewaySW6/src/Handler/PaymentHandler.php
@@ -30,6 +30,8 @@
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler;
use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\AsynchronousPaymentHandlerInterface;
use Shopware\Core\Checkout\Payment\PaymentException;
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
+use Symfony\Component\Routing\RouterInterface;
class PaymentHandler implements AsynchronousPaymentHandlerInterface
{
@@ -72,6 +74,11 @@ class PaymentHandler implements AsynchronousPaymentHandlerInterface
*/
protected $logger;
+ /**
+ * @var RouterInterface
+ */
+ protected $router;
+
/**
* @param OrderTransactionStateHandler $transactionStateHandler
* @param ContainerInterface $container
@@ -79,7 +86,8 @@ class PaymentHandler implements AsynchronousPaymentHandlerInterface
* @param PayrexxApiService $payrexxApiService
* @param TransactionHandler $transactionHandler
* @param ConfigService $configService
- * @param type $logger
+ * @param LoggerInterface $logger
+ * @param RouterInterface $router
*/
public function __construct(
OrderTransactionStateHandler $transactionStateHandler,
@@ -88,7 +96,8 @@ public function __construct(
PayrexxApiService $payrexxApiService,
TransactionHandler $transactionHandler,
ConfigService $configService,
- $logger
+ LoggerInterface $logger,
+ RouterInterface $router
) {
$this->transactionStateHandler = $transactionStateHandler;
$this->container = $container;
@@ -97,6 +106,7 @@ public function __construct(
$this->transactionHandler = $transactionHandler;
$this->configService = $configService;
$this->logger = $logger;
+ $this->router = $router;
}
/**
@@ -176,6 +186,13 @@ public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $
if (in_array($paymentMean, ['sofortueberweisung_de', 'postfinance_card', 'postfinance_efinance'])) {
throw new Exception('Unavailable payment method error');
}
+ $cancelUrl = $this->router->generate('frontend.payrexx-payment.cancel',
+ [
+ 'orderId' => $order->getOrderNumber(),
+ 'transactionId' => $transactionId,
+ ],
+ UrlGeneratorInterface::ABSOLUTE_URL
+ );
// Create Payrexx Gateway link for checkout and redirect user
try {
$payrexxGateway = $this->payrexxApiService->createPayrexxGateway(
@@ -188,7 +205,8 @@ public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $
$transaction->getReturnUrl(),
$basket,
$salesChannelId,
- $purpose
+ $purpose,
+ $cancelUrl
);
if (!$payrexxGateway) {
diff --git a/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_6.xml b/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_6.xml
index 40af1bf..36cd7ab 100644
--- a/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_6.xml
+++ b/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_6.xml
@@ -5,4 +5,5 @@
+
diff --git a/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_64.xml b/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_64.xml
index 2f7cb2e..74328a1 100644
--- a/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_64.xml
+++ b/PayrexxPaymentGatewaySW6/src/Resources/config/compatibility/routes/routes_64.xml
@@ -5,4 +5,5 @@
-
\ No newline at end of file
+
+
diff --git a/PayrexxPaymentGatewaySW6/src/Resources/config/services.xml b/PayrexxPaymentGatewaySW6/src/Resources/config/services.xml
index 9649bf5..151d147 100644
--- a/PayrexxPaymentGatewaySW6/src/Resources/config/services.xml
+++ b/PayrexxPaymentGatewaySW6/src/Resources/config/services.xml
@@ -15,6 +15,7 @@
+
@@ -65,5 +66,9 @@
-
+
+
+
+
+
diff --git a/PayrexxPaymentGatewaySW6/src/Service/PayrexxApiService.php b/PayrexxPaymentGatewaySW6/src/Service/PayrexxApiService.php
index 9811c1e..8f9eabd 100644
--- a/PayrexxPaymentGatewaySW6/src/Service/PayrexxApiService.php
+++ b/PayrexxPaymentGatewaySW6/src/Service/PayrexxApiService.php
@@ -8,6 +8,7 @@
use Shopware\Core\Framework\Context;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
@@ -64,6 +65,7 @@ private function getInterface($salesChannelId): \Payrexx\Payrexx
* @param array $basket
* @param string $salesChannelId
* @param string $purpose
+ * @param string $cancelUrl
* @return Gateway
*
*/
@@ -77,7 +79,8 @@ public function createPayrexxGateway(
string $url,
array $basket,
string $salesChannelId,
- string $purpose
+ string $purpose,
+ string $cancelUrl
) {
$config = $this->configService->getPluginConfiguration($salesChannelId);
$lookAndFeelId = !empty($config['lookFeelID']) ? $config['lookFeelID'] : null;
@@ -89,7 +92,7 @@ public function createPayrexxGateway(
$gateway->setCurrency($currency);
$gateway->setSuccessRedirectUrl($url);
$gateway->setFailedRedirectUrl($url);
- $gateway->setCancelRedirectUrl($url);
+ $gateway->setCancelRedirectUrl($cancelUrl);
$gateway->setSkipResultPage(true);
$gateway->setLookAndFeelProfile($lookAndFeelId);
diff --git a/PayrexxPaymentGatewaySW6/src/Webhook/Cancel.php b/PayrexxPaymentGatewaySW6/src/Webhook/Cancel.php
new file mode 100644
index 0000000..31ea774
--- /dev/null
+++ b/PayrexxPaymentGatewaySW6/src/Webhook/Cancel.php
@@ -0,0 +1,124 @@
+ ['storefront']])]
+class Cancel
+{
+
+ /**
+ * @var ContainerInterface
+ */
+ protected $container;
+
+ /**
+ * @var TransactionHandler
+ */
+ protected $transactionHandler;
+
+ /**
+ * @param ContainerInterface $container
+ * @param TransactionHandler $transactionHandler
+ */
+ public function __construct(
+ ContainerInterface $container,
+ TransactionHandler $transactionHandler
+ ) {
+ $this->container = $container;
+ $this->transactionHandler = $transactionHandler;
+ }
+
+ /**
+ * @Route(
+ * "/payrexx-payment/cancel",
+ * name="frontend.payrexx-payment.cancel",
+ * methods={"GET"},
+ * defaults={"csrf_protected"=false}
+ * )
+ *
+ * @param Request $request
+ * @param Context $context
+ * @return Response
+ */
+ #[Route(path: '/payrexx-payment/cancel', name: 'frontend.payrexx-payment.cancel', methods: ['GET'], defaults: ['csrf_protected' => false])]
+ public function executeCancel(Request $request, Context $context): Response
+ {
+ $orderRepository = $this->container->get('order.repository');
+ $transactionRepo = $this->container->get('order_transaction.repository');
+ $router = $this->container->get('router');
+
+ // Get parameters from the request
+ $orderNumber = $request->query->get('orderId');
+ $transactionId = $request->query->get('transactionId');
+
+ // Validate input
+ if (!$orderNumber || !$transactionId) {
+ return new Response('Invalid request parameters.', Response::HTTP_BAD_REQUEST);
+ }
+
+ // Search for the order
+ $criteria = new Criteria();
+ $criteria->addFilter(
+ new EqualsFilter('orderNumber', $orderNumber)
+ );
+
+ $order = $orderRepository->search($criteria, $context)->first();
+ if (!$order) {
+ return new Response('Order not found.', Response::HTTP_NOT_FOUND);
+ }
+
+ // Search for the transaction
+ $criteria = new Criteria([$transactionId]);
+ $criteria->addFilter(
+ new EqualsFilter('orderId', $order->getId())
+ );
+ $criteria->addAssociation('stateMachineState');
+
+ $transaction = $transactionRepo->search($criteria, $context)->first();
+
+ if (!$transaction) {
+ return new Response('Transaction not found.', Response::HTTP_NOT_FOUND);
+ }
+
+ if (!class_exists(\Payrexx\Models\Response\Transaction::class)) {
+ require_once dirname(dirname(__DIR__)). '/vendor/autoload.php';
+ }
+
+ $this->transactionHandler->handleTransactionStatus(
+ $transaction,
+ OrderTransactionStates::STATE_CANCELLED,
+ $context
+ );
+ $redirectUrl = $router->generate(
+ 'frontend.account.edit-order.page',
+ ['orderId' => $order->getId()],
+ UrlGeneratorInterface::ABSOLUTE_URL
+ );
+ return new RedirectResponse($redirectUrl);
+ }
+}