From b9c618069b9d2181862d80a0259e90e8b5c4d06d Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Thu, 4 Apr 2024 11:32:19 +0200 Subject: [PATCH 01/45] PAYOSWXP-125: replace logger --- src/DependencyInjection/controllers.xml | 4 ++-- src/DependencyInjection/handler/global_handlers.xml | 4 ++-- src/DependencyInjection/listeners.xml | 2 +- src/DependencyInjection/scheduled_tasks.xml | 2 +- src/DependencyInjection/services.xml | 12 +++--------- src/DependencyInjection/store_api.xml | 2 +- src/DependencyInjection/webhooks.xml | 6 +++--- src/Resources/config/packages/monolog.yaml | 9 ++++++++- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/DependencyInjection/controllers.xml b/src/DependencyInjection/controllers.xml index b646b8ffb..3931cb952 100644 --- a/src/DependencyInjection/controllers.xml +++ b/src/DependencyInjection/controllers.xml @@ -40,7 +40,7 @@ - + %kernel.project_dir% @@ -104,7 +104,7 @@ - + diff --git a/src/DependencyInjection/handler/global_handlers.xml b/src/DependencyInjection/handler/global_handlers.xml index ff87363ac..266f8ab15 100644 --- a/src/DependencyInjection/handler/global_handlers.xml +++ b/src/DependencyInjection/handler/global_handlers.xml @@ -41,13 +41,13 @@ - + - + diff --git a/src/DependencyInjection/listeners.xml b/src/DependencyInjection/listeners.xml index eff53726e..200831cfb 100644 --- a/src/DependencyInjection/listeners.xml +++ b/src/DependencyInjection/listeners.xml @@ -114,7 +114,7 @@ - + diff --git a/src/DependencyInjection/scheduled_tasks.xml b/src/DependencyInjection/scheduled_tasks.xml index 18a524c9c..587ae8ac6 100644 --- a/src/DependencyInjection/scheduled_tasks.xml +++ b/src/DependencyInjection/scheduled_tasks.xml @@ -11,7 +11,7 @@ - + diff --git a/src/DependencyInjection/services.xml b/src/DependencyInjection/services.xml index 47febd145..a7b9adb06 100644 --- a/src/DependencyInjection/services.xml +++ b/src/DependencyInjection/services.xml @@ -49,7 +49,7 @@ - + @@ -62,16 +62,10 @@ - + - - - - payone_payment - - @@ -115,7 +109,7 @@ - + diff --git a/src/DependencyInjection/store_api.xml b/src/DependencyInjection/store_api.xml index ab9fa5342..400df753f 100644 --- a/src/DependencyInjection/store_api.xml +++ b/src/DependencyInjection/store_api.xml @@ -16,7 +16,7 @@ - + diff --git a/src/DependencyInjection/webhooks.xml b/src/DependencyInjection/webhooks.xml index b2bdba051..846bcec4e 100644 --- a/src/DependencyInjection/webhooks.xml +++ b/src/DependencyInjection/webhooks.xml @@ -7,13 +7,13 @@ - + - + @@ -22,7 +22,7 @@ - + diff --git a/src/Resources/config/packages/monolog.yaml b/src/Resources/config/packages/monolog.yaml index ccb17e145..86a4873f1 100644 --- a/src/Resources/config/packages/monolog.yaml +++ b/src/Resources/config/packages/monolog.yaml @@ -1,7 +1,14 @@ monolog: - channels: [ "payone_transaction_forward" ] + channels: + - payone + - payone_transaction_forward handlers: + payoneLogger: + type: rotating_file + path: "%kernel.logs_dir%/payone.log" + level: info + channels: [ "payone" ] payoneTransactionForwardLogger: type: rotating_file path: "%kernel.logs_dir%/payone_transaction_forward.log" From 4d70b5b570f7020008e5b28f846a2f93805c628f Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Thu, 4 Apr 2024 11:38:40 +0200 Subject: [PATCH 02/45] PAYOSWXP-125: improve controller/route registration + & move from annotion-registration to attribute-registration --- src/Resources/config/routes.xml | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/Resources/config/routes.xml b/src/Resources/config/routes.xml index cee3d197f..d3427f02e 100644 --- a/src/Resources/config/routes.xml +++ b/src/Resources/config/routes.xml @@ -2,28 +2,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + From 756097f1552d2e01b12351df6f5d7e4a9b79db62 Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Thu, 4 Apr 2024 12:28:37 +0200 Subject: [PATCH 03/45] PAYOSWXP-125: set technical name for payment methods --- src/Installer/PaymentMethodInstaller.php | 9 +++++- src/PaymentMethod/AbstractPaymentMethod.php | 5 ++++ src/PaymentMethod/PaymentMethodInterface.php | 2 ++ src/PaymentMethod/PayoneAlipay.php | 2 ++ src/PaymentMethod/PayoneAmazonPay.php | 2 ++ src/PaymentMethod/PayoneAmazonPayExpress.php | 2 ++ src/PaymentMethod/PayoneApplePay.php | 2 ++ src/PaymentMethod/PayoneBancontact.php | 2 ++ src/PaymentMethod/PayoneCreditCard.php | 2 ++ src/PaymentMethod/PayoneDebit.php | 2 ++ src/PaymentMethod/PayoneEps.php | 2 ++ src/PaymentMethod/PayoneIDeal.php | 2 ++ src/PaymentMethod/PayoneKlarnaDirectDebit.php | 2 ++ src/PaymentMethod/PayoneKlarnaInstallment.php | 2 ++ src/PaymentMethod/PayoneKlarnaInvoice.php | 2 ++ src/PaymentMethod/PayoneOpenInvoice.php | 2 ++ src/PaymentMethod/PayonePaydirekt.php | 2 ++ src/PaymentMethod/PayonePayolutionDebit.php | 2 ++ .../PayonePayolutionInstallment.php | 2 ++ .../PayonePayolutionInvoicing.php | 2 ++ src/PaymentMethod/PayonePaypal.php | 2 ++ src/PaymentMethod/PayonePaypalExpress.php | 2 ++ src/PaymentMethod/PayonePostfinanceCard.php | 2 ++ src/PaymentMethod/PayonePostfinanceWallet.php | 2 ++ src/PaymentMethod/PayonePrepayment.php | 2 ++ src/PaymentMethod/PayonePrzelewy24.php | 2 ++ src/PaymentMethod/PayoneRatepayDebit.php | 2 ++ .../PayoneRatepayInstallment.php | 2 ++ src/PaymentMethod/PayoneRatepayInvoicing.php | 2 ++ src/PaymentMethod/PayoneSecureInvoice.php | 3 ++ .../PayoneSecuredDirectDebit.php | 2 ++ .../PayoneSecuredInstallment.php | 2 ++ src/PaymentMethod/PayoneSecuredInvoice.php | 2 ++ src/PaymentMethod/PayoneSofortBanking.php | 2 ++ src/PaymentMethod/PayoneTrustly.php | 2 ++ src/PaymentMethod/PayoneWeChatPay.php | 2 ++ src/PayonePayment.php | 6 +++- .../PaymentMethod/PaymentMethodTest.php | 28 +++++++++++++++++-- 38 files changed, 112 insertions(+), 5 deletions(-) diff --git a/src/Installer/PaymentMethodInstaller.php b/src/Installer/PaymentMethodInstaller.php index 0a8234088..d2cc55fc0 100644 --- a/src/Installer/PaymentMethodInstaller.php +++ b/src/Installer/PaymentMethodInstaller.php @@ -40,9 +40,11 @@ use PayonePayment\PaymentMethod\PayoneTrustly; use PayonePayment\PaymentMethod\PayoneWeChatPay; use PayonePayment\PayonePayment; +use Shopware\Core\Checkout\Payment\PaymentMethodDefinition; use Shopware\Core\Checkout\Payment\PaymentMethodEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; +use Shopware\Core\Framework\DataAbstractionLayer\Field\Field; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; use Shopware\Core\Framework\Plugin\Context\ActivateContext; @@ -158,7 +160,8 @@ public function __construct( private readonly EntityRepository $paymentMethodRepository, private readonly EntityRepository $salesChannelRepository, private readonly EntityRepository $paymentMethodSalesChannelRepository, - private readonly Connection $connection + private readonly Connection $connection, + private readonly PaymentMethodDefinition $paymentMethodDefinition ) { } @@ -238,6 +241,10 @@ private function upsertPaymentMethod(PaymentMethodInterface $paymentMethod, Cont 'afterOrderEnabled' => \in_array($paymentMethod::class, self::AFTER_ORDER_PAYMENT_METHODS, true), ]; + if ($this->paymentMethodDefinition->getField('technicalName') instanceof Field) { + $data['technicalName'] = $paymentMethod->getTechnicalName(); + } + // Find existing payment method by ID for update / install decision $paymentMethodEntity = $this->findPaymentMethodEntity($paymentMethod->getId(), $context); diff --git a/src/PaymentMethod/AbstractPaymentMethod.php b/src/PaymentMethod/AbstractPaymentMethod.php index 5ca76cf90..800ce197e 100644 --- a/src/PaymentMethod/AbstractPaymentMethod.php +++ b/src/PaymentMethod/AbstractPaymentMethod.php @@ -54,4 +54,9 @@ public function getPosition(): int { return $this->position; } + + final public function getTechnicalName(): string + { + return \constant(static::class . '::TECHNICAL_NAME'); + } } diff --git a/src/PaymentMethod/PaymentMethodInterface.php b/src/PaymentMethod/PaymentMethodInterface.php index 83bd1fa23..8d452dff3 100644 --- a/src/PaymentMethod/PaymentMethodInterface.php +++ b/src/PaymentMethod/PaymentMethodInterface.php @@ -19,4 +19,6 @@ public function getTemplate(): ?string; public function getTranslations(): array; public function getPosition(): int; + + public function getTechnicalName(): string; } diff --git a/src/PaymentMethod/PayoneAlipay.php b/src/PaymentMethod/PayoneAlipay.php index 95a2befc2..4ef19a450 100644 --- a/src/PaymentMethod/PayoneAlipay.php +++ b/src/PaymentMethod/PayoneAlipay.php @@ -11,6 +11,8 @@ class PayoneAlipay extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_alipay'; + protected string $id = self::UUID; protected string $name = 'PAYONE Alipay'; diff --git a/src/PaymentMethod/PayoneAmazonPay.php b/src/PaymentMethod/PayoneAmazonPay.php index ca585ed0a..984b4a033 100644 --- a/src/PaymentMethod/PayoneAmazonPay.php +++ b/src/PaymentMethod/PayoneAmazonPay.php @@ -11,6 +11,8 @@ class PayoneAmazonPay extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_amazon_pay'; + protected string $id = self::UUID; protected string $name = 'PAYONE Amazon Pay'; diff --git a/src/PaymentMethod/PayoneAmazonPayExpress.php b/src/PaymentMethod/PayoneAmazonPayExpress.php index 5a461765b..0e767f247 100644 --- a/src/PaymentMethod/PayoneAmazonPayExpress.php +++ b/src/PaymentMethod/PayoneAmazonPayExpress.php @@ -12,6 +12,8 @@ class PayoneAmazonPayExpress extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_amazon_pay_express'; + protected string $id = self::UUID; protected string $name = 'PAYONE Amazon Pay Express'; diff --git a/src/PaymentMethod/PayoneApplePay.php b/src/PaymentMethod/PayoneApplePay.php index afbc4d519..b328d5823 100644 --- a/src/PaymentMethod/PayoneApplePay.php +++ b/src/PaymentMethod/PayoneApplePay.php @@ -11,6 +11,8 @@ class PayoneApplePay extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_apple_pay'; + protected string $id = self::UUID; protected string $name = 'PAYONE Apple Pay'; diff --git a/src/PaymentMethod/PayoneBancontact.php b/src/PaymentMethod/PayoneBancontact.php index 255eef1d9..7b62ff05d 100644 --- a/src/PaymentMethod/PayoneBancontact.php +++ b/src/PaymentMethod/PayoneBancontact.php @@ -11,6 +11,8 @@ class PayoneBancontact extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_bancontact'; + protected string $id = self::UUID; protected string $name = 'PAYONE Bancontact'; diff --git a/src/PaymentMethod/PayoneCreditCard.php b/src/PaymentMethod/PayoneCreditCard.php index 3f2600a64..747dd9c6d 100644 --- a/src/PaymentMethod/PayoneCreditCard.php +++ b/src/PaymentMethod/PayoneCreditCard.php @@ -11,6 +11,8 @@ class PayoneCreditCard extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_creditcard'; + protected string $id = self::UUID; protected string $name = 'PAYONE Credit Card'; diff --git a/src/PaymentMethod/PayoneDebit.php b/src/PaymentMethod/PayoneDebit.php index 16a9deb0f..dd0559302 100644 --- a/src/PaymentMethod/PayoneDebit.php +++ b/src/PaymentMethod/PayoneDebit.php @@ -11,6 +11,8 @@ class PayoneDebit extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_debit'; + protected string $id = self::UUID; protected string $name = 'PAYONE Lastschrift'; diff --git a/src/PaymentMethod/PayoneEps.php b/src/PaymentMethod/PayoneEps.php index 661680816..cdd375ceb 100644 --- a/src/PaymentMethod/PayoneEps.php +++ b/src/PaymentMethod/PayoneEps.php @@ -11,6 +11,8 @@ class PayoneEps extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_eps'; + protected string $id = self::UUID; protected string $name = 'PAYONE eps'; diff --git a/src/PaymentMethod/PayoneIDeal.php b/src/PaymentMethod/PayoneIDeal.php index fe725c9ea..d8a205855 100644 --- a/src/PaymentMethod/PayoneIDeal.php +++ b/src/PaymentMethod/PayoneIDeal.php @@ -11,6 +11,8 @@ class PayoneIDeal extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_ideal'; + protected string $id = self::UUID; protected string $name = 'PAYONE iDEAL'; diff --git a/src/PaymentMethod/PayoneKlarnaDirectDebit.php b/src/PaymentMethod/PayoneKlarnaDirectDebit.php index 9a29893ac..f6c2efca1 100644 --- a/src/PaymentMethod/PayoneKlarnaDirectDebit.php +++ b/src/PaymentMethod/PayoneKlarnaDirectDebit.php @@ -11,6 +11,8 @@ class PayoneKlarnaDirectDebit extends AbstractPayoneKlarna { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_klarna_direct_debit'; + protected string $id = self::UUID; protected string $name = 'PAYONE Klarna Sofort bezahlen'; // do not replace this by an english wording. (this is the product name) diff --git a/src/PaymentMethod/PayoneKlarnaInstallment.php b/src/PaymentMethod/PayoneKlarnaInstallment.php index cdf5cf894..40bb148b6 100644 --- a/src/PaymentMethod/PayoneKlarnaInstallment.php +++ b/src/PaymentMethod/PayoneKlarnaInstallment.php @@ -11,6 +11,8 @@ class PayoneKlarnaInstallment extends AbstractPayoneKlarna { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_klarna_installment'; + protected string $id = self::UUID; protected string $name = 'PAYONE Klarna Ratenkauf'; // do not replace this by an english wording. (this is the product name) diff --git a/src/PaymentMethod/PayoneKlarnaInvoice.php b/src/PaymentMethod/PayoneKlarnaInvoice.php index 3c5c1286c..c07db10d2 100644 --- a/src/PaymentMethod/PayoneKlarnaInvoice.php +++ b/src/PaymentMethod/PayoneKlarnaInvoice.php @@ -11,6 +11,8 @@ class PayoneKlarnaInvoice extends AbstractPayoneKlarna { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_klarna_invoice'; + protected string $id = self::UUID; protected string $name = 'PAYONE Klarna Rechnung'; // do not replace this by an english wording. (this is the product name) diff --git a/src/PaymentMethod/PayoneOpenInvoice.php b/src/PaymentMethod/PayoneOpenInvoice.php index e3c4f956c..7a7334588 100644 --- a/src/PaymentMethod/PayoneOpenInvoice.php +++ b/src/PaymentMethod/PayoneOpenInvoice.php @@ -11,6 +11,8 @@ class PayoneOpenInvoice extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_open_invoice'; + protected string $id = self::UUID; protected string $name = 'PAYONE Invoice'; diff --git a/src/PaymentMethod/PayonePaydirekt.php b/src/PaymentMethod/PayonePaydirekt.php index 82ecc7cba..3ae6a3a2d 100644 --- a/src/PaymentMethod/PayonePaydirekt.php +++ b/src/PaymentMethod/PayonePaydirekt.php @@ -11,6 +11,8 @@ class PayonePaydirekt extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_paydirekt'; + protected string $id = self::UUID; protected string $name = 'PAYONE paydirekt'; diff --git a/src/PaymentMethod/PayonePayolutionDebit.php b/src/PaymentMethod/PayonePayolutionDebit.php index 40f2c663a..c9e99c45f 100644 --- a/src/PaymentMethod/PayonePayolutionDebit.php +++ b/src/PaymentMethod/PayonePayolutionDebit.php @@ -11,6 +11,8 @@ class PayonePayolutionDebit extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_unzer_debit'; + protected string $id = self::UUID; protected string $name = 'PAYONE Unzer Lastschrift'; diff --git a/src/PaymentMethod/PayonePayolutionInstallment.php b/src/PaymentMethod/PayonePayolutionInstallment.php index c57bd9f58..bf0746005 100644 --- a/src/PaymentMethod/PayonePayolutionInstallment.php +++ b/src/PaymentMethod/PayonePayolutionInstallment.php @@ -11,6 +11,8 @@ class PayonePayolutionInstallment extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_unzer_installment'; + protected string $id = self::UUID; protected string $name = 'PAYONE Unzer Ratenkauf'; diff --git a/src/PaymentMethod/PayonePayolutionInvoicing.php b/src/PaymentMethod/PayonePayolutionInvoicing.php index 57f5713f3..1652d8e95 100644 --- a/src/PaymentMethod/PayonePayolutionInvoicing.php +++ b/src/PaymentMethod/PayonePayolutionInvoicing.php @@ -11,6 +11,8 @@ class PayonePayolutionInvoicing extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_unzer_invoice'; + protected string $id = self::UUID; protected string $name = 'PAYONE Unzer Rechnungskauf'; diff --git a/src/PaymentMethod/PayonePaypal.php b/src/PaymentMethod/PayonePaypal.php index be0a70788..bd5bf9ff2 100644 --- a/src/PaymentMethod/PayonePaypal.php +++ b/src/PaymentMethod/PayonePaypal.php @@ -11,6 +11,8 @@ class PayonePaypal extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_paypal'; + protected string $id = self::UUID; protected string $name = 'PAYONE PayPal'; diff --git a/src/PaymentMethod/PayonePaypalExpress.php b/src/PaymentMethod/PayonePaypalExpress.php index 73188b16d..9d19d5491 100644 --- a/src/PaymentMethod/PayonePaypalExpress.php +++ b/src/PaymentMethod/PayonePaypalExpress.php @@ -11,6 +11,8 @@ class PayonePaypalExpress extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_paypal_express'; + protected string $id = self::UUID; protected string $name = 'PAYONE Paypal Express'; diff --git a/src/PaymentMethod/PayonePostfinanceCard.php b/src/PaymentMethod/PayonePostfinanceCard.php index 0cb0ed7b4..1facc6d28 100644 --- a/src/PaymentMethod/PayonePostfinanceCard.php +++ b/src/PaymentMethod/PayonePostfinanceCard.php @@ -11,6 +11,8 @@ class PayonePostfinanceCard extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_postfinance_card'; + protected string $id = self::UUID; protected string $name = 'PAYONE Postfinance (Card)'; diff --git a/src/PaymentMethod/PayonePostfinanceWallet.php b/src/PaymentMethod/PayonePostfinanceWallet.php index 321171cdd..e4282ff81 100644 --- a/src/PaymentMethod/PayonePostfinanceWallet.php +++ b/src/PaymentMethod/PayonePostfinanceWallet.php @@ -11,6 +11,8 @@ class PayonePostfinanceWallet extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_postfinance_wallet'; + protected string $id = self::UUID; protected string $name = 'PAYONE Postfinance (Wallet)'; diff --git a/src/PaymentMethod/PayonePrepayment.php b/src/PaymentMethod/PayonePrepayment.php index 2889ecc32..f16c67c6b 100644 --- a/src/PaymentMethod/PayonePrepayment.php +++ b/src/PaymentMethod/PayonePrepayment.php @@ -11,6 +11,8 @@ class PayonePrepayment extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_prepayment'; + protected string $id = self::UUID; protected string $name = 'PAYONE Prepayment'; diff --git a/src/PaymentMethod/PayonePrzelewy24.php b/src/PaymentMethod/PayonePrzelewy24.php index 1d384aa94..e7206eb8b 100644 --- a/src/PaymentMethod/PayonePrzelewy24.php +++ b/src/PaymentMethod/PayonePrzelewy24.php @@ -11,6 +11,8 @@ class PayonePrzelewy24 extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_przelewy24'; + protected string $id = self::UUID; protected string $name = 'PAYONE Przelewy24'; diff --git a/src/PaymentMethod/PayoneRatepayDebit.php b/src/PaymentMethod/PayoneRatepayDebit.php index c1f401e80..d3a0d35ab 100644 --- a/src/PaymentMethod/PayoneRatepayDebit.php +++ b/src/PaymentMethod/PayoneRatepayDebit.php @@ -11,6 +11,8 @@ class PayoneRatepayDebit extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_ratepay_debit'; + protected string $id = self::UUID; protected string $name = 'PAYONE Ratepay Direct Debit'; diff --git a/src/PaymentMethod/PayoneRatepayInstallment.php b/src/PaymentMethod/PayoneRatepayInstallment.php index a67ce67ff..b5bd60f48 100644 --- a/src/PaymentMethod/PayoneRatepayInstallment.php +++ b/src/PaymentMethod/PayoneRatepayInstallment.php @@ -11,6 +11,8 @@ class PayoneRatepayInstallment extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_ratepay_installment'; + protected string $id = self::UUID; protected string $name = 'PAYONE Ratepay Installments'; diff --git a/src/PaymentMethod/PayoneRatepayInvoicing.php b/src/PaymentMethod/PayoneRatepayInvoicing.php index 8eb063c78..fc6d03242 100644 --- a/src/PaymentMethod/PayoneRatepayInvoicing.php +++ b/src/PaymentMethod/PayoneRatepayInvoicing.php @@ -11,6 +11,8 @@ class PayoneRatepayInvoicing extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_ratepay_invoice'; + protected string $id = self::UUID; protected string $name = 'PAYONE Ratepay Open Invoice'; diff --git a/src/PaymentMethod/PayoneSecureInvoice.php b/src/PaymentMethod/PayoneSecureInvoice.php index 7dbf3eace..1dc3d8b5d 100644 --- a/src/PaymentMethod/PayoneSecureInvoice.php +++ b/src/PaymentMethod/PayoneSecureInvoice.php @@ -10,6 +10,9 @@ class PayoneSecureInvoice extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + + final public const TECHNICAL_NAME = 'payone_secure_invoice'; + final public const BUSINESSRELATION_B2B = 'b2b'; final public const BUSINESSRELATION_B2C = 'b2c'; diff --git a/src/PaymentMethod/PayoneSecuredDirectDebit.php b/src/PaymentMethod/PayoneSecuredDirectDebit.php index 4c72fe097..46090b889 100644 --- a/src/PaymentMethod/PayoneSecuredDirectDebit.php +++ b/src/PaymentMethod/PayoneSecuredDirectDebit.php @@ -11,6 +11,8 @@ class PayoneSecuredDirectDebit extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_secured_direct_debit'; + protected string $id = self::UUID; protected string $name = 'PAYONE Secured Direct Debit'; diff --git a/src/PaymentMethod/PayoneSecuredInstallment.php b/src/PaymentMethod/PayoneSecuredInstallment.php index beb2265fc..6a0cb7c29 100644 --- a/src/PaymentMethod/PayoneSecuredInstallment.php +++ b/src/PaymentMethod/PayoneSecuredInstallment.php @@ -11,6 +11,8 @@ class PayoneSecuredInstallment extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_secured_installment'; + protected string $id = self::UUID; protected string $name = 'PAYONE Secured Installment'; diff --git a/src/PaymentMethod/PayoneSecuredInvoice.php b/src/PaymentMethod/PayoneSecuredInvoice.php index 297b21b6a..81387d26e 100644 --- a/src/PaymentMethod/PayoneSecuredInvoice.php +++ b/src/PaymentMethod/PayoneSecuredInvoice.php @@ -11,6 +11,8 @@ class PayoneSecuredInvoice extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_secured_invoice'; + protected string $id = self::UUID; protected string $name = 'PAYONE Secured Invoice'; diff --git a/src/PaymentMethod/PayoneSofortBanking.php b/src/PaymentMethod/PayoneSofortBanking.php index b9918879d..59fe4c133 100644 --- a/src/PaymentMethod/PayoneSofortBanking.php +++ b/src/PaymentMethod/PayoneSofortBanking.php @@ -14,6 +14,8 @@ class PayoneSofortBanking extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_sofort'; + protected string $id = self::UUID; protected string $name = 'PAYONE Sofort'; diff --git a/src/PaymentMethod/PayoneTrustly.php b/src/PaymentMethod/PayoneTrustly.php index f0648506f..5610438f0 100644 --- a/src/PaymentMethod/PayoneTrustly.php +++ b/src/PaymentMethod/PayoneTrustly.php @@ -11,6 +11,8 @@ class PayoneTrustly extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_trustly'; + protected string $id = self::UUID; protected string $name = 'PAYONE Trustly'; diff --git a/src/PaymentMethod/PayoneWeChatPay.php b/src/PaymentMethod/PayoneWeChatPay.php index 2eaf9b3e9..5cc17a594 100644 --- a/src/PaymentMethod/PayoneWeChatPay.php +++ b/src/PaymentMethod/PayoneWeChatPay.php @@ -11,6 +11,8 @@ class PayoneWeChatPay extends AbstractPaymentMethod { final public const UUID = PaymentMethodInstaller::PAYMENT_METHOD_IDS[self::class]; + final public const TECHNICAL_NAME = 'payone_wechat'; + protected string $id = self::UUID; protected string $name = 'PAYONE WeChat Pay'; diff --git a/src/PayonePayment.php b/src/PayonePayment.php index c400b752a..25175b4cb 100644 --- a/src/PayonePayment.php +++ b/src/PayonePayment.php @@ -9,6 +9,7 @@ use PayonePayment\Installer\CustomFieldInstaller; use PayonePayment\Installer\PaymentMethodInstaller; use PayonePayment\Installer\RuleInstaller\RuleInstallerSecureInvoice; +use Shopware\Core\Checkout\Payment\PaymentMethodDefinition; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\Plugin; use Shopware\Core\Framework\Plugin\Context\ActivateContext; @@ -177,13 +178,16 @@ private function getPaymentMethodInstaller(): PaymentMethodInstaller $paymentMethodSalesChannelRepository = $this->container->get('sales_channel_payment_method.repository'); /** @var Connection $connection */ $connection = $this->container->get(Connection::class); + /** @var PaymentMethodDefinition $paymentMethodDefinition */ + $paymentMethodDefinition = $this->container->get(PaymentMethodDefinition::class); return new PaymentMethodInstaller( $pluginIdProvider, $paymentMethodRepository, $salesChannelRepository, $paymentMethodSalesChannelRepository, - $connection + $connection, + $paymentMethodDefinition ); } diff --git a/tests/Integration/PaymentMethod/PaymentMethodTest.php b/tests/Integration/PaymentMethod/PaymentMethodTest.php index 864ab0593..28ddd5b74 100644 --- a/tests/Integration/PaymentMethod/PaymentMethodTest.php +++ b/tests/Integration/PaymentMethod/PaymentMethodTest.php @@ -11,14 +11,36 @@ class PaymentMethodTest extends TestCase { - public function testSameUuid(): void + public function testIfUuidIsSetAndUnique(): void { + $idMapping = []; foreach (ClassHelper::getPaymentMethodClasses() as $class) { /** @var AbstractPaymentMethod $instance */ $instance = new $class(); static::assertInstanceOf(PaymentMethodInterface::class, $instance); - // test if UUID is the same as $id - static::assertEquals(\constant($class . '::UUID'), $instance->getId(), sprintf('%s needs to be the same values as %s', $class . '::$id', $class . '::UUID')); + + $id = \constant($class . '::UUID'); + static::assertNotNull($id, 'id for ' . $class . ' should not be null.'); + static::assertEquals($id, $instance->getId(), sprintf('%s needs to be the same values as %s', $class . '::$id', $class . '::UUID')); + static::assertArrayNotHasKey($instance->getId(), $idMapping, 'id for ' . $class . ' does already exist for payment method ' . ($idMapping[$instance->getId()] ?? null)); + $idMapping[$instance->getId()] = $class; + } + } + + public function testIfTechnicalNameIsSetAndUnique(): void + { + $technicalMapping = []; + foreach (ClassHelper::getPaymentMethodClasses() as $class) { + /** @var AbstractPaymentMethod $instance */ + $instance = new $class(); + static::assertInstanceOf(PaymentMethodInterface::class, $instance); + + $technicalName = \constant($class . '::TECHNICAL_NAME'); + static::assertNotNull($technicalName, 'technical name for ' . $class . ' should not be null.'); + static::assertEquals($technicalName, $instance->getTechnicalName(), 'method ' . $class . '::getTechnicalName should return the same value as ' . $class . '::TECHNICAL_NAME'); + static::assertStringStartsWith('payone_', $technicalName, 'technical-name for ' . $class . ' should start with `payone_`'); + static::assertArrayNotHasKey($technicalName, $technicalMapping, 'technical.name for ' . $class . ' does already exist for payment method ' . ($technicalMapping[$technicalName] ?? null)); + $technicalMapping[$technicalName] = $class; } } } From ef2b33a98092fefa4c378949f97d44a25fe1573f Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Thu, 4 Apr 2024 13:17:49 +0200 Subject: [PATCH 04/45] PAYOSWXP-125: replace payment-exceptions --- .../CartHasher/CartHasherInterface.php | 5 -- ...ctGenericExpressCheckoutPaymentHandler.php | 21 ++++-- .../PaymentStateHandler.php | 36 +++++----- .../PaymentStateHandlerInterface.php | 2 +- ...stractAsynchronousPayonePaymentHandler.php | 22 ++++-- .../AbstractKlarnaPaymentHandler.php | 2 +- .../AbstractPayonePaymentHandler.php | 2 + ...bstractSynchronousPayonePaymentHandler.php | 22 ++++-- .../PayoneApplePayPaymentHandler.php | 4 +- .../PayoneCreditCardPaymentHandler.php | 3 +- .../PayonePaypalPaymentHandler.php | 3 +- .../AbstractRequestParameterBuilder.php | 16 ++++- .../CaptureRequestParameterBuilder.php | 7 +- .../Refund/RefundRequestParameterBuilder.php | 8 +-- .../AuthorizeRequestParameterBuilder.php | 18 ++++- .../PaymentStateHandlerTest.php | 69 +++++++++++++++++++ .../AbstractKlarnaPaymentHandlerTest.php | 11 +-- .../AbstractPaymentHandlerTest.php | 38 ++++------ .../CaptureRequestParameterBuilderTest.php | 22 +++++- .../RefundRequestParameterBuilderTest.php | 22 +++++- .../PaymentHandler/PaymentHandlerMock.php | 16 +++++ 21 files changed, 258 insertions(+), 91 deletions(-) create mode 100644 tests/Components/PaymentStateHandler/PaymentStateHandlerTest.php diff --git a/src/Components/CartHasher/CartHasherInterface.php b/src/Components/CartHasher/CartHasherInterface.php index 2ff695037..d4397a0d9 100644 --- a/src/Components/CartHasher/CartHasherInterface.php +++ b/src/Components/CartHasher/CartHasherInterface.php @@ -8,8 +8,6 @@ use Shopware\Core\Checkout\Order\OrderEntity; use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; use Shopware\Core\Checkout\Payment\Cart\SyncPaymentTransactionStruct; -use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; -use Shopware\Core\Checkout\Payment\Exception\SyncPaymentProcessException; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Shopware\Core\System\SalesChannel\SalesChannelContext; @@ -20,9 +18,6 @@ public function generate(Cart|OrderEntity $entity, SalesChannelContext $context) public function validate(Cart|OrderEntity $entity, string $cartHash, SalesChannelContext $context): bool; - /** - * @throws AsyncPaymentProcessException|SyncPaymentProcessException - */ public function validateRequest( RequestDataBag $requestDataBag, AsyncPaymentTransactionStruct|SyncPaymentTransactionStruct $paymentTransaction, diff --git a/src/Components/GenericExpressCheckout/PaymentHandler/AbstractGenericExpressCheckoutPaymentHandler.php b/src/Components/GenericExpressCheckout/PaymentHandler/AbstractGenericExpressCheckoutPaymentHandler.php index 04448d314..e9e4e181a 100644 --- a/src/Components/GenericExpressCheckout/PaymentHandler/AbstractGenericExpressCheckoutPaymentHandler.php +++ b/src/Components/GenericExpressCheckout/PaymentHandler/AbstractGenericExpressCheckoutPaymentHandler.php @@ -9,6 +9,7 @@ use PayonePayment\Struct\PaymentTransaction; use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; +use Shopware\Core\Checkout\Payment\PaymentException; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -42,10 +43,22 @@ protected function handleResponse( SalesChannelContext $salesChannelContext ): void { if (empty($response['status']) || $response['status'] === 'ERROR') { - throw new AsyncPaymentProcessException( - $transaction->getOrderTransaction()->getId(), - $this->translator->trans('PayonePayment.errorMessages.genericError') - ); + if (class_exists(PaymentException::class)) { + throw PaymentException::asyncProcessInterrupted( + $transaction->getOrderTransaction()->getId(), + $this->translator->trans('PayonePayment.errorMessages.genericError') + ); + } elseif (class_exists(AsyncPaymentProcessException::class)) { + // required for shopware version <= 6.5.3 + // @phpstan-ignore-next-line + throw new AsyncPaymentProcessException( + $transaction->getOrderTransaction()->getId(), + $this->translator->trans('PayonePayment.errorMessages.genericError') + ); + } + + // should never occur. Just to be safe. + throw new \RuntimeException('payment process interrupted.'); } $data = $this->preparePayoneOrderTransactionData($request, $response, [ diff --git a/src/Components/PaymentStateHandler/PaymentStateHandler.php b/src/Components/PaymentStateHandler/PaymentStateHandler.php index 62b8c59d1..be1e3466a 100644 --- a/src/Components/PaymentStateHandler/PaymentStateHandler.php +++ b/src/Components/PaymentStateHandler/PaymentStateHandler.php @@ -7,6 +7,7 @@ use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentFinalizeException; use Shopware\Core\Checkout\Payment\Exception\CustomerCanceledAsyncPaymentException; +use Shopware\Core\Checkout\Payment\PaymentException; use Symfony\Contracts\Translation\TranslatorInterface; class PaymentStateHandler implements PaymentStateHandlerInterface @@ -15,27 +16,30 @@ public function __construct(private readonly TranslatorInterface $translator) { } - public function handleStateResponse(AsyncPaymentTransactionStruct $transaction, string $state): void + public function handleStateResponse(AsyncPaymentTransactionStruct $transaction, string|null $state): void { - if (empty($state)) { - throw new AsyncPaymentFinalizeException( - $transaction->getOrderTransaction()->getId(), - $this->translator->trans('PayonePayment.errorMessages.genericError') - ); + if (empty($state) || $state === 'error') { + if (class_exists(PaymentException::class)) { + throw PaymentException::asyncFinalizeInterrupted($transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError')); + } elseif (class_exists(AsyncPaymentFinalizeException::class)) { + // required for shopware version <= 6.5.3 + throw new AsyncPaymentFinalizeException($transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError')); // @phpstan-ignore-line + } + + // should never occur, just to be safe. - this will lead into a fatal error. The user can not keep going with processing the order. + throw new \RuntimeException('payment finalize was interrupted ' . $transaction->getOrderTransaction()->getId()); } if ($state === 'cancel') { - throw new CustomerCanceledAsyncPaymentException( - $transaction->getOrderTransaction()->getId(), - '' - ); - } + if (class_exists(PaymentException::class)) { + throw PaymentException::customerCanceled($transaction->getOrderTransaction()->getId(), ''); + } elseif (class_exists(CustomerCanceledAsyncPaymentException::class)) { + // required for shopware version <= 6.5.3 + throw new CustomerCanceledAsyncPaymentException($transaction->getOrderTransaction()->getId(), ''); // @phpstan-ignore-line + } - if ($state === 'error') { - throw new AsyncPaymentFinalizeException( - $transaction->getOrderTransaction()->getId(), - $this->translator->trans('PayonePayment.errorMessages.genericError') - ); + // should never occur, just to be safe. - this will lead into a fatal error. The user can not keep going with processing the order. + throw new \RuntimeException('payment was canceled by the customer ' . $transaction->getOrderTransaction()->getId()); } } } diff --git a/src/Components/PaymentStateHandler/PaymentStateHandlerInterface.php b/src/Components/PaymentStateHandler/PaymentStateHandlerInterface.php index 0722663bd..a78af6f66 100644 --- a/src/Components/PaymentStateHandler/PaymentStateHandlerInterface.php +++ b/src/Components/PaymentStateHandler/PaymentStateHandlerInterface.php @@ -8,5 +8,5 @@ interface PaymentStateHandlerInterface { - public function handleStateResponse(AsyncPaymentTransactionStruct $transaction, string $state): void; + public function handleStateResponse(AsyncPaymentTransactionStruct $transaction, string|null $state): void; } diff --git a/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php b/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php index 3d8af01da..6c69e7e20 100644 --- a/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php +++ b/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php @@ -17,6 +17,7 @@ use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\AsynchronousPaymentHandlerInterface; use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; +use Shopware\Core\Checkout\Payment\PaymentException; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Shopware\Core\System\SalesChannel\SalesChannelContext; @@ -52,7 +53,7 @@ public function pay( } catch (PayoneRequestException) { $this->beforeException(); - throw new AsyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); @@ -81,14 +82,14 @@ public function pay( } catch (PayoneRequestException $exception) { $this->beforeException(); - throw new AsyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $exception->getResponse()['error']['CustomerMessage'] ); } catch (\Throwable) { $this->beforeException(); - throw new AsyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); @@ -141,7 +142,7 @@ protected function handleResponse( SalesChannelContext $salesChannelContext ): void { if (empty($response['status']) || $response['status'] !== 'REDIRECT') { - throw new AsyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); @@ -160,4 +161,17 @@ protected function getRedirectResponse(SalesChannelContext $context, array $requ { return new RedirectResponse($response['redirecturl']); } + + protected function createPaymentException(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): \Throwable + { + if (class_exists(PaymentException::class)) { + return PaymentException::asyncProcessInterrupted($orderTransactionId, $errorMessage, $e); + } elseif (class_exists(AsyncPaymentProcessException::class)) { + // required for shopware version <= 6.5.3 + throw new AsyncPaymentProcessException($orderTransactionId, $errorMessage, $e); // @phpstan-ignore-line + } + + // should never occur, just to be safe. + throw new \RuntimeException('payment process was interrupted ' . $orderTransactionId); + } } diff --git a/src/PaymentHandler/AbstractKlarnaPaymentHandler.php b/src/PaymentHandler/AbstractKlarnaPaymentHandler.php index 192307288..2705cbde3 100644 --- a/src/PaymentHandler/AbstractKlarnaPaymentHandler.php +++ b/src/PaymentHandler/AbstractKlarnaPaymentHandler.php @@ -58,7 +58,7 @@ public function pay( $authToken = $dataBag->get('payoneKlarnaAuthorizationToken'); if (!$authToken) { - throw new AsyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); diff --git a/src/PaymentHandler/AbstractPayonePaymentHandler.php b/src/PaymentHandler/AbstractPayonePaymentHandler.php index b60aed6e5..af3d5e0f6 100644 --- a/src/PaymentHandler/AbstractPayonePaymentHandler.php +++ b/src/PaymentHandler/AbstractPayonePaymentHandler.php @@ -253,4 +253,6 @@ protected function getAdditionalTransactionData(RequestDataBag $dataBag, array $ { return []; } + + abstract protected function createPaymentException(string $orderTransactionId, string $errorMessage, ?\Throwable $e): \Throwable; } diff --git a/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php b/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php index 65e19aa54..5b1a25795 100644 --- a/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php +++ b/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php @@ -16,6 +16,7 @@ use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\SynchronousPaymentHandlerInterface; use Shopware\Core\Checkout\Payment\Cart\SyncPaymentTransactionStruct; use Shopware\Core\Checkout\Payment\Exception\SyncPaymentProcessException; +use Shopware\Core\Checkout\Payment\PaymentException; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Shopware\Core\System\SalesChannel\SalesChannelContext; @@ -48,7 +49,7 @@ public function pay( } catch (PayoneRequestException) { $this->beforeException(); - throw new SyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); @@ -77,14 +78,14 @@ public function pay( } catch (PayoneRequestException $exception) { $this->beforeException(); - throw new SyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $exception->getResponse()['error']['CustomerMessage'] ); } catch (\Throwable) { $this->beforeException(); - throw new SyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); @@ -127,7 +128,7 @@ protected function handleResponse( SalesChannelContext $salesChannelContext ): void { if (empty($response['status']) || $response['status'] === 'ERROR') { - throw new SyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); @@ -141,4 +142,17 @@ protected function handleResponse( $this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); } + + protected function createPaymentException(string $orderTransactionId, string $errorMessage, ?\Throwable $e = null): \Throwable + { + if (class_exists(PaymentException::class)) { + return PaymentException::asyncProcessInterrupted($orderTransactionId, $errorMessage, $e); + } elseif (class_exists(SyncPaymentProcessException::class)) { + // required for shopware version <= 6.5.3 + throw new SyncPaymentProcessException($orderTransactionId, $errorMessage, $e); // @phpstan-ignore-line + } + + // should never occur, just to be safe. + throw new \RuntimeException('payment process was interrupted ' . $orderTransactionId); + } } diff --git a/src/PaymentHandler/PayoneApplePayPaymentHandler.php b/src/PaymentHandler/PayoneApplePayPaymentHandler.php index 2beabe1c4..2e8c713e7 100644 --- a/src/PaymentHandler/PayoneApplePayPaymentHandler.php +++ b/src/PaymentHandler/PayoneApplePayPaymentHandler.php @@ -21,14 +21,14 @@ public function pay( $response = json_decode((string) $dataBag->get('response', '{}'), true, 512, \JSON_THROW_ON_ERROR); if ($response === null || !\array_key_exists('status', $response) || !\array_key_exists('txid', $response)) { - throw new SyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); } if ($response['status'] !== 'APPROVED' && $response['status'] !== 'PENDING') { - throw new SyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); diff --git a/src/PaymentHandler/PayoneCreditCardPaymentHandler.php b/src/PaymentHandler/PayoneCreditCardPaymentHandler.php index a6f7882a0..9045e1828 100644 --- a/src/PaymentHandler/PayoneCreditCardPaymentHandler.php +++ b/src/PaymentHandler/PayoneCreditCardPaymentHandler.php @@ -15,7 +15,6 @@ use PayonePayment\Payone\RequestParameter\RequestParameterFactory; use PayonePayment\Struct\PaymentTransaction; use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; -use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Shopware\Core\System\SalesChannel\SalesChannelContext; @@ -95,7 +94,7 @@ protected function handleResponse( SalesChannelContext $salesChannelContext ): void { if (empty($response['status']) || $response['status'] === 'ERROR') { - throw new AsyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); diff --git a/src/PaymentHandler/PayonePaypalPaymentHandler.php b/src/PaymentHandler/PayonePaypalPaymentHandler.php index 65e1701eb..797a75966 100644 --- a/src/PaymentHandler/PayonePaypalPaymentHandler.php +++ b/src/PaymentHandler/PayonePaypalPaymentHandler.php @@ -7,7 +7,6 @@ use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder; use PayonePayment\Struct\PaymentTransaction; use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; -use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -46,7 +45,7 @@ protected function handleResponse( SalesChannelContext $salesChannelContext ): void { if (empty($response['status']) || $response['status'] === 'ERROR') { - throw new AsyncPaymentProcessException( + throw $this->createPaymentException( $transaction->getOrderTransaction()->getId(), $this->translator->trans('PayonePayment.errorMessages.genericError') ); diff --git a/src/Payone/RequestParameter/Builder/AbstractRequestParameterBuilder.php b/src/Payone/RequestParameter/Builder/AbstractRequestParameterBuilder.php index 09d80594a..65e9cdc55 100644 --- a/src/Payone/RequestParameter/Builder/AbstractRequestParameterBuilder.php +++ b/src/Payone/RequestParameter/Builder/AbstractRequestParameterBuilder.php @@ -7,9 +7,10 @@ use PayonePayment\Installer\CustomFieldInstaller; use PayonePayment\Payone\RequestParameter\Struct\AbstractRequestParameterStruct; use Shopware\Core\Checkout\Order\OrderEntity; +use Shopware\Core\Checkout\Payment\Exception\InvalidOrderException; +use Shopware\Core\Checkout\Payment\PaymentException; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; -use Shopware\Core\Framework\Validation\DataBag\DataBag; use Shopware\Core\System\Currency\CurrencyEntity; use Symfony\Component\HttpFoundation\ParameterBag; @@ -173,4 +174,17 @@ protected function applyBirthdayParameter(OrderEntity $order, array &$parameters $parameters['birthday'] = $birthday->format('Ymd'); } } + + protected function orderNotFoundException(string $orderId): \Throwable + { + if (class_exists(PaymentException::class)) { + return PaymentException::invalidOrder($orderId); + } elseif (class_exists(InvalidOrderException::class)) { + // required for shopware version <= 6.5.3 + throw new InvalidOrderException($orderId); // @phpstan-ignore-line + } + + // should never occur, just to be safe. + throw new \RuntimeException('invalid order ' . $orderId); + } } diff --git a/src/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilder.php b/src/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilder.php index 7bc8b7a1d..8a9d46a3d 100644 --- a/src/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilder.php +++ b/src/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilder.php @@ -18,7 +18,6 @@ use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder; use PayonePayment\Payone\RequestParameter\Struct\AbstractRequestParameterStruct; use PayonePayment\Payone\RequestParameter\Struct\FinancialTransactionStruct; -use Shopware\Core\Checkout\Payment\Exception\InvalidOrderException; use Shopware\Core\System\Currency\CurrencyEntity; class CaptureRequestParameterBuilder extends AbstractRequestParameterBuilder @@ -49,15 +48,15 @@ public function getRequestParameter(AbstractRequestParameterStruct $arguments): } if ($transactionData === null) { - throw new InvalidOrderException($order->getId()); + throw $this->orderNotFoundException($order->getId()); } if ($transactionData->getSequenceNumber() === null) { - throw new InvalidOrderException($order->getId()); + throw $this->orderNotFoundException($order->getId()); } if ($transactionData->getSequenceNumber() < 0) { - throw new InvalidOrderException($order->getId()); + throw $this->orderNotFoundException($order->getId()); } /** @var CurrencyEntity $currency */ diff --git a/src/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilder.php b/src/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilder.php index fec4ff4ba..f4f89ef99 100644 --- a/src/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilder.php +++ b/src/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilder.php @@ -32,7 +32,7 @@ public function getRequestParameter(AbstractRequestParameterStruct $arguments): $transactionData = $arguments->getPaymentTransaction()->getOrderTransaction()->getExtension(PayonePaymentOrderTransactionExtension::NAME); if ($transactionData === null) { - throw new InvalidOrderException($order->getId()); + throw $this->orderNotFoundException($order->getId()); } if ($totalAmount === null) { @@ -40,15 +40,15 @@ public function getRequestParameter(AbstractRequestParameterStruct $arguments): } if (empty($transactionData->getTransactionId())) { - throw new InvalidOrderException($order->getId()); + throw $this->orderNotFoundException($order->getId()); } if ($transactionData->getSequenceNumber() === null) { - throw new InvalidOrderException($order->getId()); + throw $this->orderNotFoundException($order->getId()); } if ($transactionData->getSequenceNumber() < 0) { - throw new InvalidOrderException($order->getId()); + throw $this->orderNotFoundException($order->getId()); } //TODO: fix set refunded amount diff --git a/src/Payone/RequestParameter/Builder/Trustly/AuthorizeRequestParameterBuilder.php b/src/Payone/RequestParameter/Builder/Trustly/AuthorizeRequestParameterBuilder.php index 547b33229..d3f072d42 100644 --- a/src/Payone/RequestParameter/Builder/Trustly/AuthorizeRequestParameterBuilder.php +++ b/src/Payone/RequestParameter/Builder/Trustly/AuthorizeRequestParameterBuilder.php @@ -10,6 +10,7 @@ use PayonePayment\Payone\RequestParameter\Struct\PaymentTransactionStruct; use PayonePayment\Struct\PaymentTransaction; use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; +use Shopware\Core\Checkout\Payment\PaymentException; use Symfony\Component\HttpFoundation\ParameterBag; class AuthorizeRequestParameterBuilder extends AbstractRequestParameterBuilder @@ -48,7 +49,22 @@ private function validateIbanRequestParameter(ParameterBag $dataBag, PaymentTran $iban = $dataBag->get('iban'); if (empty($iban) || !\is_string($iban)) { - throw new AsyncPaymentProcessException($transaction->getOrderTransaction()->getId(), 'Missing iban parameter.'); + if (class_exists(PaymentException::class)) { + throw PaymentException::asyncProcessInterrupted( + $transaction->getOrderTransaction()->getId(), + 'Missing iban parameter.' + ); + } elseif (class_exists(AsyncPaymentProcessException::class)) { + // required for shopware version <= 6.5.3 + // @phpstan-ignore-next-line + throw new AsyncPaymentProcessException( + $transaction->getOrderTransaction()->getId(), + 'Missing iban parameter.' + ); + } + + // should never occur. Just to be safe. + throw new \RuntimeException('payment process interrupted. Missing iban parameter.'); } return $iban; diff --git a/tests/Components/PaymentStateHandler/PaymentStateHandlerTest.php b/tests/Components/PaymentStateHandler/PaymentStateHandlerTest.php new file mode 100644 index 000000000..97dae504e --- /dev/null +++ b/tests/Components/PaymentStateHandler/PaymentStateHandlerTest.php @@ -0,0 +1,69 @@ +createMock(Translator::class)); + + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } elseif (class_exists(CustomerCanceledAsyncPaymentException::class)) { + $this->expectException(CustomerCanceledAsyncPaymentException::class); + } else { + throw new \Exception('neither PaymentException nor CustomerCanceledAsyncPaymentException does exist.'); + } + + $handler->handleStateResponse($this->createTransactionStruct(), 'cancel'); + } + + /** + * @dataProvider exceptionGotThrownOnErrorDataProvider + */ + public function testIfExceptionGotThrownOnError(string|null $state): void + { + $handler = new PaymentStateHandler($this->createMock(Translator::class)); + + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } elseif (class_exists(AsyncPaymentFinalizeException::class)) { + $this->expectException(AsyncPaymentFinalizeException::class); + } else { + throw new \Exception('neither PaymentException nor AsyncPaymentFinalizeException does exist.'); + } + + $handler->handleStateResponse($this->createTransactionStruct(), $state); + } + + public static function exceptionGotThrownOnErrorDataProvider(): array + { + return [ + [null], + ['error'], + ]; + } + + private function createTransactionStruct(): AsyncPaymentTransactionStruct + { + $mock = $this->createMock(AsyncPaymentTransactionStruct::class); + + $orderTransaction = $this->createMock(OrderTransactionEntity::class); + $orderTransaction->method('getId')->willReturn(Uuid::randomHex()); + $mock->method('getOrderTransaction')->willReturn($orderTransaction); + + return $mock; + } +} diff --git a/tests/PaymentHandler/AbstractKlarnaPaymentHandlerTest.php b/tests/PaymentHandler/AbstractKlarnaPaymentHandlerTest.php index 3e1ae8692..3b526a848 100644 --- a/tests/PaymentHandler/AbstractKlarnaPaymentHandlerTest.php +++ b/tests/PaymentHandler/AbstractKlarnaPaymentHandlerTest.php @@ -13,9 +13,6 @@ use PayonePayment\Payone\Client\PayoneClientInterface; use PayonePayment\Payone\RequestParameter\RequestParameterFactory; use Shopware\Core\Checkout\Order\OrderEntity; -use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\AsynchronousPaymentHandlerInterface; -use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; -use Shopware\Core\Checkout\Payment\Exception\SyncPaymentProcessException; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -39,13 +36,7 @@ public function testItThrowsExceptionOnMissingToken(): void $paymentHandler::class ); - if ($paymentHandler instanceof AsynchronousPaymentHandlerInterface) { - $expectedException = AsyncPaymentProcessException::class; - } else { - $expectedException = SyncPaymentProcessException::class; - } - - $this->expectException($expectedException); + $this->expectedPaymentInterruptedException($paymentHandler); $this->performPayment($paymentHandler, $paymentTransaction, $dataBag, $salesChannelContext); } diff --git a/tests/PaymentHandler/AbstractPaymentHandlerTest.php b/tests/PaymentHandler/AbstractPaymentHandlerTest.php index 4d639510d..7408f9feb 100644 --- a/tests/PaymentHandler/AbstractPaymentHandlerTest.php +++ b/tests/PaymentHandler/AbstractPaymentHandlerTest.php @@ -20,6 +20,7 @@ use Shopware\Core\Checkout\Payment\Cart\SyncPaymentTransactionStruct; use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; use Shopware\Core\Checkout\Payment\Exception\SyncPaymentProcessException; +use Shopware\Core\Checkout\Payment\PaymentException; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; use Shopware\Core\System\SalesChannel\SalesChannelContext; @@ -98,14 +99,21 @@ public function testItThrowsExceptionOnErrorStatus(): void $paymentHandler::class ); + $this->expectedPaymentInterruptedException($paymentHandler); + $this->performPayment($paymentHandler, $paymentTransaction, $dataBag, $salesChannelContext); + } + + protected function expectedPaymentInterruptedException(AbstractPayonePaymentHandler $paymentHandler) + { if ($paymentHandler instanceof AsynchronousPaymentHandlerInterface) { - $expectedException = AsyncPaymentProcessException::class; + $expectedException = class_exists(AsyncPaymentProcessException::class) ? AsyncPaymentProcessException::class : PaymentException::class; + } else if ($paymentHandler instanceof SynchronousPaymentHandlerInterface) { + $expectedException = class_exists(SyncPaymentProcessException::class) ? SyncPaymentProcessException::class : PaymentException::class; } else { - $expectedException = SyncPaymentProcessException::class; + throw new \RuntimeException('invalid payment handler ' . $paymentHandler::class); } $this->expectException($expectedException); - $this->performPayment($paymentHandler, $paymentTransaction, $dataBag, $salesChannelContext); } public function testItThrowsExceptionOnInvalidStatus(): void @@ -128,13 +136,7 @@ public function testItThrowsExceptionOnInvalidStatus(): void $paymentHandler::class ); - if ($paymentHandler instanceof AsynchronousPaymentHandlerInterface) { - $expectedException = AsyncPaymentProcessException::class; - } else { - $expectedException = SyncPaymentProcessException::class; - } - - $this->expectException($expectedException); + $this->expectedPaymentInterruptedException($paymentHandler); $this->performPayment($paymentHandler, $paymentTransaction, $dataBag, $salesChannelContext); } @@ -170,13 +172,7 @@ public function testItHandlesPayoneExceptionsCorrectly(): void $paymentHandler::class ); - if ($paymentHandler instanceof AsynchronousPaymentHandlerInterface) { - $expectedException = AsyncPaymentProcessException::class; - } else { - $expectedException = SyncPaymentProcessException::class; - } - - $this->expectException($expectedException); + $this->expectedPaymentInterruptedException($paymentHandler); $this->expectExceptionMessageMatches('/.*test-customer-message.*/'); $this->performPayment($paymentHandler, $paymentTransaction, $dataBag, $salesChannelContext); } @@ -204,13 +200,7 @@ public function testItHandlesRandomThrowableCorrectly(): void $paymentHandler::class ); - if ($paymentHandler instanceof AsynchronousPaymentHandlerInterface) { - $expectedException = AsyncPaymentProcessException::class; - } else { - $expectedException = SyncPaymentProcessException::class; - } - - $this->expectException($expectedException); + $this->expectedPaymentInterruptedException($paymentHandler); $this->performPayment($paymentHandler, $paymentTransaction, $dataBag, $salesChannelContext); } diff --git a/tests/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilderTest.php b/tests/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilderTest.php index db69c1e45..fe58a6e21 100644 --- a/tests/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilderTest.php +++ b/tests/Payone/RequestParameter/Builder/Capture/CaptureRequestParameterBuilderTest.php @@ -17,6 +17,7 @@ use PayonePayment\TestCaseBase\PayoneTestBehavior; use PHPUnit\Framework\TestCase; use Shopware\Core\Checkout\Payment\Exception\InvalidOrderException; +use Shopware\Core\Checkout\Payment\PaymentException; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; /** @@ -107,7 +108,12 @@ public function testItThrowsExceptionOnMissingTransactionData(): void $builder = $this->getContainer()->get(CaptureRequestParameterBuilder::class); $struct->getPaymentTransaction()->getOrderTransaction()->removeExtension(PayonePaymentOrderTransactionExtension::NAME); - $this->expectException(InvalidOrderException::class); + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } else { + $this->expectException(InvalidOrderException::class); + } + $builder->getRequestParameter($struct); } @@ -131,7 +137,12 @@ public function testItThrowsExceptionOnMissingSequenceNumber(): void ]); $struct->getPaymentTransaction()->getOrderTransaction()->addExtension(PayonePaymentOrderTransactionExtension::NAME, $extension); - $this->expectException(InvalidOrderException::class); + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } else { + $this->expectException(InvalidOrderException::class); + } + $builder->getRequestParameter($struct); } @@ -155,7 +166,12 @@ public function testItThrowsExceptionOnInvalidSequenceNumber(): void ]); $struct->getPaymentTransaction()->getOrderTransaction()->addExtension(PayonePaymentOrderTransactionExtension::NAME, $extension); - $this->expectException(InvalidOrderException::class); + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } else { + $this->expectException(InvalidOrderException::class); + } + $builder->getRequestParameter($struct); } diff --git a/tests/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilderTest.php b/tests/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilderTest.php index 645b36467..52791c067 100644 --- a/tests/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilderTest.php +++ b/tests/Payone/RequestParameter/Builder/Refund/RefundRequestParameterBuilderTest.php @@ -14,6 +14,7 @@ use PayonePayment\TestCaseBase\PayoneTestBehavior; use PHPUnit\Framework\TestCase; use Shopware\Core\Checkout\Payment\Exception\InvalidOrderException; +use Shopware\Core\Checkout\Payment\PaymentException; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; /** @@ -104,7 +105,12 @@ public function testItThrowsExceptionOnMissingTransactionData(): void $builder = $this->getContainer()->get(RefundRequestParameterBuilder::class); $struct->getPaymentTransaction()->getOrderTransaction()->removeExtension(PayonePaymentOrderTransactionExtension::NAME); - $this->expectException(InvalidOrderException::class); + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } else { + $this->expectException(InvalidOrderException::class); + } + $builder->getRequestParameter($struct); } @@ -128,7 +134,12 @@ public function testItThrowsExceptionOnMissingTransactionId(): void ]); $struct->getPaymentTransaction()->getOrderTransaction()->addExtension(PayonePaymentOrderTransactionExtension::NAME, $extension); - $this->expectException(InvalidOrderException::class); + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } else { + $this->expectException(InvalidOrderException::class); + } + $builder->getRequestParameter($struct); } @@ -152,7 +163,12 @@ public function testItThrowsExceptionOnMissingSequenceNumber(): void ]); $struct->getPaymentTransaction()->getOrderTransaction()->addExtension(PayonePaymentOrderTransactionExtension::NAME, $extension); - $this->expectException(InvalidOrderException::class); + if (class_exists(PaymentException::class)) { + $this->expectException(PaymentException::class); + } else { + $this->expectException(InvalidOrderException::class); + } + $builder->getRequestParameter($struct); } diff --git a/tests/TestCaseBase/Mock/PaymentHandler/PaymentHandlerMock.php b/tests/TestCaseBase/Mock/PaymentHandler/PaymentHandlerMock.php index d8d75bba9..0cb89004b 100644 --- a/tests/TestCaseBase/Mock/PaymentHandler/PaymentHandlerMock.php +++ b/tests/TestCaseBase/Mock/PaymentHandler/PaymentHandlerMock.php @@ -6,6 +6,9 @@ use PayonePayment\PaymentHandler\AbstractPayonePaymentHandler; use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder; +use Shopware\Core\Checkout\Payment\PaymentException; +use Shopware\Core\Checkout\Payment\Exception\SyncPaymentProcessException; + class PaymentHandlerMock extends AbstractPayonePaymentHandler { @@ -23,4 +26,17 @@ protected function getDefaultAuthorizationMethod(): string { return AbstractRequestParameterBuilder::REQUEST_ACTION_AUTHORIZE; } + + protected function createPaymentException(string $orderTransactionId, string $errorMessage, ?\Throwable $e): \Throwable + { + if (class_exists(PaymentException::class)) { + return PaymentException::asyncProcessInterrupted($orderTransactionId, $errorMessage, $e); + } elseif (class_exists(SyncPaymentProcessException::class)) { + // required for shopware version <= 6.5.3 + throw new SyncPaymentProcessException($orderTransactionId, $errorMessage, $e); // @phpstan-ignore-line + } + + // should never occur, just to be safe. + throw new \RuntimeException('payment process was interrupted ' . $orderTransactionId); + } } From f35db3faa5d6d6b2372875c866d42ac4de78c527 Mon Sep 17 00:00:00 2001 From: Frederik Rommel Date: Thu, 4 Apr 2024 14:43:42 +0200 Subject: [PATCH 05/45] reformat code --- .../payone-order-items.html.twig | 28 +- .../payone-payment-management/index.js | 244 +++++++++--------- .../payone-payment-order-action-log/index.js | 193 ++++++++------ .../payone-payment-webhook-log/index.js | 177 +++++++------ 4 files changed, 349 insertions(+), 293 deletions(-) diff --git a/src/Resources/app/administration/src/module/sw-order/component/payone-order-items/payone-order-items.html.twig b/src/Resources/app/administration/src/module/sw-order/component/payone-order-items/payone-order-items.html.twig index 1158c3160..74cfe12fa 100644 --- a/src/Resources/app/administration/src/module/sw-order/component/payone-order-items/payone-order-items.html.twig +++ b/src/Resources/app/administration/src/module/sw-order/component/payone-order-items/payone-order-items.html.twig @@ -1,11 +1,11 @@ {% block payone_payment_details %}
+ :dataSource="orderItems" + :columns="orderItemColumns" + :showActions="false" + :showSelection="true" + v-on:select-item="onSelectItem">