Skip to content

Commit af41d62

Browse files
authored
[CC-2672] add WERO (#216)
1 parent 7e78dc1 commit af41d62

File tree

18 files changed

+465
-13
lines changed

18 files changed

+465
-13
lines changed

src/Constants/AdditionalTransactionDataKeys.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ class AdditionalTransactionDataKeys
1818
public const CHECKOUTTYPE = 'checkoutType';
1919

2020
public const CARD = 'card';
21+
public const WERO = 'wero';
2122
}

src/Constants/IdStrings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class IdStrings
5252
public const SOFORT = 'sft';
5353
public const TWINT = 'twt';
5454
public const WECHATPAY = 'wcp';
55+
public const WERO = 'wro';
5556

5657
public const OPEN_BANKING = 'obp';
5758

@@ -95,6 +96,7 @@ class IdStrings
9596
self::SOFORT,
9697
self::TWINT,
9798
self::WECHATPAY,
99+
self::WERO,
98100
self::OPEN_BANKING,
99101
];
100102
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace UnzerSDK\Constants;
4+
5+
/**
6+
* Allowed amount payment type values for Wero event-dependent payment.
7+
*/
8+
class WeroAmountPaymentTypes
9+
{
10+
public const PAY = 'PAY';
11+
public const PAYUPTO = 'PAYUPTO';
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace UnzerSDK\Constants;
4+
5+
/**
6+
* Allowed capture trigger values for Wero event dependent payment.
7+
*/
8+
class WeroCaptureTriggers
9+
{
10+
public const SHIPPING = 'SHIPPING';
11+
public const DELIVERY = 'DELIVERY';
12+
public const AVAILABILITY = 'AVAILABILITY';
13+
public const SERVICEFULFILMENT = 'SERVICEFULFILMENT';
14+
public const OTHER = 'OTHER';
15+
}

src/Resources/EmbeddedResources/Paypage/PaymentMethodConfig.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace UnzerSDK\Resources\EmbeddedResources\Paypage;
44

55
use UnzerSDK\Resources\AbstractUnzerResource;
6+
use UnzerSDK\Resources\EmbeddedResources\WeroEventDependentPayment;
67

78
class PaymentMethodConfig extends AbstractUnzerResource
89
{
@@ -15,6 +16,19 @@ class PaymentMethodConfig extends AbstractUnzerResource
1516
protected ?bool $credentialOnFile = null; // card only.
1617
protected ?string $exemption = null; // card only.
1718

19+
protected ?WeroEventDependentPayment $eventDependentPayment = null;
20+
21+
public function getEventDependentPayment(): ?WeroEventDependentPayment
22+
{
23+
return $this->eventDependentPayment;
24+
}
25+
26+
public function setEventDependentPayment(?WeroEventDependentPayment $eventDependentPayment): PaymentMethodConfig
27+
{
28+
$this->eventDependentPayment = $eventDependentPayment;
29+
return $this;
30+
}
31+
1832
/**
1933
* @param bool|null $enabled
2034
* @param int|null $order
@@ -80,4 +94,4 @@ public function setExemption(?string $exemption): PaymentMethodConfig
8094
$this->exemption = $exemption;
8195
return $this;
8296
}
83-
}
97+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\EmbeddedResources;
4+
5+
use UnzerSDK\Constants\WeroAmountPaymentTypes;
6+
use UnzerSDK\Constants\WeroCaptureTriggers;
7+
use UnzerSDK\Resources\AbstractUnzerResource;
8+
9+
/**
10+
* Represents the `eventDependentPayment` object for Wero additional transaction data.
11+
*/
12+
class WeroEventDependentPayment extends AbstractUnzerResource
13+
{
14+
/** @see WeroCaptureTriggers */
15+
protected ?string $captureTrigger = null;
16+
/** @see WeroAmountPaymentTypes */
17+
protected ?string $amountPaymentType = null;
18+
protected ?int $maxAuthToCaptureTime = null;
19+
protected ?bool $multiCapturesAllowed = null;
20+
21+
public function getCaptureTrigger(): ?string
22+
{
23+
return $this->captureTrigger;
24+
}
25+
26+
/**
27+
* @see WeroCaptureTriggers for allowed values
28+
*/
29+
public function setCaptureTrigger(?string $captureTrigger): WeroEventDependentPayment
30+
{
31+
$this->captureTrigger = $captureTrigger;
32+
return $this;
33+
}
34+
35+
public function getAmountPaymentType(): ?string
36+
{
37+
return $this->amountPaymentType;
38+
}
39+
40+
/**
41+
* @see WeroAmountPaymentTypes for allowed values
42+
*/
43+
public function setAmountPaymentType(?string $amountPaymentType): WeroEventDependentPayment
44+
{
45+
$this->amountPaymentType = $amountPaymentType;
46+
return $this;
47+
}
48+
49+
public function getMaxAuthToCaptureTime(): ?int
50+
{
51+
return $this->maxAuthToCaptureTime;
52+
}
53+
54+
public function setMaxAuthToCaptureTime(?int $maxAuthToCaptureTime): WeroEventDependentPayment
55+
{
56+
$this->maxAuthToCaptureTime = $maxAuthToCaptureTime;
57+
return $this;
58+
}
59+
60+
public function getMultiCapturesAllowed(): ?bool
61+
{
62+
return $this->multiCapturesAllowed;
63+
}
64+
65+
public function setMultiCapturesAllowed(?bool $multiCapturesAllowed): WeroEventDependentPayment
66+
{
67+
$this->multiCapturesAllowed = $multiCapturesAllowed;
68+
return $this;
69+
}
70+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\EmbeddedResources;
4+
5+
use stdClass;
6+
use UnzerSDK\Adapter\HttpAdapterInterface;
7+
use UnzerSDK\Resources\AbstractUnzerResource;
8+
9+
/*
10+
* Represents `wero` object of `additionalTransactionData`.
11+
*/
12+
13+
class WeroTransactionData extends AbstractUnzerResource
14+
{
15+
/** @var WeroEventDependentPayment|null $eventDependentPayment */
16+
protected ?WeroEventDependentPayment $eventDependentPayment = null;
17+
18+
/**
19+
* @return WeroEventDependentPayment|null
20+
*/
21+
public function getEventDependentPayment(): ?WeroEventDependentPayment
22+
{
23+
return $this->eventDependentPayment;
24+
}
25+
26+
/**
27+
* @param WeroEventDependentPayment|null $eventDependentPayment
28+
* @return WeroTransactionData
29+
*/
30+
public function setEventDependentPayment(?WeroEventDependentPayment $eventDependentPayment): WeroTransactionData
31+
{
32+
$this->eventDependentPayment = $eventDependentPayment;
33+
return $this;
34+
}
35+
36+
/**
37+
* @inheritDoc
38+
*/
39+
public function handleResponse($response, string $method = HttpAdapterInterface::REQUEST_GET): void
40+
{
41+
parent::handleResponse($response, $method);
42+
if ($response instanceof stdClass && isset($response->eventDependentPayment)) {
43+
$edp = $this->getEventDependentPayment() ?? new WeroEventDependentPayment();
44+
$edp->handleResponse($response->eventDependentPayment);
45+
$this->setEventDependentPayment($edp);
46+
}
47+
}
48+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\PaymentTypes;
4+
5+
class Wero extends BasePaymentType
6+
{
7+
}

src/Resources/TransactionTypes/AbstractTransactionType.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
namespace UnzerSDK\Resources\TransactionTypes;
1010

11+
use RuntimeException;
12+
use stdClass;
1113
use UnzerSDK\Adapter\HttpAdapterInterface;
1214
use UnzerSDK\Exceptions\UnzerApiException;
1315
use UnzerSDK\Resources\AbstractUnzerResource;
1416
use UnzerSDK\Resources\EmbeddedResources\CardTransactionData;
1517
use UnzerSDK\Resources\EmbeddedResources\RiskData;
1618
use UnzerSDK\Resources\EmbeddedResources\ShippingData;
19+
use UnzerSDK\Resources\EmbeddedResources\WeroTransactionData;
1720
use UnzerSDK\Resources\Payment;
1821
use UnzerSDK\Resources\PaymentTypes\BasePaymentType;
1922
use UnzerSDK\Traits\HasAdditionalTransactionData;
@@ -24,8 +27,6 @@
2427
use UnzerSDK\Traits\HasStates;
2528
use UnzerSDK\Traits\HasTraceId;
2629
use UnzerSDK\Traits\HasUniqueAndShortId;
27-
use RuntimeException;
28-
use stdClass;
2930

3031
abstract class AbstractTransactionType extends AbstractUnzerResource
3132
{
@@ -170,6 +171,7 @@ protected function handleAdditionalTransactionData(stdClass $response): void
170171
$this->handleRiskData($additionalTransactionData);
171172
$this->handleShipping($additionalTransactionData);
172173
$this->handleCardTransactionData($additionalTransactionData);
174+
$this->handleWeroTransactionData($additionalTransactionData);
173175
}
174176
}
175177

@@ -223,4 +225,21 @@ protected function handleCardTransactionData(stdClass $additionalTransactionData
223225
$this->setCardTransactionData($cardTransactionData);
224226
}
225227
}
228+
229+
/**
230+
* Handle WeroTransactionData object contained in additional transaction data from API response.
231+
*
232+
* @param stdClass $additionalTransactionData
233+
*
234+
* @return void
235+
*/
236+
protected function handleWeroTransactionData(stdClass $additionalTransactionData): void
237+
{
238+
$wero = $additionalTransactionData->wero ?? null;
239+
if ($wero !== null) {
240+
$weroTransactionData = $this->getWeroTransactionData() ?? new WeroTransactionData();
241+
$weroTransactionData->handleResponse($wero);
242+
$this->setWeroTransactionData($weroTransactionData);
243+
}
244+
}
226245
}

src/Services/ResourceService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use UnzerSDK\Resources\PaymentTypes\Sofort;
5353
use UnzerSDK\Resources\PaymentTypes\Twint;
5454
use UnzerSDK\Resources\PaymentTypes\Wechatpay;
55+
use UnzerSDK\Resources\PaymentTypes\Wero;
5556
use UnzerSDK\Resources\Recurring;
5657
use UnzerSDK\Resources\TransactionTypes\Authorization;
5758
use UnzerSDK\Resources\TransactionTypes\Cancellation;
@@ -957,6 +958,9 @@ public static function getTypeInstanceFromIdString($typeId): BasePaymentType
957958
case IdStrings::WECHATPAY:
958959
$paymentType = new Wechatpay();
959960
break;
961+
case IdStrings::WERO:
962+
$paymentType = new Wero();
963+
break;
960964
case IdStrings::OPEN_BANKING:
961965
$paymentType = new OpenbankingPis();
962966
break;

0 commit comments

Comments
 (0)