From 895878373cfece5c8998ec7410518ce83927e9f9 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Thu, 14 Aug 2025 17:42:51 +0200 Subject: [PATCH 1/8] [CC-2672] Add wero class. --- src/Constants/IdStrings.php | 2 ++ src/Resources/PaymentTypes/Wero.php | 7 +++++++ src/Services/ResourceService.php | 4 ++++ 3 files changed, 13 insertions(+) create mode 100644 src/Resources/PaymentTypes/Wero.php diff --git a/src/Constants/IdStrings.php b/src/Constants/IdStrings.php index ee363228..662c9ea9 100755 --- a/src/Constants/IdStrings.php +++ b/src/Constants/IdStrings.php @@ -52,6 +52,7 @@ class IdStrings public const SOFORT = 'sft'; public const TWINT = 'twt'; public const WECHATPAY = 'wcp'; + public const WERO = 'wro'; public const OPEN_BANKING = 'obp'; @@ -95,6 +96,7 @@ class IdStrings self::SOFORT, self::TWINT, self::WECHATPAY, + self::WERO, self::OPEN_BANKING, ]; } diff --git a/src/Resources/PaymentTypes/Wero.php b/src/Resources/PaymentTypes/Wero.php new file mode 100644 index 00000000..93a3f046 --- /dev/null +++ b/src/Resources/PaymentTypes/Wero.php @@ -0,0 +1,7 @@ + Date: Fri, 15 Aug 2025 11:13:26 +0200 Subject: [PATCH 2/8] [CC-2672] Add wero class. --- test/integration/PaymentTypes/WeroTest.php | 74 ++++++++++++++++++++++ test/unit/Services/ResourceServiceTest.php | 3 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/integration/PaymentTypes/WeroTest.php diff --git a/test/integration/PaymentTypes/WeroTest.php b/test/integration/PaymentTypes/WeroTest.php new file mode 100644 index 00000000..47c2d58b --- /dev/null +++ b/test/integration/PaymentTypes/WeroTest.php @@ -0,0 +1,74 @@ +unzer->createPaymentType(new Wero()); + $this->assertInstanceOf(Wero::class, $wero); + $this->assertNotEmpty($wero->getId()); + + $fetched = $this->unzer->fetchPaymentType($wero->getId()); + $this->assertInstanceOf(Wero::class, $fetched); + $this->assertNotSame($wero, $fetched); + $this->assertEquals($wero->expose(), $fetched->expose()); + + return $fetched; + } + + /** + * Verify Wero can authorize. + * + * @test + * + * @depends weroShouldBeCreatableAndFetchable + */ + public function weroShouldBeAuthorizable(Wero $wero): void + { + $authorization = new Authorization(100.0, 'EUR', self::RETURN_URL); + $authorization = $this->unzer->performAuthorization($authorization, $wero); + $this->assertNotNull($authorization); + $this->assertNotEmpty($authorization->getId()); + $this->assertNotEmpty($authorization->getRedirectUrl()); + + $payment = $authorization->getPayment(); + $this->assertNotNull($payment); + $this->assertTrue($payment->isPending()); + } + + /** + * Verify Wero can charge. + * + * @test + * + * @depends weroShouldBeCreatableAndFetchable + */ + public function weroShouldBeChargeable(Wero $wero): void + { + $charge = new Charge(100.0, 'EUR', self::RETURN_URL); + $charge = $this->unzer->performCharge($charge, $wero); + $this->assertNotNull($charge); + $this->assertNotEmpty($charge->getId()); + $this->assertNotEmpty($charge->getRedirectUrl()); + + $fetched = $this->unzer->fetchChargeById($charge->getPayment()->getId(), $charge->getId()); + $this->assertEquals($charge->setCard3ds(false)->expose(), $fetched->expose()); + } +} diff --git a/test/unit/Services/ResourceServiceTest.php b/test/unit/Services/ResourceServiceTest.php index 8ba3c4c7..f87d57c4 100755 --- a/test/unit/Services/ResourceServiceTest.php +++ b/test/unit/Services/ResourceServiceTest.php @@ -1426,7 +1426,8 @@ public function fetchResourceByUrlForAPaymentTypeShouldCallFetchPaymentTypeDP(): 'SEPA_DIRECT_DEBIT' => ['s-sdd-xen2ybcovn56', 'https://api.unzer.com/v1/types/direct-debit/s-sdd-xen2ybcovn56/'], 'SEPA_DIRECT_DEBIT_GUARANTEED' => ['s-ddg-xen2ybcovn56', 'https://api.unzer.com/v1/types/direct-debit-guaranteed/s-ddg-xen2ybcovn56/'], 'SOFORT' => ['s-sft-xen2ybcovn56', 'https://api.unzer.com/v1/types/sofort/s-sft-xen2ybcovn56/'], - 'WECHATPAY' => ['s-wcp-xen2ybcovn56', 'https://api.unzer.com/v1/types/wechatpay/s-wcp-xen2ybcovn56/'] + 'WECHATPAY' => ['s-wcp-xen2ybcovn56', 'https://api.unzer.com/v1/types/wechatpay/s-wcp-xen2ybcovn56/'], + 'WERO' => ['s-wro-xen2ybcovn56', 'https://api.unzer.com/v1/types/wechatpay/s-wro-xen2ybcovn56/'] ]; } From 40715b0aa08538794f99f663a67c26ea066df374 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Fri, 15 Aug 2025 17:19:35 +0200 Subject: [PATCH 3/8] [CC-2672] Add Wero. --- .../AdditionalTransactionDataKeys.php | 1 + src/Constants/WeroAmountPaymentTypes.php | 12 +++ src/Constants/WeroCaptureTriggers.php | 15 ++++ .../WeroEventDependentPayment.php | 76 +++++++++++++++++++ .../EmbeddedResources/WeroTransactionData.php | 47 ++++++++++++ .../AbstractTransactionType.php | 23 +++++- src/Traits/HasAdditionalTransactionData.php | 26 +++++++ test/integration/PaymentTypes/WeroTest.php | 33 +++++++- .../WeroTransactionDataTest.php | 40 ++++++++++ 9 files changed, 270 insertions(+), 3 deletions(-) create mode 100644 src/Constants/WeroAmountPaymentTypes.php create mode 100644 src/Constants/WeroCaptureTriggers.php create mode 100644 src/Resources/EmbeddedResources/WeroEventDependentPayment.php create mode 100644 src/Resources/EmbeddedResources/WeroTransactionData.php create mode 100644 test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php diff --git a/src/Constants/AdditionalTransactionDataKeys.php b/src/Constants/AdditionalTransactionDataKeys.php index 3cf31f3b..338a6e2c 100644 --- a/src/Constants/AdditionalTransactionDataKeys.php +++ b/src/Constants/AdditionalTransactionDataKeys.php @@ -18,4 +18,5 @@ class AdditionalTransactionDataKeys public const CHECKOUTTYPE = 'checkoutType'; public const CARD = 'card'; + public const WERO = 'wero'; } diff --git a/src/Constants/WeroAmountPaymentTypes.php b/src/Constants/WeroAmountPaymentTypes.php new file mode 100644 index 00000000..1ccc0d03 --- /dev/null +++ b/src/Constants/WeroAmountPaymentTypes.php @@ -0,0 +1,12 @@ +captureTrigger; + } + + public function setCaptureTrigger(?string $captureTrigger): WeroEventDependentPayment + { + $this->captureTrigger = $captureTrigger; + return $this; + } + + public function getAmountPaymentType(): ?string + { + return $this->amountPaymentType; + } + + public function setAmountPaymentType(?string $amountPaymentType): WeroEventDependentPayment + { + $this->amountPaymentType = $amountPaymentType; + return $this; + } + + /** + * @return string|int|null + */ + public function getMaxAuthToCaptureTime() + { + return $this->maxAuthToCaptureTime; + } + + /** + * @param string|int|null $maxAuthToCaptureTime + */ + public function setMaxAuthToCaptureTime($maxAuthToCaptureTime): WeroEventDependentPayment + { + $this->maxAuthToCaptureTime = $maxAuthToCaptureTime; + return $this; + } + + /** + * @return bool|string|null + */ + public function getMultiCapturesAllowed() + { + return $this->multiCapturesAllowed; + } + + /** + * @param bool|string|null $multiCapturesAllowed + */ + public function setMultiCapturesAllowed($multiCapturesAllowed): WeroEventDependentPayment + { + $this->multiCapturesAllowed = $multiCapturesAllowed; + return $this; + } +} diff --git a/src/Resources/EmbeddedResources/WeroTransactionData.php b/src/Resources/EmbeddedResources/WeroTransactionData.php new file mode 100644 index 00000000..80ac6076 --- /dev/null +++ b/src/Resources/EmbeddedResources/WeroTransactionData.php @@ -0,0 +1,47 @@ +eventDependentPayment; + } + + /** + * @param WeroEventDependentPayment|null $eventDependentPayment + * @return WeroTransactionData + */ + public function setEventDependentPayment(?WeroEventDependentPayment $eventDependentPayment): WeroTransactionData + { + $this->eventDependentPayment = $eventDependentPayment; + return $this; + } + + /** + * @inheritDoc + */ + public function handleResponse($response, string $method = null): void + { + parent::handleResponse($response, $method); + if ($response instanceof stdClass && isset($response->eventDependentPayment)) { + $edp = $this->getEventDependentPayment() ?? new WeroEventDependentPayment(); + $edp->handleResponse($response->eventDependentPayment); + $this->setEventDependentPayment($edp); + } + } +} diff --git a/src/Resources/TransactionTypes/AbstractTransactionType.php b/src/Resources/TransactionTypes/AbstractTransactionType.php index 1572e8b8..70bd0802 100755 --- a/src/Resources/TransactionTypes/AbstractTransactionType.php +++ b/src/Resources/TransactionTypes/AbstractTransactionType.php @@ -8,12 +8,15 @@ namespace UnzerSDK\Resources\TransactionTypes; +use RuntimeException; +use stdClass; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\EmbeddedResources\CardTransactionData; use UnzerSDK\Resources\EmbeddedResources\RiskData; use UnzerSDK\Resources\EmbeddedResources\ShippingData; +use UnzerSDK\Resources\EmbeddedResources\WeroTransactionData; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Traits\HasAdditionalTransactionData; @@ -24,8 +27,6 @@ use UnzerSDK\Traits\HasStates; use UnzerSDK\Traits\HasTraceId; use UnzerSDK\Traits\HasUniqueAndShortId; -use RuntimeException; -use stdClass; abstract class AbstractTransactionType extends AbstractUnzerResource { @@ -170,6 +171,7 @@ protected function handleAdditionalTransactionData(stdClass $response): void $this->handleRiskData($additionalTransactionData); $this->handleShipping($additionalTransactionData); $this->handleCardTransactionData($additionalTransactionData); + $this->handleWeroTransactionData($additionalTransactionData); } } @@ -223,4 +225,21 @@ protected function handleCardTransactionData(stdClass $additionalTransactionData $this->setCardTransactionData($cardTransactionData); } } + + /** + * Handle WeroTransactionData object contained in additional transaction data from API response. + * + * @param stdClass $additionalTransactionData + * + * @return void + */ + protected function handleWeroTransactionData(stdClass $additionalTransactionData): void + { + $wero = $additionalTransactionData->wero ?? null; + if ($wero !== null) { + $weroTransactionData = $this->getWeroTransactionData() ?? new WeroTransactionData(); + $weroTransactionData->handleResponse($wero); + $this->setWeroTransactionData($weroTransactionData); + } + } } diff --git a/src/Traits/HasAdditionalTransactionData.php b/src/Traits/HasAdditionalTransactionData.php index 3dcd4b2c..ff8ced73 100644 --- a/src/Traits/HasAdditionalTransactionData.php +++ b/src/Traits/HasAdditionalTransactionData.php @@ -14,6 +14,7 @@ use UnzerSDK\Resources\EmbeddedResources\CardTransactionData; use UnzerSDK\Resources\EmbeddedResources\RiskData; use UnzerSDK\Resources\EmbeddedResources\ShippingData; +use UnzerSDK\Resources\EmbeddedResources\WeroTransactionData; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\TransactionTypes\AbstractTransactionType; use UnzerSDK\Services\ResourceService; @@ -221,4 +222,29 @@ public function setCardTransactionData(?CardTransactionData $cardTransactionData $this->addAdditionalTransactionData(AdditionalTransactionDataKeys::CARD, $cardTransactionData); return $this; } + + /** + * Get the wero field from additional transaction Data. + * + * @return WeroTransactionData|null "wero" object of additionalTransaction data. + */ + public function getWeroTransactionData(): ?WeroTransactionData + { + $key = AdditionalTransactionDataKeys::WERO; + $wero = $this->getAdditionalTransactionData()->$key ?? null; + return $wero instanceof WeroTransactionData ? $wero : null; + } + + /** + * Sets WeroTransactionData object as "wero" field of additionalTransactionData. + * + * @param WeroTransactionData|null $weroTransactionData + * + * @return self + */ + public function setWeroTransactionData(?WeroTransactionData $weroTransactionData): self + { + $this->addAdditionalTransactionData(AdditionalTransactionDataKeys::WERO, $weroTransactionData); + return $this; + } } diff --git a/test/integration/PaymentTypes/WeroTest.php b/test/integration/PaymentTypes/WeroTest.php index 47c2d58b..a7c08e82 100644 --- a/test/integration/PaymentTypes/WeroTest.php +++ b/test/integration/PaymentTypes/WeroTest.php @@ -6,6 +6,10 @@ namespace UnzerSDK\test\integration\PaymentTypes; +use UnzerSDK\Constants\WeroAmountPaymentTypes; +use UnzerSDK\Constants\WeroCaptureTriggers; +use UnzerSDK\Resources\EmbeddedResources\WeroEventDependentPayment; +use UnzerSDK\Resources\EmbeddedResources\WeroTransactionData; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\Wero; use UnzerSDK\Resources\TransactionTypes\Authorization; @@ -43,6 +47,18 @@ public function weroShouldBeCreatableAndFetchable(): BasePaymentType public function weroShouldBeAuthorizable(Wero $wero): void { $authorization = new Authorization(100.0, 'EUR', self::RETURN_URL); + + // Add Wero additional transaction data + $weroData = (new WeroTransactionData()) + ->setEventDependentPayment( + (new WeroEventDependentPayment()) + ->setCaptureTrigger(WeroCaptureTriggers::SERVICEFULFILMENT) + ->setAmountPaymentType(WeroAmountPaymentTypes::PAY) + ->setMaxAuthToCaptureTime(300) + ->setMultiCapturesAllowed(false) + ); + $authorization->setWeroTransactionData($weroData); + $authorization = $this->unzer->performAuthorization($authorization, $wero); $this->assertNotNull($authorization); $this->assertNotEmpty($authorization->getId()); @@ -63,12 +79,27 @@ public function weroShouldBeAuthorizable(Wero $wero): void public function weroShouldBeChargeable(Wero $wero): void { $charge = new Charge(100.0, 'EUR', self::RETURN_URL); + + // Add Wero additional transaction data + $weroData = (new WeroTransactionData()) + ->setEventDependentPayment( + (new WeroEventDependentPayment()) + ->setCaptureTrigger(WeroCaptureTriggers::SERVICEFULFILMENT) + ->setAmountPaymentType(WeroAmountPaymentTypes::PAY) + ->setMaxAuthToCaptureTime(300) + ->setMultiCapturesAllowed(false) + ); + $charge->setWeroTransactionData($weroData); + $charge = $this->unzer->performCharge($charge, $wero); $this->assertNotNull($charge); $this->assertNotEmpty($charge->getId()); $this->assertNotEmpty($charge->getRedirectUrl()); $fetched = $this->unzer->fetchChargeById($charge->getPayment()->getId(), $charge->getId()); - $this->assertEquals($charge->setCard3ds(false)->expose(), $fetched->expose()); + + $this->assertEquals(($charge->getPaymentId()), $fetched->getPaymentId()); + $this->assertEquals(($charge->getAmount()), $fetched->getAmount()); + $this->assertEquals(($charge->getId()), $fetched->getId()); } } diff --git a/test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php b/test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php new file mode 100644 index 00000000..69301dd5 --- /dev/null +++ b/test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php @@ -0,0 +1,40 @@ +setCaptureTrigger(WeroCaptureTriggers::SERVICEFULFILMENT) + ->setAmountPaymentType(WeroAmountPaymentTypes::PAY) + ->setMaxAuthToCaptureTime('300') + ->setMultiCapturesAllowed('false'); + + $wtd = (new WeroTransactionData()) + ->setEventDependentPayment($edp); + + // Getters + $this->assertInstanceOf(WeroEventDependentPayment::class, $wtd->getEventDependentPayment()); + $this->assertEquals(WeroCaptureTriggers::SERVICEFULFILMENT, $wtd->getEventDependentPayment()->getCaptureTrigger()); + + // Expose + $exposed = $wtd->expose(); + $this->assertArrayHasKey('eventDependentPayment', $exposed); + $this->assertEquals(WeroCaptureTriggers::SERVICEFULFILMENT, $exposed['eventDependentPayment']['captureTrigger']); + $this->assertEquals(WeroAmountPaymentTypes::PAY, $exposed['eventDependentPayment']['amountPaymentType']); + $this->assertSame(300, $exposed['eventDependentPayment']['maxAuthToCaptureTime']); + $this->assertSame(false, $exposed['eventDependentPayment']['multiCapturesAllowed']); + $this->assertArrayNotHasKey('enabled', $exposed); + } +} From 3905f3eee1c829deab722b6bca256c4a4271e4f8 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Mon, 18 Aug 2025 11:01:50 +0200 Subject: [PATCH 4/8] [CC-2672] Add Wero. --- .../EmbeddedResources/WeroEventDependentPayment.php | 10 ++-------- .../EmbeddedResources/WeroTransactionData.php | 3 ++- .../EmbeddedResources/WeroTransactionDataTest.php | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Resources/EmbeddedResources/WeroEventDependentPayment.php b/src/Resources/EmbeddedResources/WeroEventDependentPayment.php index b4409bbd..4d4eb74f 100644 --- a/src/Resources/EmbeddedResources/WeroEventDependentPayment.php +++ b/src/Resources/EmbeddedResources/WeroEventDependentPayment.php @@ -48,10 +48,7 @@ public function getMaxAuthToCaptureTime() return $this->maxAuthToCaptureTime; } - /** - * @param string|int|null $maxAuthToCaptureTime - */ - public function setMaxAuthToCaptureTime($maxAuthToCaptureTime): WeroEventDependentPayment + public function setMaxAuthToCaptureTime(?int $maxAuthToCaptureTime): WeroEventDependentPayment { $this->maxAuthToCaptureTime = $maxAuthToCaptureTime; return $this; @@ -65,10 +62,7 @@ public function getMultiCapturesAllowed() return $this->multiCapturesAllowed; } - /** - * @param bool|string|null $multiCapturesAllowed - */ - public function setMultiCapturesAllowed($multiCapturesAllowed): WeroEventDependentPayment + public function setMultiCapturesAllowed(?bool $multiCapturesAllowed): WeroEventDependentPayment { $this->multiCapturesAllowed = $multiCapturesAllowed; return $this; diff --git a/src/Resources/EmbeddedResources/WeroTransactionData.php b/src/Resources/EmbeddedResources/WeroTransactionData.php index 80ac6076..e172e4e3 100644 --- a/src/Resources/EmbeddedResources/WeroTransactionData.php +++ b/src/Resources/EmbeddedResources/WeroTransactionData.php @@ -3,6 +3,7 @@ namespace UnzerSDK\Resources\EmbeddedResources; use stdClass; +use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Resources\AbstractUnzerResource; /* @@ -35,7 +36,7 @@ public function setEventDependentPayment(?WeroEventDependentPayment $eventDepend /** * @inheritDoc */ - public function handleResponse($response, string $method = null): void + public function handleResponse($response, string $method = HttpAdapterInterface::REQUEST_GET): void { parent::handleResponse($response, $method); if ($response instanceof stdClass && isset($response->eventDependentPayment)) { diff --git a/test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php b/test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php index 69301dd5..feca25e2 100644 --- a/test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php +++ b/test/unit/Resources/EmbeddedResources/WeroTransactionDataTest.php @@ -18,8 +18,8 @@ public function gettersSettersAndExposeShouldWork(): void $edp = (new WeroEventDependentPayment()) ->setCaptureTrigger(WeroCaptureTriggers::SERVICEFULFILMENT) ->setAmountPaymentType(WeroAmountPaymentTypes::PAY) - ->setMaxAuthToCaptureTime('300') - ->setMultiCapturesAllowed('false'); + ->setMaxAuthToCaptureTime(300) + ->setMultiCapturesAllowed(false); $wtd = (new WeroTransactionData()) ->setEventDependentPayment($edp); From a14a78bdb443ccb1f841d976e1462d7dbb49dbff Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Mon, 18 Aug 2025 11:12:27 +0200 Subject: [PATCH 5/8] [CC-2672] Add Wero. --- .../HasAdditionalTransactionDataTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/unit/Traits/HasAdditionalTransactionDataTest.php b/test/unit/Traits/HasAdditionalTransactionDataTest.php index 2a926e85..93707196 100644 --- a/test/unit/Traits/HasAdditionalTransactionDataTest.php +++ b/test/unit/Traits/HasAdditionalTransactionDataTest.php @@ -11,9 +11,13 @@ namespace UnzerSDK\test\unit\Traits; +use UnzerSDK\Constants\WeroAmountPaymentTypes; +use UnzerSDK\Constants\WeroCaptureTriggers; use UnzerSDK\Resources\EmbeddedResources\CardTransactionData; use UnzerSDK\Resources\EmbeddedResources\RiskData; use UnzerSDK\Resources\EmbeddedResources\ShippingData; +use UnzerSDK\Resources\EmbeddedResources\WeroEventDependentPayment; +use UnzerSDK\Resources\EmbeddedResources\WeroTransactionData; use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\test\BasePaymentTest; @@ -110,6 +114,69 @@ public function exposeCardDataAsExpected(): void $this->assertEquals('exemptionType', $additionalTransactionData->card['exemptionType']); } + /** + * WeroData setters/getters should work as expected. + * + * @test + */ + public function setAndGetWeroData(): void + { + $dummy = new TraitDummyHasAdditionalTransactionData(); + $this->assertNull($dummy->getWeroTransactionData()); + + $edp = (new WeroEventDependentPayment()) + ->setCaptureTrigger(WeroCaptureTriggers::SERVICEFULFILMENT) + ->setAmountPaymentType(WeroAmountPaymentTypes::PAY) + ->setMaxAuthToCaptureTime(300) + ->setMultiCapturesAllowed(false); + + $weroTransactionData = (new WeroTransactionData()) + ->setEventDependentPayment($edp); + + $dummy->setWeroTransactionData($weroTransactionData); + + $wero = $dummy->getWeroTransactionData(); + $this->assertNotNull($wero); + $this->assertInstanceOf(WeroTransactionData::class, $wero); + $this->assertInstanceOf(WeroEventDependentPayment::class, $wero->getEventDependentPayment()); + $this->assertEquals(WeroCaptureTriggers::SERVICEFULFILMENT, $wero->getEventDependentPayment()->getCaptureTrigger()); + $this->assertEquals(WeroAmountPaymentTypes::PAY, $wero->getEventDependentPayment()->getAmountPaymentType()); + $this->assertSame(300, $wero->getEventDependentPayment()->getMaxAuthToCaptureTime()); + $this->assertSame(false, $wero->getEventDependentPayment()->getMultiCapturesAllowed()); + } + + /** + * WeroData should be exposed correctly. + * + * @test + */ + public function exposeWeroDataAsExpected(): void + { + $dummy = new TraitDummyHasAdditionalTransactionData(); + $this->assertNull($dummy->getWeroTransactionData()); + + $edp = (new WeroEventDependentPayment()) + ->setCaptureTrigger(WeroCaptureTriggers::SERVICEFULFILMENT) + ->setAmountPaymentType(WeroAmountPaymentTypes::PAY) + ->setMaxAuthToCaptureTime(300) + ->setMultiCapturesAllowed(false); + + $weroTransactionData = (new WeroTransactionData()) + ->setEventDependentPayment($edp); + + $dummy->setWeroTransactionData($weroTransactionData); + + $exposedResource = $dummy->expose(); + $this->assertNotNull($exposedResource['additionalTransactionData']); + $additionalTransactionData = $exposedResource['additionalTransactionData']; + + $this->assertArrayHasKey('eventDependentPayment', $additionalTransactionData->wero); + $this->assertEquals(WeroCaptureTriggers::SERVICEFULFILMENT, $additionalTransactionData->wero['eventDependentPayment']['captureTrigger']); + $this->assertEquals(WeroAmountPaymentTypes::PAY, $additionalTransactionData->wero['eventDependentPayment']['amountPaymentType']); + $this->assertSame(300, $additionalTransactionData->wero['eventDependentPayment']['maxAuthToCaptureTime']); + $this->assertSame(false, $additionalTransactionData->wero['eventDependentPayment']['multiCapturesAllowed']); + } + /** * Verify checkoutType can be set via typeId correctly. * From cfe962c95959315c3875c63265f84ebeae5d0cd3 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Mon, 18 Aug 2025 11:54:54 +0200 Subject: [PATCH 6/8] [CC-2672] Add Wero. --- src/Constants/WeroAmountPaymentTypes.php | 2 +- .../WeroEventDependentPayment.php | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Constants/WeroAmountPaymentTypes.php b/src/Constants/WeroAmountPaymentTypes.php index 1ccc0d03..aeb1ae4d 100644 --- a/src/Constants/WeroAmountPaymentTypes.php +++ b/src/Constants/WeroAmountPaymentTypes.php @@ -3,7 +3,7 @@ namespace UnzerSDK\Constants; /** - * Allowed amount payment type values for Wero event dependent payment. + * Allowed amount payment type values for Wero event-dependent payment. */ class WeroAmountPaymentTypes { diff --git a/src/Resources/EmbeddedResources/WeroEventDependentPayment.php b/src/Resources/EmbeddedResources/WeroEventDependentPayment.php index 4d4eb74f..e210e495 100644 --- a/src/Resources/EmbeddedResources/WeroEventDependentPayment.php +++ b/src/Resources/EmbeddedResources/WeroEventDependentPayment.php @@ -2,18 +2,18 @@ namespace UnzerSDK\Resources\EmbeddedResources; +use UnzerSDK\Constants\WeroAmountPaymentTypes; +use UnzerSDK\Constants\WeroCaptureTriggers; use UnzerSDK\Resources\AbstractUnzerResource; /** * Represents the `eventDependentPayment` object for Wero additional transaction data. - * - * Allowed values - * - captureTrigger: SHIPPING, DELIVERY, AVAILABILITY, SERVICEFULFILMENT, OTHER - * - amountPaymentType: PAY, PAYUPTO */ class WeroEventDependentPayment extends AbstractUnzerResource { + /** @see WeroCaptureTriggers */ protected ?string $captureTrigger = null; + /** @see WeroAmountPaymentTypes */ protected ?string $amountPaymentType = null; protected ?int $maxAuthToCaptureTime = null; protected ?bool $multiCapturesAllowed = null; @@ -23,6 +23,9 @@ public function getCaptureTrigger(): ?string return $this->captureTrigger; } + /** + * @see WeroCaptureTriggers for allowed values + */ public function setCaptureTrigger(?string $captureTrigger): WeroEventDependentPayment { $this->captureTrigger = $captureTrigger; @@ -34,6 +37,9 @@ public function getAmountPaymentType(): ?string return $this->amountPaymentType; } + /** + * @see WeroAmountPaymentTypes for allowed values + */ public function setAmountPaymentType(?string $amountPaymentType): WeroEventDependentPayment { $this->amountPaymentType = $amountPaymentType; From 277d2cb0c720b229f9ddd5ae8e754179a0c23f7b Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Thu, 21 Aug 2025 17:39:57 +0200 Subject: [PATCH 7/8] [CC-2672] Cleanup failing integration tests. --- test/BasePaymentTest.php | 2 +- .../PaymentTypes/PaylaterInstallmentTest.php | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/BasePaymentTest.php b/test/BasePaymentTest.php index 54d6bf0d..dae50318 100755 --- a/test/BasePaymentTest.php +++ b/test/BasePaymentTest.php @@ -292,7 +292,7 @@ public function createCharge($amount = 100.0): Charge */ public static function generateRandomId(): string { - return str_replace('.', '', microtime(true)); + return str_replace('.', '', random_int(0, 99999999)); } /** diff --git a/test/integration/PaymentTypes/PaylaterInstallmentTest.php b/test/integration/PaymentTypes/PaylaterInstallmentTest.php index 3770a9ab..bb98d74a 100644 --- a/test/integration/PaymentTypes/PaylaterInstallmentTest.php +++ b/test/integration/PaymentTypes/PaylaterInstallmentTest.php @@ -13,18 +13,18 @@ namespace UnzerSDK\test\integration\PaymentTypes; use UnzerSDK\Constants\CustomerTypes; +use UnzerSDK\Constants\ShippingTypes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\CustomerFactory; use UnzerSDK\Resources\EmbeddedResources\Address; -use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; +use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\test\BaseIntegrationTest; - use function count; class PaylaterInstallmentTest extends BaseIntegrationTest @@ -232,7 +232,7 @@ protected function createAuthorizeTransaction(): Authorization $ins = new PaylaterInstallment($plans->getId(), $selectedPlan->getNumberOfRates(), 'DE89370400440532013000', 'DE', 'Peter Mustermann'); $this->unzer->createPaymentType($ins); - $customer = $this->getCustomer()->setFirstname('Peter')->setLastname('Mustermann'); + $customer = $this->getCustomer(); $basket = $this->createBasket(); $authorization = new Authorization(99.99, 'EUR', self::RETURN_URL); @@ -244,17 +244,22 @@ protected function createAuthorizeTransaction(): Authorization */ public function getCustomer(): Customer { - $customer = CustomerFactory::createCustomer('Manuel', 'Weißmann'); + $customer = CustomerFactory::createCustomer('Maximilian', 'Mustermann'); $address = (new Address()) - ->setStreet('Hugo-Junckers-Straße 3') + ->setName('Maximilian Mustermann') + ->setStreet('Hugo-Junkers-Str. 3') ->setState('DE-BO') ->setZip('60386') ->setCity('Frankfurt am Main') ->setCountry('DE'); $customer + ->setSalutation('mr') ->setBillingAddress($address) - ->setBirthDate('2000-12-12') - ->setEmail('manuel-weissmann@unzer.com'); + ->setCustomerId('c' . substr(self::generateRandomId(), 0, 7)) + ->setShippingAddress((clone $address)->setShippingType(ShippingTypes::EQUALS_BILLING)) + ->setLanguage('de') + ->setBirthDate('1974-10-02') + ->setEmail('accept@unzer.com'); return $customer; } From e6219acd8e0b7813ec0cc167162c2546d52c4932 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Thu, 21 Aug 2025 17:51:41 +0200 Subject: [PATCH 8/8] [CC-2672] Enable wero config fo payment page. --- .../Paypage/PaymentMethodConfig.php | 16 +++++++++++++++- test/integration/Resources/PaypageV2Test.php | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php b/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php index e63914ca..1f75a8d4 100644 --- a/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php +++ b/src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php @@ -3,6 +3,7 @@ namespace UnzerSDK\Resources\EmbeddedResources\Paypage; use UnzerSDK\Resources\AbstractUnzerResource; +use UnzerSDK\Resources\EmbeddedResources\WeroEventDependentPayment; class PaymentMethodConfig extends AbstractUnzerResource { @@ -15,6 +16,19 @@ class PaymentMethodConfig extends AbstractUnzerResource protected ?bool $credentialOnFile = null; // card only. protected ?string $exemption = null; // card only. + protected ?WeroEventDependentPayment $eventDependentPayment = null; + + public function getEventDependentPayment(): ?WeroEventDependentPayment + { + return $this->eventDependentPayment; + } + + public function setEventDependentPayment(?WeroEventDependentPayment $eventDependentPayment): PaymentMethodConfig + { + $this->eventDependentPayment = $eventDependentPayment; + return $this; + } + /** * @param bool|null $enabled * @param int|null $order @@ -80,4 +94,4 @@ public function setExemption(?string $exemption): PaymentMethodConfig $this->exemption = $exemption; return $this; } -} \ No newline at end of file +} diff --git a/test/integration/Resources/PaypageV2Test.php b/test/integration/Resources/PaypageV2Test.php index 2b6b8238..18ca4ac6 100644 --- a/test/integration/Resources/PaypageV2Test.php +++ b/test/integration/Resources/PaypageV2Test.php @@ -5,12 +5,15 @@ use UnzerSDK\Constants\CustomerGroups; use UnzerSDK\Constants\ExemptionType; use UnzerSDK\Constants\PaypageCheckoutTypes; +use UnzerSDK\Constants\WeroAmountPaymentTypes; +use UnzerSDK\Constants\WeroCaptureTriggers; use UnzerSDK\Resources\EmbeddedResources\Paypage\PaymentMethodConfig; use UnzerSDK\Resources\EmbeddedResources\Paypage\PaymentMethodsConfigs; use UnzerSDK\Resources\EmbeddedResources\Paypage\Resources; use UnzerSDK\Resources\EmbeddedResources\Paypage\Style; use UnzerSDK\Resources\EmbeddedResources\Paypage\Urls; use UnzerSDK\Resources\EmbeddedResources\Risk; +use UnzerSDK\Resources\EmbeddedResources\WeroEventDependentPayment; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaymentTypes\Alipay; use UnzerSDK\Resources\PaymentTypes\Applepay; @@ -294,6 +297,18 @@ public function paymentMethodsConfigsDataProvider() 'paypal' => $enabledConfig ]); + $withWeroConfig = new PaymentMethodsConfigs(); + $withWeroConfig->setMethodConfigs([ + 'wero' => (new PaymentMethodConfig()) + ->setEnabled(true) + ->setEventDependentPayment($edp = (new WeroEventDependentPayment()) + ->setCaptureTrigger(WeroCaptureTriggers::SERVICEFULFILMENT) + ->setAmountPaymentType(WeroAmountPaymentTypes::PAY) + ->setMaxAuthToCaptureTime(300) + ->setMultiCapturesAllowed(false) + ) + ]); + $withCardSpecificConfig = (new PaymentMethodsConfigs())->addMethodConfig(Card::class, $cardConfig); @@ -331,7 +346,8 @@ public function paymentMethodsConfigsDataProvider() 'Method Configs' => [$withMethodConfigs], 'CardSpecificConfig' => [$withCardSpecificConfig], 'ClassNames' => [$withClassNames], - 'PaylaterConfig' => [$withPaylaterConfig] + 'PaylaterConfig' => [$withPaylaterConfig], + 'WeroConfig' => [$withWeroConfig] ]; } }