From 3a76b4f276c88fec3c2ea11b7817e305aeaa2595 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Tue, 16 Jun 2026 14:22:21 +0200 Subject: [PATCH 1/3] [CC-2379] Fix fatal error when payment type resolves to null in performCharge and performSca. Co-Authored-By: Claude Sonnet 4.6 --- src/Services/PaymentService.php | 4 ++-- test/unit/Services/PaymentServiceTest.php | 29 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index e05dd4ccd..b84987d98 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -157,7 +157,7 @@ public function performCharge(Charge $charge, $paymentType, $customer = null, ?M $paymentType = $payment->getPaymentType(); /** @var Charge $charge */ - $charge->setSpecialParams($paymentType->getTransactionParams() ?? []); + $charge->setSpecialParams($paymentType?->getTransactionParams() ?? []); $payment->addCharge($charge)->setCustomer($customer)->setMetadata($metadata)->setBasket($basket); $this->getResourceService()->createResource($charge); @@ -417,7 +417,7 @@ public function performSca(Sca $sca, $paymentType, $customer = null, ?Metadata $ $paymentType = $payment->getPaymentType(); /** @var Sca $sca */ - $sca->setSpecialParams($paymentType->getTransactionParams() ?? []); + $sca->setSpecialParams($paymentType?->getTransactionParams() ?? []); $payment->setSca($sca)->setCustomer($customer)->setMetadata($metadata)->setBasket($basket); $this->getResourceService()->createResource($sca); diff --git a/test/unit/Services/PaymentServiceTest.php b/test/unit/Services/PaymentServiceTest.php index f73cb6c8f..2b898baef 100755 --- a/test/unit/Services/PaymentServiceTest.php +++ b/test/unit/Services/PaymentServiceTest.php @@ -31,6 +31,7 @@ use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Resources\TransactionTypes\Payout; +use UnzerSDK\Resources\TransactionTypes\Sca; use UnzerSDK\Resources\TransactionTypes\Shipment; use UnzerSDK\Services\CancelService; use UnzerSDK\Services\PaymentService; @@ -283,6 +284,34 @@ public function chargePaymentShouldSetArgumentsInNewChargeObject(): void $this->assertEquals([$returnedCharge], $payment->getCharges()); } + /** + * Verify performCharge does not throw a fatal error when the payment type resolves to null. + * + * @test + */ + public function performChargeWithNullPaymentTypeShouldNotThrowFatalError(): void + { + $this->expectNotToPerformAssertions(); + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); + $paymentSrv = (new Unzer('s-priv-123'))->setResourceService($resourceSrvMock)->getPaymentService(); + + $paymentSrv->performCharge(new Charge(), null); + } + + /** + * Verify performSca does not throw a fatal error when the payment type resolves to null. + * + * @test + */ + public function performScaWithNullPaymentTypeShouldNotThrowFatalError(): void + { + $this->expectNotToPerformAssertions(); + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); + $paymentSrv = (new Unzer('s-priv-123'))->setResourceService($resourceSrvMock)->getPaymentService(); + + $paymentSrv->performSca(new Sca(), null); + } + // // From 3c9f6de57590c0068368ab4a599976b1f05da0e5 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Tue, 16 Jun 2026 14:29:27 +0200 Subject: [PATCH 2/3] [CC-2379] Apply consistent nullsafe operator in performAuthorization. Co-Authored-By: Claude Sonnet 4.6 --- src/Services/PaymentService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index b84987d98..a8a11b2af 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -86,7 +86,7 @@ public function performAuthorization( ): Authorization { $payment = $this->createPayment($paymentType); $paymentType = $payment->getPaymentType(); - $authorization->setSpecialParams($paymentType !== null ? $paymentType->getTransactionParams() : []); + $authorization->setSpecialParams($paymentType?->getTransactionParams() ?? []); $payment->setAuthorization($authorization) ->setCustomer($customer) From 9d8d94e1023d31f89e615aae468a8e806bdeabae Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Wed, 17 Jun 2026 09:55:54 +0200 Subject: [PATCH 3/3] [CC-2379] Use explicit try/catch in null payment type tests for clearer intent. Co-Authored-By: Claude Sonnet 4.6 --- test/unit/Services/PaymentServiceTest.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/unit/Services/PaymentServiceTest.php b/test/unit/Services/PaymentServiceTest.php index 2b898baef..ea3441cc9 100755 --- a/test/unit/Services/PaymentServiceTest.php +++ b/test/unit/Services/PaymentServiceTest.php @@ -291,11 +291,15 @@ public function chargePaymentShouldSetArgumentsInNewChargeObject(): void */ public function performChargeWithNullPaymentTypeShouldNotThrowFatalError(): void { - $this->expectNotToPerformAssertions(); $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); $paymentSrv = (new Unzer('s-priv-123'))->setResourceService($resourceSrvMock)->getPaymentService(); - $paymentSrv->performCharge(new Charge(), null); + try { + $paymentSrv->performCharge(new Charge(), null); + $this->assertTrue(true); + } catch (\Throwable $e) { + $this->fail('performCharge threw an unexpected error: ' . $e->getMessage()); + } } /** @@ -305,11 +309,15 @@ public function performChargeWithNullPaymentTypeShouldNotThrowFatalError(): void */ public function performScaWithNullPaymentTypeShouldNotThrowFatalError(): void { - $this->expectNotToPerformAssertions(); $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['createResource'])->getMock(); $paymentSrv = (new Unzer('s-priv-123'))->setResourceService($resourceSrvMock)->getPaymentService(); - $paymentSrv->performSca(new Sca(), null); + try { + $paymentSrv->performSca(new Sca(), null); + $this->assertTrue(true); + } catch (\Throwable $e) { + $this->fail('performSca threw an unexpected error: ' . $e->getMessage()); + } } //