From 05d72cf3c73a322d2532587ade7dbbb96b0bf74a Mon Sep 17 00:00:00 2001 From: Hasan Hasanzade Date: Wed, 20 Sep 2023 14:49:09 +0400 Subject: [PATCH] Giropay payment method (#89) * added Giropay payment method * changed plugin version in composer to 2.1.0 --- composer.json | 2 +- src/Installer/PaymentMethodInstaller.php | 2 + src/PaymentHandler/GiropayHandler.php | 49 ++++++++++++++++++++++++ src/PaymentMethod/Giropay.php | 34 ++++++++++++++++ src/Resources/config/services.xml | 7 ++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/PaymentHandler/GiropayHandler.php create mode 100644 src/PaymentMethod/Giropay.php diff --git a/composer.json b/composer.json index fdcc9c0..a8cdcdb 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "better-payment/bp-plugin-shopware6-api2", "description": "Better Payment plugin to implement payment methods using API2", - "version": "2.0.0", + "version": "2.1.0", "type": "shopware-platform-plugin", "license": "proprietary", "authors": [ diff --git a/src/Installer/PaymentMethodInstaller.php b/src/Installer/PaymentMethodInstaller.php index 6324c2f..f809ad6 100644 --- a/src/Installer/PaymentMethodInstaller.php +++ b/src/Installer/PaymentMethodInstaller.php @@ -3,6 +3,7 @@ namespace BetterPayment\Installer; use BetterPayment\BetterPayment; +use BetterPayment\PaymentMethod\Giropay; use BetterPayment\PaymentMethod\InvoiceB2B; use BetterPayment\PaymentMethod\PaymentMethod; use BetterPayment\PaymentMethod\CreditCard; @@ -28,6 +29,7 @@ class PaymentMethodInstaller Paydirekt::class, Sofort::class, Paypal::class, + Giropay::class, SEPADirectDebit::class, SEPADirectDebitB2B::class, Invoice::class, diff --git a/src/PaymentHandler/GiropayHandler.php b/src/PaymentHandler/GiropayHandler.php new file mode 100644 index 0000000..45583b7 --- /dev/null +++ b/src/PaymentHandler/GiropayHandler.php @@ -0,0 +1,49 @@ +orderTransactionStateHandler = $orderTransactionStateHandler; + $this->betterPaymentClient = $betterPaymentClient; + } + + public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $dataBag, SalesChannelContext $salesChannelContext): RedirectResponse + { + try { + $redirectUrl = $this->betterPaymentClient->request($transaction)->action_data->url; + } catch (\Exception $e) { + throw new AsyncPaymentProcessException( + $transaction->getOrderTransaction()->getId(), + 'An error occurred during the communication with external payment gateway' . PHP_EOL + . $e->getMessage() . PHP_EOL + . 'TRACE: ' . $e->getTraceAsString() + ); + } + + return new RedirectResponse($redirectUrl); + } + + public function finalize(AsyncPaymentTransactionStruct $transaction, Request $request, SalesChannelContext $salesChannelContext): void + { + $context = $salesChannelContext->getContext(); + $this->orderTransactionStateHandler->paid($transaction->getOrderTransaction()->getId(), $context); + } +} \ No newline at end of file diff --git a/src/PaymentMethod/Giropay.php b/src/PaymentMethod/Giropay.php new file mode 100644 index 0000000..75a24d6 --- /dev/null +++ b/src/PaymentMethod/Giropay.php @@ -0,0 +1,34 @@ + [ + 'name' => 'Giropay', + 'description' => '', + 'customFields' => [ + 'shortname' => self::SHORTNAME + ] + ], + 'en-GB' => [ + 'name' => 'Giropay', + 'description' => '', + 'customFields' => [ + 'shortname' => self::SHORTNAME + ] + ], + ]; +} \ No newline at end of file diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 794dec9..41bfe8c 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -34,6 +34,13 @@ + + + + + + +