From 0e6185c863941bd81ecb645c619b28dc22978d02 Mon Sep 17 00:00:00 2001 From: Francois-Gomis Date: Tue, 8 Oct 2024 10:13:49 +0200 Subject: [PATCH] fix: change php client version and fix Alma order save in array --- composer.json | 2 +- src/Payum/Action/ValidatePaymentAction.php | 28 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d87c232..2eebca4 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "license": "MIT", "require": { "php": "~7.3 || ~7.4 || ~8.0 || ~8.1 || ~8.2", - "alma/alma-php-client": ">=1.11.2", + "alma/alma-php-client": ">=2.2.0", "sylius/sylius": ">=v1.9.0", "ext-json": "*" }, diff --git a/src/Payum/Action/ValidatePaymentAction.php b/src/Payum/Action/ValidatePaymentAction.php index 1e360ef..12b0f16 100644 --- a/src/Payum/Action/ValidatePaymentAction.php +++ b/src/Payum/Action/ValidatePaymentAction.php @@ -49,9 +49,11 @@ public function execute($request): void $paymentData ); + // Convert Alma's orders to an array to save on Sylius' Payment details + $paymentData->orders = $this->convertOrderToArrayForDBSave($paymentData->orders); + // Save Alma's payment data on Sylius' Payment details $details[AlmaBridgeInterface::DETAILS_KEY_PAYMENT_DATA] = $paymentData; - $payment->setDetails($details); } @@ -63,4 +65,28 @@ public function supports($request): bool return $request instanceof ValidatePayment && $request->getModel() instanceof PaymentInterface; } + + /** + * Convert Alma's orders to an array to save on Sylius' Payment details + * + * @param array $orders + * @return array + */ + private function convertOrderToArrayForDBSave(array $orders): array + { + $arrayOrders = []; + foreach ($orders as $order) { + $arrayOrders[] = [ + 'comment' => $order->getComment(), + 'created' => $order->getCreatedAt(), + 'customer_url' => $order->getCustomerUrl(), + 'data' => $order->getOrderData(), + 'id' => $order->getExternalId(), + 'merchant_reference' => $order->getMerchantReference(), + 'merchant_url' => $order->getMerchantUrl(), + 'payment' =>$order->getPaymentId() + ]; + } + return $arrayOrders; + } }