From 015a9c0ed63f1e2df88018be4cc102aabafbc7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20M=C3=BCller?= Date: Tue, 14 Nov 2023 20:16:47 +0100 Subject: [PATCH] PAYOSWXP-105: Add order action log and webhook log --- .../OrderActionLogDataHandler.php | 45 +++++ .../OrderActionLogDataHandlerInterface.php | 22 +++ .../WebhookLog/WebhookLogDataHandler.php | 38 ++++ .../WebhookLogDataHandlerInterface.php | 20 +++ .../AbstractTransactionHandler.php | 18 +- .../Capture/CaptureTransactionHandler.php | 9 +- .../Refund/RefundTransactionHandler.php | 7 +- .../PayonePaymentOrderActionLogCollection.php | 18 ++ .../PayonePaymentOrderActionLogDefinition.php | 67 +++++++ .../PayonePaymentOrderActionLogEntity.php | 170 ++++++++++++++++++ .../PayonePaymentWebhookLogCollection.php | 18 ++ .../PayonePaymentWebhookLogDefinition.php | 62 +++++++ .../PayonePaymentWebhookLogEntity.php | 110 ++++++++++++ src/DependencyInjection/entities.xml | 8 + .../handler/global_handlers.xml | 12 ++ .../handler/payment_handler.xml | 6 +- src/DependencyInjection/webhooks.xml | 12 +- ...ration1695663841AddOrderActionLogTable.php | 51 ++++++ .../Migration1695663842AddWebhookLogTable.php | 45 +++++ ...stractAsynchronousPayonePaymentHandler.php | 12 +- .../AbstractKlarnaPaymentHandler.php | 7 +- ...bstractSynchronousPayonePaymentHandler.php | 12 +- .../PayoneApplePayPaymentHandler.php | 8 +- .../PayoneCreditCardPaymentHandler.php | 15 +- .../PayoneDebitPaymentHandler.php | 7 +- ...onePayolutionInstallmentPaymentHandler.php | 7 +- .../PayonePaypalExpressPaymentHandler.php | 8 +- .../PayonePaypalPaymentHandler.php | 8 +- src/Payone/Client/PayoneClient.php | 4 +- .../Webhook/Handler/WebhookLogHandler.php | 74 ++++++++ .../payone-payment-management.html.twig | 2 +- .../payone-payment-order-action-log/index.js | 100 +++++++++++ .../payone-payment-order-action-log.html.twig | 85 +++++++++ .../payone-payment-webhook-log/index.js | 93 ++++++++++ .../payone-payment-webhook-log.html.twig | 60 +++++++ .../src/module/sw-order/index.js | 2 + .../src/module/sw-order/snippet/de-DE.json | 54 ++++++ .../src/module/sw-order/snippet/en-GB.json | 54 ++++++ .../view/sw-order-detail-payone/index.js | 2 + .../sw-order-detail-payone.html.twig | 27 ++- .../dist/storefront/js/payone-payment.js | 2 +- .../administration/js/payone-payment.js | 2 +- src/Resources/public/static/js/0.js | 2 +- src/Resources/public/static/js/1.js | 2 +- src/Resources/public/static/js/10.js | 2 +- src/Resources/public/static/js/11.js | 2 +- src/Resources/public/static/js/12.js | 2 +- src/Resources/public/static/js/13.js | 1 + src/Resources/public/static/js/14.js | 1 + src/Resources/public/static/js/2.js | 2 +- src/Resources/public/static/js/3.js | 2 +- src/Resources/public/static/js/4.js | 2 +- src/Resources/public/static/js/5.js | 2 +- src/Resources/public/static/js/6.js | 2 +- src/Resources/public/static/js/7.js | 2 +- src/Resources/public/static/js/8.js | 2 +- src/Resources/public/static/js/9.js | 2 +- 57 files changed, 1361 insertions(+), 50 deletions(-) create mode 100644 src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandler.php create mode 100644 src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandlerInterface.php create mode 100644 src/Components/DataHandler/WebhookLog/WebhookLogDataHandler.php create mode 100644 src/Components/DataHandler/WebhookLog/WebhookLogDataHandlerInterface.php create mode 100644 src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogCollection.php create mode 100644 src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogDefinition.php create mode 100644 src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogEntity.php create mode 100644 src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogCollection.php create mode 100644 src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogDefinition.php create mode 100644 src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogEntity.php create mode 100644 src/Migration/Migration1695663841AddOrderActionLogTable.php create mode 100644 src/Migration/Migration1695663842AddWebhookLogTable.php create mode 100644 src/Payone/Webhook/Handler/WebhookLogHandler.php create mode 100644 src/Resources/app/administration/src/module/sw-order/component/payone-payment-order-action-log/index.js create mode 100644 src/Resources/app/administration/src/module/sw-order/component/payone-payment-order-action-log/payone-payment-order-action-log.html.twig create mode 100644 src/Resources/app/administration/src/module/sw-order/component/payone-payment-webhook-log/index.js create mode 100644 src/Resources/app/administration/src/module/sw-order/component/payone-payment-webhook-log/payone-payment-webhook-log.html.twig create mode 100644 src/Resources/public/static/js/13.js create mode 100644 src/Resources/public/static/js/14.js diff --git a/src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandler.php b/src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandler.php new file mode 100644 index 000000000..810c73b80 --- /dev/null +++ b/src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandler.php @@ -0,0 +1,45 @@ + $request + * @param array $response + */ + public function createOrderActionLog( + OrderEntity $order, + array $request, + array $response, + Context $context + ): void { + $orderActionLog = [ + 'orderId' => $order->getId(), + 'transactionId' => $response['txid'], + 'referenceNumber' => $order->getOrderNumber(), + 'request' => $request['request'], + 'response' => $response['status'], + 'amount' => $request['amount'], + 'mode' => $request['mode'], + 'merchantId' => $request['mid'], + 'portalId' => $request['portalid'], + 'requestDetails' => $request, + 'responseDetails' => $response, + 'requestDateTime' => new \DateTime(), + ]; + + $this->orderActionLogRepository->create([$orderActionLog], $context); + } +} diff --git a/src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandlerInterface.php b/src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandlerInterface.php new file mode 100644 index 000000000..13fe4a181 --- /dev/null +++ b/src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandlerInterface.php @@ -0,0 +1,22 @@ + $request + * @param array $response + */ + public function createOrderActionLog( + OrderEntity $order, + array $request, + array $response, + Context $context + ): void; +} diff --git a/src/Components/DataHandler/WebhookLog/WebhookLogDataHandler.php b/src/Components/DataHandler/WebhookLog/WebhookLogDataHandler.php new file mode 100644 index 000000000..db4dc8b15 --- /dev/null +++ b/src/Components/DataHandler/WebhookLog/WebhookLogDataHandler.php @@ -0,0 +1,38 @@ + $webhookData + */ + public function createWebhookLog( + OrderEntity $order, + array $webhookData, + Context $context + ): void { + $webhookLog = [ + 'orderId' => $order->getId(), + 'transactionId' => $webhookData['txid'], + 'transactionState' => $webhookData['txaction'], + 'sequenceNumber' => (int) $webhookData['sequencenumber'], + 'clearingType' => $webhookData['clearingtype'], + 'webhookDetails' => $webhookData, + 'webhookDateTime' => new \DateTime(), + ]; + + $this->webhookLogRepository->create([$webhookLog], $context); + } +} diff --git a/src/Components/DataHandler/WebhookLog/WebhookLogDataHandlerInterface.php b/src/Components/DataHandler/WebhookLog/WebhookLogDataHandlerInterface.php new file mode 100644 index 000000000..cfab29b1c --- /dev/null +++ b/src/Components/DataHandler/WebhookLog/WebhookLogDataHandlerInterface.php @@ -0,0 +1,20 @@ + $webhookData + */ + public function createWebhookLog( + OrderEntity $order, + array $webhookData, + Context $context + ): void; +} diff --git a/src/Components/TransactionHandler/AbstractTransactionHandler.php b/src/Components/TransactionHandler/AbstractTransactionHandler.php index 061482f30..eac4a2472 100644 --- a/src/Components/TransactionHandler/AbstractTransactionHandler.php +++ b/src/Components/TransactionHandler/AbstractTransactionHandler.php @@ -5,6 +5,7 @@ namespace PayonePayment\Components\TransactionHandler; use PayonePayment\Components\Currency\CurrencyPrecisionInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Payone\Client\Exception\PayoneRequestException; use PayonePayment\Payone\Client\PayoneClientInterface; @@ -28,7 +29,7 @@ abstract class AbstractTransactionHandler protected PayoneClientInterface $client; - protected TransactionDataHandlerInterface $dataHandler; + protected TransactionDataHandlerInterface $transactionDataHandler; protected EntityRepository $transactionRepository; @@ -38,6 +39,8 @@ abstract class AbstractTransactionHandler protected CurrencyPrecisionInterface $currencyPrecision; + protected OrderActionLogDataHandlerInterface $orderActionLogDataHandler; + public function handleRequest(ParameterBag $parameterBag, string $action, Context $context): array { $this->context = $context; @@ -93,11 +96,18 @@ protected function executeRequest(array $request): array try { $response = $this->client->request($request); - $this->dataHandler->logResponse($this->paymentTransaction, $this->context, [ + $this->transactionDataHandler->logResponse($this->paymentTransaction, $this->context, [ 'request' => $request, 'response' => $response, ]); + $this->orderActionLogDataHandler->createOrderActionLog( + $this->paymentTransaction->getOrder(), + $request, + $response, + $this->context + ); + return [ new JsonResponse(['status' => true]), $response, @@ -141,8 +151,8 @@ protected function updateTransactionData(ParameterBag $parameterBag, float $capt } } - $this->dataHandler->incrementSequenceNumber($this->paymentTransaction, $transactionData); - $this->dataHandler->saveTransactionData($this->paymentTransaction, $this->context, $transactionData); + $this->transactionDataHandler->incrementSequenceNumber($this->paymentTransaction, $transactionData); + $this->transactionDataHandler->saveTransactionData($this->paymentTransaction, $this->context, $transactionData); } protected function saveOrderLineItemData(array $orderLines, Context $context): void diff --git a/src/Components/TransactionHandler/Capture/CaptureTransactionHandler.php b/src/Components/TransactionHandler/Capture/CaptureTransactionHandler.php index 8a129ab5b..f8e86a454 100644 --- a/src/Components/TransactionHandler/Capture/CaptureTransactionHandler.php +++ b/src/Components/TransactionHandler/Capture/CaptureTransactionHandler.php @@ -5,6 +5,7 @@ namespace PayonePayment\Components\TransactionHandler\Capture; use PayonePayment\Components\Currency\CurrencyPrecisionInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\TransactionHandler\AbstractTransactionHandler; use PayonePayment\Components\TransactionStatus\TransactionStatusServiceInterface; @@ -26,7 +27,8 @@ class CaptureTransactionHandler extends AbstractTransactionHandler implements Ca public function __construct( RequestParameterFactory $requestFactory, PayoneClientInterface $client, - TransactionDataHandlerInterface $dataHandler, + TransactionDataHandlerInterface $transactionDataHandler, + OrderActionLogDataHandlerInterface $orderActionLogDataHandler, private readonly TransactionStatusServiceInterface $transactionStatusService, EntityRepository $transactionRepository, EntityRepository $lineItemRepository, @@ -34,7 +36,8 @@ public function __construct( ) { $this->requestFactory = $requestFactory; $this->client = $client; - $this->dataHandler = $dataHandler; + $this->transactionDataHandler = $transactionDataHandler; + $this->orderActionLogDataHandler = $orderActionLogDataHandler; $this->transactionRepository = $transactionRepository; $this->lineItemRepository = $lineItemRepository; $this->currencyPrecision = $currencyPrecision; @@ -123,7 +126,7 @@ private function updateClearingBankAccountData(array $payoneResponse): void $newClearingBankAccountData = $payoneResponse['clearing']['BankAccount'] ?? null; if (!empty($newClearingBankAccountData)) { - $this->dataHandler->saveTransactionData( + $this->transactionDataHandler->saveTransactionData( $this->paymentTransaction, $this->context, [ diff --git a/src/Components/TransactionHandler/Refund/RefundTransactionHandler.php b/src/Components/TransactionHandler/Refund/RefundTransactionHandler.php index 98e6e8578..8694de8d9 100644 --- a/src/Components/TransactionHandler/Refund/RefundTransactionHandler.php +++ b/src/Components/TransactionHandler/Refund/RefundTransactionHandler.php @@ -5,6 +5,7 @@ namespace PayonePayment\Components\TransactionHandler\Refund; use PayonePayment\Components\Currency\CurrencyPrecisionInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\TransactionHandler\AbstractTransactionHandler; use PayonePayment\Components\TransactionStatus\TransactionStatusServiceInterface; @@ -26,7 +27,8 @@ class RefundTransactionHandler extends AbstractTransactionHandler implements Ref public function __construct( RequestParameterFactory $requestFactory, PayoneClientInterface $client, - TransactionDataHandlerInterface $dataHandler, + TransactionDataHandlerInterface $transactionDataHandler, + OrderActionLogDataHandlerInterface $orderActionLogDataHandler, private readonly TransactionStatusServiceInterface $transactionStatusService, EntityRepository $transactionRepository, EntityRepository $lineItemRepository, @@ -34,7 +36,8 @@ public function __construct( ) { $this->requestFactory = $requestFactory; $this->client = $client; - $this->dataHandler = $dataHandler; + $this->transactionDataHandler = $transactionDataHandler; + $this->orderActionLogDataHandler = $orderActionLogDataHandler; $this->transactionRepository = $transactionRepository; $this->lineItemRepository = $lineItemRepository; $this->currencyPrecision = $currencyPrecision; diff --git a/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogCollection.php b/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogCollection.php new file mode 100644 index 000000000..7b0323dca --- /dev/null +++ b/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogCollection.php @@ -0,0 +1,18 @@ + + */ +class PayonePaymentOrderActionLogCollection extends EntityCollection +{ + protected function getExpectedClass(): string + { + return PayonePaymentOrderActionLogEntity::class; + } +} diff --git a/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogDefinition.php b/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogDefinition.php new file mode 100644 index 000000000..56cfdcc90 --- /dev/null +++ b/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogDefinition.php @@ -0,0 +1,67 @@ +setFlags(new PrimaryKey(), new Required()), + + (new FkField('order_id', 'orderId', OrderDefinition::class))->addFlags(new Required()), + (new ReferenceVersionField(OrderDefinition::class, 'order_version_id'))->addFlags(new Required()), + new ManyToOneAssociationField('order', 'order_id', OrderDefinition::class, 'id', false), + + (new StringField('transaction_id', 'transactionId'))->setFlags(new Required()), + (new StringField('reference_number', 'referenceNumber'))->setFlags(new Required()), + (new StringField('request', 'request'))->setFlags(new Required()), + (new StringField('response', 'response'))->setFlags(new Required()), + (new IntField('amount', 'amount'))->setFlags(new Required()), + (new StringField('mode', 'mode'))->setFlags(new Required()), + (new StringField('merchant_id', 'merchantId'))->setFlags(new Required()), + (new StringField('portal_id', 'portalId'))->setFlags(new Required()), + (new JsonField('request_details', 'requestDetails'))->setFlags(new Required()), + (new JsonField('response_details', 'responseDetails'))->setFlags(new Required()), + (new DateTimeField('request_date_time', 'requestDateTime'))->setFlags(new Required()), + + new CreatedAtField(), + new UpdatedAtField(), + ]); + } +} diff --git a/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogEntity.php b/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogEntity.php new file mode 100644 index 000000000..3f31154da --- /dev/null +++ b/src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogEntity.php @@ -0,0 +1,170 @@ +order; + } + + public function setOrder(?OrderEntity $order): void + { + $this->order = $order; + } + + public function getOrderId(): string + { + return $this->orderId; + } + + public function setOrderId(string $orderId): void + { + $this->orderId = $orderId; + } + + public function getTransactionId(): string + { + return $this->transactionId; + } + + public function setTransactionId(string $transactionId): void + { + $this->transactionId = $transactionId; + } + + public function getReferenceNumber(): string + { + return $this->referenceNumber; + } + + public function setReferenceNumber(string $referenceNumber): void + { + $this->referenceNumber = $referenceNumber; + } + + public function getRequest(): string + { + return $this->request; + } + + public function setRequest(string $request): void + { + $this->request = $request; + } + + public function getResponse(): string + { + return $this->response; + } + + public function setResponse(string $response): void + { + $this->response = $response; + } + + public function getAmount(): int + { + return $this->amount; + } + + public function setAmount(int $amount): void + { + $this->amount = $amount; + } + + public function getMode(): string + { + return $this->mode; + } + + public function setMode(string $mode): void + { + $this->mode = $mode; + } + + public function getMerchantId(): string + { + return $this->merchantId; + } + + public function setMerchantId(string $merchantId): void + { + $this->merchantId = $merchantId; + } + + public function getPortalId(): string + { + return $this->portalId; + } + + public function setPortalId(string $portalId): void + { + $this->portalId = $portalId; + } + + public function getRequestDetails(): array + { + return $this->requestDetails; + } + + public function setRequestDetails(array $requestDetails): void + { + $this->requestDetails = $requestDetails; + } + + public function getResponseDetails(): array + { + return $this->responseDetails; + } + + public function setResponseDetails(array $responseDetails): void + { + $this->responseDetails = $responseDetails; + } + + public function getRequestDateTime(): \DateTimeInterface + { + return $this->requestDateTime; + } + + public function setRequestDateTime(\DateTimeInterface $requestDateTime): void + { + $this->requestDateTime = $requestDateTime; + } +} diff --git a/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogCollection.php b/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogCollection.php new file mode 100644 index 000000000..9eef035e5 --- /dev/null +++ b/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogCollection.php @@ -0,0 +1,18 @@ + + */ +class PayonePaymentWebhookLogCollection extends EntityCollection +{ + protected function getExpectedClass(): string + { + return PayonePaymentWebhookLogEntity::class; + } +} diff --git a/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogDefinition.php b/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogDefinition.php new file mode 100644 index 000000000..c271fd654 --- /dev/null +++ b/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogDefinition.php @@ -0,0 +1,62 @@ +setFlags(new PrimaryKey(), new Required()), + + (new FkField('order_id', 'orderId', OrderDefinition::class))->addFlags(new Required()), + (new ReferenceVersionField(OrderDefinition::class, 'order_version_id'))->addFlags(new Required()), + new ManyToOneAssociationField('order', 'order_id', OrderDefinition::class, 'id', false), + + (new StringField('transaction_id', 'transactionId'))->setFlags(new Required()), + (new StringField('transaction_state', 'transactionState'))->setFlags(new Required()), + (new IntField('sequence_number', 'sequenceNumber'))->setFlags(new Required()), + (new StringField('clearing_type', 'clearingType'))->setFlags(new Required()), + (new JsonField('webhook_details', 'webhookDetails'))->setFlags(new Required()), + (new DateTimeField('webhook_date_time', 'webhookDateTime'))->setFlags(new Required()), + + new CreatedAtField(), + new UpdatedAtField(), + ]); + } +} diff --git a/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogEntity.php b/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogEntity.php new file mode 100644 index 000000000..416688908 --- /dev/null +++ b/src/DataAbstractionLayer/Entity/WebhookLog/PayonePaymentWebhookLogEntity.php @@ -0,0 +1,110 @@ +order; + } + + public function setOrder(?OrderEntity $order): void + { + $this->order = $order; + } + + public function getOrderId(): string + { + return $this->orderId; + } + + public function setOrderId(string $orderId): void + { + $this->orderId = $orderId; + } + + public function getTransactionId(): string + { + return $this->transactionId; + } + + public function setTransactionId(string $transactionId): void + { + $this->transactionId = $transactionId; + } + + public function getTransactionState(): string + { + return $this->transactionState; + } + + public function setTransactionState(string $transactionState): void + { + $this->transactionState = $transactionState; + } + + public function getSequenceNumber(): int + { + return $this->sequenceNumber; + } + + public function setSequenceNumber(int $sequenceNumber): void + { + $this->sequenceNumber = $sequenceNumber; + } + + public function getClearingType(): string + { + return $this->clearingType; + } + + public function setClearingType(string $clearingType): void + { + $this->clearingType = $clearingType; + } + + public function getWebhookDetails(): array + { + return $this->webhookDetails; + } + + public function setWebhookDetails(array $webhookDetails): void + { + $this->webhookDetails = $webhookDetails; + } + + public function getWebhookDateTime(): \DateTimeInterface + { + return $this->webhookDateTime; + } + + public function setWebhookDateTime(\DateTimeInterface $webhookDateTime): void + { + $this->webhookDateTime = $webhookDateTime; + } +} diff --git a/src/DependencyInjection/entities.xml b/src/DependencyInjection/entities.xml index 615aad2d5..585c44243 100644 --- a/src/DependencyInjection/entities.xml +++ b/src/DependencyInjection/entities.xml @@ -20,6 +20,14 @@ + + + + + + + + diff --git a/src/DependencyInjection/handler/global_handlers.xml b/src/DependencyInjection/handler/global_handlers.xml index dc54f146f..490f2ea3a 100644 --- a/src/DependencyInjection/handler/global_handlers.xml +++ b/src/DependencyInjection/handler/global_handlers.xml @@ -9,6 +9,7 @@ + @@ -19,6 +20,7 @@ + @@ -37,6 +39,16 @@ + + + + + + + + + + diff --git a/src/DependencyInjection/handler/payment_handler.xml b/src/DependencyInjection/handler/payment_handler.xml index 08a834571..ba575d9cb 100644 --- a/src/DependencyInjection/handler/payment_handler.xml +++ b/src/DependencyInjection/handler/payment_handler.xml @@ -15,7 +15,8 @@ abstract="true"> - + + @@ -25,7 +26,8 @@ abstract="true"> - + + diff --git a/src/DependencyInjection/webhooks.xml b/src/DependencyInjection/webhooks.xml index 72fd3ba10..84818a137 100644 --- a/src/DependencyInjection/webhooks.xml +++ b/src/DependencyInjection/webhooks.xml @@ -12,17 +12,25 @@ - + + + + + + + + + - + diff --git a/src/Migration/Migration1695663841AddOrderActionLogTable.php b/src/Migration/Migration1695663841AddOrderActionLogTable.php new file mode 100644 index 000000000..c0315a356 --- /dev/null +++ b/src/Migration/Migration1695663841AddOrderActionLogTable.php @@ -0,0 +1,51 @@ +executeStatement($sql); + } + + public function updateDestructive(Connection $connection): void + { + // implement update destructive + } +} diff --git a/src/Migration/Migration1695663842AddWebhookLogTable.php b/src/Migration/Migration1695663842AddWebhookLogTable.php new file mode 100644 index 000000000..bed69624c --- /dev/null +++ b/src/Migration/Migration1695663842AddWebhookLogTable.php @@ -0,0 +1,45 @@ +executeStatement($sql); + } + + public function updateDestructive(Connection $connection): void + { + // implement update destructive + } +} diff --git a/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php b/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php index a9334fd24..1f0ef4a22 100644 --- a/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php +++ b/src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php @@ -5,6 +5,7 @@ namespace PayonePayment\PaymentHandler; use PayonePayment\Components\ConfigReader\ConfigReaderInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\DeviceFingerprint\AbstractDeviceFingerprintService; use PayonePayment\Components\PaymentStateHandler\PaymentStateHandlerInterface; @@ -32,7 +33,8 @@ public function __construct( RequestStack $requestStack, protected readonly PayoneClientInterface $client, protected readonly TranslatorInterface $translator, - protected readonly TransactionDataHandlerInterface $dataHandler, + protected readonly TransactionDataHandlerInterface $transactionDataHandler, + protected readonly OrderActionLogDataHandlerInterface $orderActionLogDataHandler, protected readonly PaymentStateHandlerInterface $stateHandler, protected readonly RequestParameterFactory $requestParameterFactory, protected readonly ?AbstractDeviceFingerprintService $deviceFingerprintService = null @@ -144,7 +146,13 @@ protected function handleResponse( $this->getAdditionalTransactionData($dataBag, $request, $response) ); - $this->dataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->orderActionLogDataHandler->createOrderActionLog( + $transaction->getOrder(), + $request, + $response, + $salesChannelContext->getContext() + ); } protected function getRedirectResponse(array $request, array $response): RedirectResponse diff --git a/src/PaymentHandler/AbstractKlarnaPaymentHandler.php b/src/PaymentHandler/AbstractKlarnaPaymentHandler.php index f2fbd44f9..192307288 100644 --- a/src/PaymentHandler/AbstractKlarnaPaymentHandler.php +++ b/src/PaymentHandler/AbstractKlarnaPaymentHandler.php @@ -6,6 +6,7 @@ use PayonePayment\Components\CartHasher\CartHasherInterface; use PayonePayment\Components\ConfigReader\ConfigReaderInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\PaymentStateHandler\PaymentStateHandlerInterface; use PayonePayment\Payone\Client\PayoneClientInterface; @@ -28,7 +29,8 @@ public function __construct( RequestStack $requestStack, PayoneClientInterface $client, TranslatorInterface $translator, - TransactionDataHandlerInterface $dataHandler, + TransactionDataHandlerInterface $transactionDataHandler, + OrderActionLogDataHandlerInterface $orderActionLogDataHandler, PaymentStateHandlerInterface $stateHandler, RequestParameterFactory $requestParameterFactory, protected CartHasherInterface $cartHasher @@ -39,7 +41,8 @@ public function __construct( $requestStack, $client, $translator, - $dataHandler, + $transactionDataHandler, + $orderActionLogDataHandler, $stateHandler, $requestParameterFactory ); diff --git a/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php b/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php index d1b0cfded..fd43852ea 100644 --- a/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php +++ b/src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php @@ -5,6 +5,7 @@ namespace PayonePayment\PaymentHandler; use PayonePayment\Components\ConfigReader\ConfigReaderInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\DeviceFingerprint\AbstractDeviceFingerprintService; use PayonePayment\Payone\Client\Exception\PayoneRequestException; @@ -29,7 +30,8 @@ public function __construct( RequestStack $requestStack, protected readonly PayoneClientInterface $client, protected readonly TranslatorInterface $translator, - protected readonly TransactionDataHandlerInterface $dataHandler, + protected readonly TransactionDataHandlerInterface $transactionDataHandler, + protected readonly OrderActionLogDataHandlerInterface $orderActionLogDataHandler, protected readonly RequestParameterFactory $requestParameterFactory, protected readonly ?AbstractDeviceFingerprintService $deviceFingerprintService = null ) { @@ -130,6 +132,12 @@ protected function handleResponse( $this->getAdditionalTransactionData($dataBag, $request, $response) ); - $this->dataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->orderActionLogDataHandler->createOrderActionLog( + $transaction->getOrder(), + $request, + $response, + $salesChannelContext->getContext() + ); } } diff --git a/src/PaymentHandler/PayoneApplePayPaymentHandler.php b/src/PaymentHandler/PayoneApplePayPaymentHandler.php index 8d2b61b36..2d14dcd28 100644 --- a/src/PaymentHandler/PayoneApplePayPaymentHandler.php +++ b/src/PaymentHandler/PayoneApplePayPaymentHandler.php @@ -47,7 +47,13 @@ public function pay( ]; $data = $this->preparePayoneOrderTransactionData($request, $response); - $this->dataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->orderActionLogDataHandler->createOrderActionLog( + $transaction->getOrder(), + $request, + $response, + $salesChannelContext->getContext() + ); } public static function isCapturable(array $transactionData, array $payoneTransActionData): bool diff --git a/src/PaymentHandler/PayoneCreditCardPaymentHandler.php b/src/PaymentHandler/PayoneCreditCardPaymentHandler.php index aeaeeea1d..3fb5e5af6 100644 --- a/src/PaymentHandler/PayoneCreditCardPaymentHandler.php +++ b/src/PaymentHandler/PayoneCreditCardPaymentHandler.php @@ -6,6 +6,7 @@ use PayonePayment\Components\CardRepository\CardRepositoryInterface; use PayonePayment\Components\ConfigReader\ConfigReaderInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\PaymentStateHandler\PaymentStateHandlerInterface; use PayonePayment\Components\TransactionStatus\TransactionStatusService; @@ -37,7 +38,8 @@ public function __construct( RequestStack $requestStack, PayoneClientInterface $client, TranslatorInterface $translator, - TransactionDataHandlerInterface $dataHandler, + TransactionDataHandlerInterface $transactionDataHandler, + OrderActionLogDataHandlerInterface $orderActionLogDataHandler, PaymentStateHandlerInterface $stateHandler, RequestParameterFactory $requestParameterFactory, protected CardRepositoryInterface $cardRepository @@ -48,7 +50,8 @@ public function __construct( $requestStack, $client, $translator, - $dataHandler, + $transactionDataHandler, + $orderActionLogDataHandler, $stateHandler, $requestParameterFactory ); @@ -138,7 +141,13 @@ protected function handleResponse( 'card_type' => $cardType, ], ]); - $this->dataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->orderActionLogDataHandler->createOrderActionLog( + $transaction->getOrder(), + $request, + $response, + $salesChannelContext->getContext() + ); if ($paymentTransaction->getOrder()->getLineItems() !== null) { $this->setLineItemCustomFields($paymentTransaction->getOrder()->getLineItems(), $salesChannelContext->getContext()); diff --git a/src/PaymentHandler/PayoneDebitPaymentHandler.php b/src/PaymentHandler/PayoneDebitPaymentHandler.php index 6577e03c7..e485d425c 100644 --- a/src/PaymentHandler/PayoneDebitPaymentHandler.php +++ b/src/PaymentHandler/PayoneDebitPaymentHandler.php @@ -5,6 +5,7 @@ namespace PayonePayment\PaymentHandler; use PayonePayment\Components\ConfigReader\ConfigReaderInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\MandateService\MandateServiceInterface; use PayonePayment\Components\TransactionStatus\TransactionStatusService; @@ -29,7 +30,8 @@ public function __construct( RequestStack $requestStack, PayoneClientInterface $client, TranslatorInterface $translator, - TransactionDataHandlerInterface $dataHandler, + TransactionDataHandlerInterface $transactionDataHandler, + OrderActionLogDataHandlerInterface $orderActionLogDataHandler, RequestParameterFactory $requestParameterFactory, protected MandateServiceInterface $mandateService ) { @@ -39,7 +41,8 @@ public function __construct( $requestStack, $client, $translator, - $dataHandler, + $transactionDataHandler, + $orderActionLogDataHandler, $requestParameterFactory ); } diff --git a/src/PaymentHandler/PayonePayolutionInstallmentPaymentHandler.php b/src/PaymentHandler/PayonePayolutionInstallmentPaymentHandler.php index da2ee0402..1099b6437 100644 --- a/src/PaymentHandler/PayonePayolutionInstallmentPaymentHandler.php +++ b/src/PaymentHandler/PayonePayolutionInstallmentPaymentHandler.php @@ -6,6 +6,7 @@ use PayonePayment\Components\CartHasher\CartHasherInterface; use PayonePayment\Components\ConfigReader\ConfigReaderInterface; +use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface; use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandlerInterface; use PayonePayment\Components\Validator\Birthday; use PayonePayment\Components\Validator\PaymentMethod; @@ -28,7 +29,8 @@ public function __construct( RequestStack $requestStack, PayoneClientInterface $client, TranslatorInterface $translator, - TransactionDataHandlerInterface $dataHandler, + TransactionDataHandlerInterface $transactionDataHandler, + OrderActionLogDataHandlerInterface $orderActionLogDataHandler, RequestParameterFactory $requestParameterFactory, protected CartHasherInterface $cartHasher ) { @@ -38,7 +40,8 @@ public function __construct( $requestStack, $client, $translator, - $dataHandler, + $transactionDataHandler, + $orderActionLogDataHandler, $requestParameterFactory ); } diff --git a/src/PaymentHandler/PayonePaypalExpressPaymentHandler.php b/src/PaymentHandler/PayonePaypalExpressPaymentHandler.php index 408644025..5b31be62c 100644 --- a/src/PaymentHandler/PayonePaypalExpressPaymentHandler.php +++ b/src/PaymentHandler/PayonePaypalExpressPaymentHandler.php @@ -56,7 +56,13 @@ protected function handleResponse( 'workOrderId' => $dataBag->get('workorder'), ]); - $this->dataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->orderActionLogDataHandler->createOrderActionLog( + $transaction->getOrder(), + $request, + $response, + $salesChannelContext->getContext() + ); } protected function getRedirectResponse(array $request, array $response): RedirectResponse diff --git a/src/PaymentHandler/PayonePaypalPaymentHandler.php b/src/PaymentHandler/PayonePaypalPaymentHandler.php index e05f9d5f9..dd964c947 100644 --- a/src/PaymentHandler/PayonePaypalPaymentHandler.php +++ b/src/PaymentHandler/PayonePaypalPaymentHandler.php @@ -53,7 +53,13 @@ protected function handleResponse( } $data = $this->preparePayoneOrderTransactionData($request, $response); - $this->dataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data); + $this->orderActionLogDataHandler->createOrderActionLog( + $transaction->getOrder(), + $request, + $response, + $salesChannelContext->getContext() + ); } protected function getRedirectResponse(array $request, array $response): RedirectResponse diff --git a/src/Payone/Client/PayoneClient.php b/src/Payone/Client/PayoneClient.php index 1f0d82e3c..961b5442e 100644 --- a/src/Payone/Client/PayoneClient.php +++ b/src/Payone/Client/PayoneClient.php @@ -61,7 +61,7 @@ public function request(array $parameters, bool $json = true): array ]); if (empty($data)) { - throw new PayoneRequestException('payone returned a empty response', $parameters, []); + throw new PayoneRequestException('payone returned an empty response', $parameters, []); } $response = array_change_key_case($data, \CASE_LOWER); @@ -69,7 +69,7 @@ public function request(array $parameters, bool $json = true): array ksort($response, \SORT_NATURAL | \SORT_FLAG_CASE); if ($response['status'] === 'ERROR') { - throw new PayoneRequestException('payone returned a error', $parameters, $response); + throw new PayoneRequestException('payone returned an error', $parameters, $response); } return $response; diff --git a/src/Payone/Webhook/Handler/WebhookLogHandler.php b/src/Payone/Webhook/Handler/WebhookLogHandler.php new file mode 100644 index 000000000..cd08dd797 --- /dev/null +++ b/src/Payone/Webhook/Handler/WebhookLogHandler.php @@ -0,0 +1,74 @@ +request->all(); + + /** @var PaymentTransaction|null $paymentTransaction */ + $paymentTransaction = $this->transactionDataHandler->getPaymentTransactionByPayoneTransactionId( + $salesChannelContext->getContext(), + (int) $data['txid'] + ); + + if ($paymentTransaction === null) { + $this->logger->warning(sprintf('Could not get transaction for id %s', (int) $data['txid'])); + + return; + } + + // Sanitize incoming data + $data = $this->utf8EncodeRecursive($data); + + $this->webhookLogDataHandler->createWebhookLog( + $paymentTransaction->getOrder(), + $data, + $salesChannelContext->getContext() + ); + } + + private function utf8EncodeRecursive(array $transactionData): array + { + foreach ($transactionData as &$transactionValue) { + if (\is_array($transactionValue)) { + $transactionValue = $this->utf8EncodeRecursive($transactionValue); + + continue; + } + + $transactionValue = utf8_encode((string) $transactionValue); + } + unset($transactionValue); + + return $transactionData; + } +} diff --git a/src/Resources/app/administration/src/module/sw-order/component/payone-payment-management/payone-payment-management.html.twig b/src/Resources/app/administration/src/module/sw-order/component/payone-payment-management/payone-payment-management.html.twig index 29a4b362a..f9f936bcd 100644 --- a/src/Resources/app/administration/src/module/sw-order/component/payone-payment-management/payone-payment-management.html.twig +++ b/src/Resources/app/administration/src/module/sw-order/component/payone-payment-management/payone-payment-management.html.twig @@ -1,7 +1,7 @@ {% block payone_payment_management %}