From 3b169c630c5fe8ebc0f08d2a4cac36f1d6724e3a Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Sat, 29 Nov 2025 14:42:14 +0100 Subject: [PATCH 1/4] Add payment component payload to OrderRequest --- src/Api/Transactions/OrderRequest.php | 17 ++++++ .../OrderRequest/Arguments/PaymentData.php | 57 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/Api/Transactions/OrderRequest/Arguments/PaymentData.php diff --git a/src/Api/Transactions/OrderRequest.php b/src/Api/Transactions/OrderRequest.php index aaffe53..f7a5a8b 100644 --- a/src/Api/Transactions/OrderRequest.php +++ b/src/Api/Transactions/OrderRequest.php @@ -15,6 +15,7 @@ use MultiSafepay\Api\Transactions\OrderRequest\Arguments\Description; use MultiSafepay\Api\Transactions\OrderRequest\Arguments\GatewayInfoInterface; use MultiSafepay\Api\Transactions\OrderRequest\Arguments\GoogleAnalytics; +use MultiSafepay\Api\Transactions\OrderRequest\Arguments\PaymentData; use MultiSafepay\Api\Transactions\OrderRequest\Arguments\PaymentOptions; use MultiSafepay\Api\Transactions\OrderRequest\Arguments\PluginDetails; use MultiSafepay\Api\Transactions\OrderRequest\Arguments\SecondChance; @@ -116,6 +117,11 @@ class OrderRequest extends RequestBody implements OrderRequestInterface */ protected $checkoutOptions; + /** + * @var PaymentData + */ + protected $paymentData; + /** * @var int */ @@ -494,6 +500,16 @@ public function addCheckoutOptions(CheckoutOptions $checkoutOptions): OrderReque return $this; } + /** + * @param PaymentData $paymentData + * @return OrderRequest + */ + public function addPaymentData(PaymentData $paymentData): OrderRequest + { + $this->paymentData = $paymentData; + return $this; + } + /** * @param int $seconds * @return OrderRequest @@ -620,6 +636,7 @@ public function getData(): array 'delivery' => $this->delivery ? $this->delivery->getData() : null, 'shopping_cart' => $this->shoppingCart ? $this->shoppingCart->getData() : null, 'checkout_options' => $this->checkoutOptions ? $this->checkoutOptions->getData() : null, + 'payment_data' => $this->paymentData ? $this->paymentData->getData() : null, 'days_active' => $this->daysActive, 'seconds_active' => $this->secondsActive, 'plugin' => $this->pluginDetails ? $this->pluginDetails->getData() : null, diff --git a/src/Api/Transactions/OrderRequest/Arguments/PaymentData.php b/src/Api/Transactions/OrderRequest/Arguments/PaymentData.php new file mode 100644 index 0000000..d1746db --- /dev/null +++ b/src/Api/Transactions/OrderRequest/Arguments/PaymentData.php @@ -0,0 +1,57 @@ +payload = $payload; + return $this; + } + + /** + * @param string $gateway + * @return PaymentData + */ + public function addGateway(string $gateway): PaymentData + { + $this->gateway = $gateway; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return [ + 'payload' => $this->payload, + 'gateway' => $this->gateway, + ]; + } +} From 0b1d1b98fd6b70bd08f6d606c4f4ad5a175481e3 Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Mon, 1 Dec 2025 05:07:32 +0100 Subject: [PATCH 2/4] Add tests for the `payment_data` property of an OrderRequest --- .../Api/Transactions/OrderRequestTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Unit/Api/Transactions/OrderRequestTest.php b/tests/Unit/Api/Transactions/OrderRequestTest.php index f472176..019d5c6 100644 --- a/tests/Unit/Api/Transactions/OrderRequestTest.php +++ b/tests/Unit/Api/Transactions/OrderRequestTest.php @@ -2,6 +2,7 @@ namespace MultiSafepay\Tests\Unit\Api\Transactions; use MultiSafepay\Api\Transactions\OrderRequest; +use MultiSafepay\Api\Transactions\OrderRequest\Arguments\PaymentData; use MultiSafepay\Api\Transactions\OrderRequest\Arguments\ShoppingCart\Item as ShoppingCartItem; use MultiSafepay\Exception\InvalidArgumentException; use MultiSafepay\Exception\InvalidTotalAmountException; @@ -229,4 +230,33 @@ public function testOrderWithAffiliate() $this->assertArrayHasKey('affiliate', $data); $this->assertArrayHasKey('split_payments', $data['affiliate']); } + + /** + * Test if we can get payment data, within an order request + * @throws InvalidArgumentException + * @throws InvalidTotalAmountException + */ + public function testOrderWithPaymentData() + { + $orderRequest = $this->createIdealOrderRedirectRequestFixture(); + $orderRequest->addPaymentData((new PaymentData()) + ->addPayload('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30') + ); + $data = $orderRequest->getData(); + + $this->assertArrayHasKey('payment_data', $data); + } + + /** + * Test if we can get payment data, within an order request + * @throws InvalidArgumentException + * @throws InvalidTotalAmountException + */ + public function testOrderWithoutPaymentData() + { + $orderRequest = $this->createIdealOrderRedirectRequestFixture(); + $data = $orderRequest->getData(); + + $this->assertArrayNotHasKey('payment_data', $data); + } } From f7dd30b59a34112147f96d00ea374831a29a4f3c Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Mon, 1 Dec 2025 08:35:05 +0100 Subject: [PATCH 3/4] Add `tokenize` property to `PaymentData` --- .../OrderRequest/Arguments/PaymentData.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Api/Transactions/OrderRequest/Arguments/PaymentData.php b/src/Api/Transactions/OrderRequest/Arguments/PaymentData.php index d1746db..65f58ea 100644 --- a/src/Api/Transactions/OrderRequest/Arguments/PaymentData.php +++ b/src/Api/Transactions/OrderRequest/Arguments/PaymentData.php @@ -24,6 +24,11 @@ class PaymentData extends DataObject */ private $gateway; + /** + * @var bool + */ + private $tokenize; + /** * @param string $payload * @return PaymentData @@ -44,14 +49,25 @@ public function addGateway(string $gateway): PaymentData return $this; } + /** + * @param bool $tokenize + * @return PaymentData + */ + public function addTokenize(bool $tokenize): PaymentData + { + $this->tokenize = $tokenize; + return $this; + } + /** * @return array */ public function getData(): array { - return [ + return $this->removeNullRecursive([ 'payload' => $this->payload, 'gateway' => $this->gateway, - ]; + 'tokenize' => $this->tokenize, + ]); } } From d80034619a6dec0ddb71a3a1ed880a392ed3659e Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Thu, 18 Dec 2025 15:46:36 +0100 Subject: [PATCH 4/4] Code style fix in OrderRequestTest --- tests/Unit/Api/Transactions/OrderRequestTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Unit/Api/Transactions/OrderRequestTest.php b/tests/Unit/Api/Transactions/OrderRequestTest.php index 019d5c6..315c055 100644 --- a/tests/Unit/Api/Transactions/OrderRequestTest.php +++ b/tests/Unit/Api/Transactions/OrderRequestTest.php @@ -239,9 +239,7 @@ public function testOrderWithAffiliate() public function testOrderWithPaymentData() { $orderRequest = $this->createIdealOrderRedirectRequestFixture(); - $orderRequest->addPaymentData((new PaymentData()) - ->addPayload('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30') - ); + $orderRequest->addPaymentData((new PaymentData())->addPayload('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30')); $data = $orderRequest->getData(); $this->assertArrayHasKey('payment_data', $data);