Skip to content

Commit 82948e1

Browse files
authored
CC-1581/add-linkpay-creation (#199)
* [CC-1581] - removed `preselectedMethod` from `\UnzerSDK\Resources\EmbeddedResources\Paypage\PaymentMethodsConfigs` since its not supported by API anymore. * [CC-1581] - add delete request - handle empty request body for paypage delete response. * [CC-1648] Add paypage style properties: - favicon
1 parent c66f9f8 commit 82948e1

File tree

9 files changed

+296
-23
lines changed

9 files changed

+296
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/composer.lock
99
/build
1010
/myreport.html/
11+
/test/.env
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace UnzerSDK\Resources\EmbeddedResources\Paypage;
4+
5+
use UnzerSDK\Resources\AbstractUnzerResource;
6+
7+
class AmountSettings extends AbstractUnzerResource
8+
{
9+
protected ?float $minimum = null;
10+
protected ?float $maximum = null;
11+
12+
/**
13+
* @param float|null $minimum
14+
* @param float|null $maximum
15+
*/
16+
public function __construct(?float $minimum, ?float $maximum)
17+
{
18+
$this->minimum = $minimum;
19+
$this->maximum = $maximum;
20+
}
21+
22+
public function getMinimum(): ?float
23+
{
24+
return $this->minimum;
25+
}
26+
27+
public function setMinimum(?float $minimum): AmountSettings
28+
{
29+
$this->minimum = $minimum;
30+
return $this;
31+
}
32+
33+
public function getMaximum(): ?float
34+
{
35+
return $this->maximum;
36+
}
37+
38+
public function setMaximum(?float $maximum): AmountSettings
39+
{
40+
$this->maximum = $maximum;
41+
return $this;
42+
}
43+
}

src/Resources/EmbeddedResources/Paypage/PaymentMethodsConfigs.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class PaymentMethodsConfigs extends AbstractUnzerResource
1717
];
1818

1919
protected ?PaymentMethodConfig $default = null;
20-
protected ?string $preselectedMethod = null;
2120

2221
/** @var PaymentMethodConfig[] */
2322
protected ?array $methodConfigs = null;
@@ -67,17 +66,6 @@ public function setDefault(?PaymentMethodConfig $default): PaymentMethodsConfigs
6766
return $this;
6867
}
6968

70-
public function getPreselectedMethod(): ?string
71-
{
72-
return $this->preselectedMethod;
73-
}
74-
75-
public function setPreselectedMethod(?string $preselectedMethod): PaymentMethodsConfigs
76-
{
77-
$this->preselectedMethod = $preselectedMethod;
78-
return $this;
79-
}
80-
8169
public function getMethodConfigs(): ?array
8270
{
8371
return $this->methodConfigs;

src/Resources/EmbeddedResources/Paypage/Style.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,43 @@
66

77
class Style extends AbstractUnzerResource
88
{
9+
protected ?bool $hideBasket = null;
910
protected ?bool $hideUnzerLogo = null;
1011
protected ?bool $shadows = null;
1112
protected ?string $backgroundColor = null;
1213
protected ?string $backgroundImage = null;
1314
protected ?string $brandColor = null;
1415
protected ?string $cornerRadius = null;
16+
protected ?string $favicon = null;
1517
protected ?string $font = null;
1618
protected ?string $footerColor = null;
1719
protected ?string $headerColor = null;
1820
protected ?string $logoImage = null;
1921
protected ?string $linkColor = null;
2022
protected ?string $textColor = null;
2123

24+
public function getHideBasket(): ?bool
25+
{
26+
return $this->hideBasket;
27+
}
28+
29+
public function setHideBasket(?bool $hideBasket): Style
30+
{
31+
$this->hideBasket = $hideBasket;
32+
return $this;
33+
}
34+
35+
public function getFavicon(): ?string
36+
{
37+
return $this->favicon;
38+
}
39+
40+
public function setFavicon(?string $favicon): Style
41+
{
42+
$this->favicon = $favicon;
43+
return $this;
44+
}
45+
2246
public function getLogoImage(): ?string
2347
{
2448
return $this->logoImage;

src/Resources/V2/Paypage.php

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace UnzerSDK\Resources\V2;
44

5+
use DateTime;
56
use stdClass;
67
use UnzerSDK\Adapter\HttpAdapterInterface;
78
use UnzerSDK\Apis\PaypageAPIConfig;
89
use UnzerSDK\Constants\PaypageCheckoutTypes;
910
use UnzerSDK\Constants\TransactionTypes;
1011
use UnzerSDK\Resources\AbstractUnzerResource;
12+
use UnzerSDK\Resources\EmbeddedResources\Paypage\AmountSettings;
1113
use UnzerSDK\Resources\EmbeddedResources\Paypage\Payment;
1214
use UnzerSDK\Resources\EmbeddedResources\Paypage\PaymentMethodsConfigs;
1315
use UnzerSDK\Resources\EmbeddedResources\Paypage\Resources;
@@ -29,7 +31,7 @@ class Paypage extends AbstractUnzerResource
2931
protected ?string $recurrenceType = null;
3032
protected ?string $shopName = null;
3133
protected ?string $type = null;
32-
protected float $amount;
34+
protected ?float $amount;
3335
protected string $currency;
3436

3537
/** @var string $mode "charge" or "authorize" */
@@ -41,17 +43,27 @@ class Paypage extends AbstractUnzerResource
4143
protected $paymentMethodsConfigs;
4244
protected ?Risk $risk = null;
4345

46+
// Linkpay only.
47+
protected ?string $alias = null;
48+
protected ?bool $multiUse = null;
49+
50+
protected ?DateTime $expiresAt = null;
51+
protected ?AmountSettings $amountSettings = null;
52+
53+
// Response fields
4454
private ?string $redirectUrl = null;
4555

4656
private ?array $payments = null;
4757
private ?int $total = null;
4858

59+
private ?string $qrCodeSvg = null;
60+
4961
/**
5062
* @param $amount
5163
* @param $currency
5264
* @param $mode
5365
*/
54-
public function __construct($amount, $currency, $mode = TransactionTypes::CHARGE)
66+
public function __construct(?float $amount, string $currency, string $mode = TransactionTypes::CHARGE)
5567
{
5668
$this->amount = $amount;
5769
$this->currency = $currency;
@@ -318,4 +330,70 @@ public function setCheckoutType(?string $checkoutType): Paypage
318330
$this->checkoutType = $checkoutType;
319331
return $this;
320332
}
333+
334+
public function getAlias(): ?string
335+
{
336+
return $this->alias;
337+
}
338+
339+
public function setAlias(?string $alias): Paypage
340+
{
341+
$this->alias = $alias;
342+
return $this;
343+
}
344+
345+
public function getMultiUse(): ?bool
346+
{
347+
return $this->multiUse;
348+
}
349+
350+
public function setMultiUse(?bool $multiUse): Paypage
351+
{
352+
$this->multiUse = $multiUse;
353+
return $this;
354+
}
355+
356+
public function getExpiresAt(): ?DateTime
357+
{
358+
return $this->expiresAt;
359+
}
360+
361+
public function setExpiresAt(?DateTime $expiresAt): Paypage
362+
{
363+
$this->expiresAt = $expiresAt;
364+
return $this;
365+
}
366+
367+
public function getAmountSettings(): ?AmountSettings
368+
{
369+
return $this->amountSettings;
370+
}
371+
372+
public function setAmountSettings(?AmountSettings $amountSettings): Paypage
373+
{
374+
$this->amountSettings = $amountSettings;
375+
return $this;
376+
}
377+
378+
public function getQrCodeSvg(): ?string
379+
{
380+
return $this->qrCodeSvg;
381+
}
382+
383+
public function setQrCodeSvg(?string $qrCodeSvg): Paypage
384+
{
385+
$this->qrCodeSvg = $qrCodeSvg;
386+
return $this;
387+
}
388+
389+
390+
public function expose()
391+
{
392+
$exposeArray = parent::expose();
393+
$expiresAtKey = 'expiresAt';
394+
if (isset($exposeArray[$expiresAtKey])) {
395+
$exposeArray['expiresAt'] = $this->getExpiresAt()->format(DateTime::ATOM);
396+
}
397+
return $exposeArray;
398+
}
321399
}

src/Services/ResourceService.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function send(
126126
$appendId = $httpMethod !== HttpAdapterInterface::REQUEST_POST;
127127
$uri = $resource->getUri($appendId, $httpMethod);
128128
$responseJson = $resource->getUnzerObject()->getHttpService()->send($uri, $resource, $httpMethod, $apiVersion);
129-
return json_decode($responseJson, false);
129+
return !empty($responseJson) ? json_decode($responseJson, false) : new stdClass();
130130
}
131131

132132
/**
@@ -413,13 +413,25 @@ public function getPaymentResource($payment): Payment
413413
return $paymentObject;
414414
}
415415

416+
/** Create Paypage V2 resource.
417+
* @throws UnzerApiException
418+
*/
416419
public function createPaypage(PaypageV2 $paypage): PaypageV2
417420
{
418421
$paypage->setParentResource($this->unzer);
419422
$this->createResource($paypage);
420423
return $paypage;
421424
}
422425

426+
/** Delete Paypage V2
427+
* @throws UnzerApiException
428+
*/
429+
public function deletePaypage(PaypageV2 $paypage): void
430+
{
431+
$paypage->setParentResource($this->unzer);
432+
$this->deleteResource($paypage);
433+
}
434+
423435
/**
424436
* @inheritDoc
425437
*/

src/Unzer.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,24 @@ public function createPaypage(PaypageV2 $paypage): PaypageV2
956956
return $this->resourceService->createPaypage($paypage);
957957
}
958958

959+
/**
960+
* Delete paypage v2 resource.
961+
*/
962+
public function deletePaypage(PaypageV2 $paypage): void
963+
{
964+
$this->resourceService->deletePaypage($paypage);
965+
}
966+
967+
/**
968+
* Delete paypage v2 by resource ID.
969+
*/
970+
public function deletePaypageById(string $paypageId): void
971+
{
972+
$paypage = new PaypageV2(null, '');
973+
$paypage->setId($paypageId);
974+
$this->deletePaypage($paypage);
975+
}
976+
959977
/**
960978
* Fetch list of associated payments for the given payment page. Use `\UnzerSDK\Resources\V2\Paypage::getPayments`
961979
* to get the list of payments.

0 commit comments

Comments
 (0)