Skip to content

Commit 68f840f

Browse files
authored
Merge pull request #74 from unzerdev/UMCS-434/basket_v2_examples
(fix) (UMCS-434) Make examples use basket v2.
2 parents b0d3065 + 6d8c376 commit 68f840f

File tree

8 files changed

+72
-37
lines changed

8 files changed

+72
-37
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
77
### Added
88
* Add Support for basket `v2` resource.
99
### Changed
10-
* Add support for payment state `create` which can occur when using payment pages.
11-
* Several minor improvements.
10+
* Add support for payment state `create` which can occur when using payment pages.
11+
* Examples:
12+
* Use `v2/basket` resource for secured payment methods and payment pages.
13+
* Remove broken image-URLs of payment page examples.
14+
* Several minor improvements.
1215

1316
## [1.1.4.2](https://github.com/unzerdev/php-sdk/compare/1.1.4.1..1.1.4.2)
1417
### Added

examples/EmbeddedPayPage/Controller.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@
7878
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));
7979

8080
// ... however you can customize the Payment Page using additional parameters.
81-
$paypage->setLogoImage('https://dev.unzer.com/wp-content/uploads/2020/09/Unzer__PrimaryLogo_Raspberry_RGB.png')
82-
->setShopName('My Test Shop')
81+
$paypage->setShopName('My Test Shop')
8382
->setTagline('Try and stop us from being awesome!')
8483
->setOrderId($orderId)
8584
->setInvoiceId('i' . microtime(true));
@@ -88,10 +87,17 @@
8887
$paypage->setEffectiveInterestRate(4.99);
8988

9089
// ... a Basket is mandatory for InstallmentSecured
91-
$basketItem = (new BasketItem('Hat', 100.00, 119.00, 1))
92-
->setAmountGross(119.0)
93-
->setAmountVat(19.0);
94-
$basket = new Basket($orderId, 119.0, 'EUR', [$basketItem]);
90+
$basketItem = (new BasketItem())
91+
->setAmountPerUnitGross(119.00)
92+
->setVat(19.00)
93+
->setQuantity(1)
94+
->setBasketItemReferenceId('item1')
95+
->setTitle('Hat');
96+
97+
$basket = new Basket($orderId);
98+
$basket->setTotalValueGross(119.00)
99+
->addBasketItem($basketItem)
100+
->setCurrencyCode('EUR');
95101

96102
if ($transactionType === 'charge') {
97103
$unzer->initPayPageCharge($paypage, $customer, $basket);

examples/HostedPayPage/Controller.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
8484
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));
8585

8686
// ... however you can customize the Payment Page using additional parameters.
87-
$paypage->setLogoImage('https://dev.unzer.com/wp-content/uploads/2020/09/Unzer__PrimaryLogo_Raspberry_RGB.png')
88-
->setFullPageImage('https://dev.unzer.com/wp-content/uploads/2020/09/01_Unzer_Ambitious_RGB_LoRes.jpg')
89-
->setShopName('My Test Shop')
87+
$paypage->setShopName('My Test Shop')
9088
->setShopDescription('Best shop in the whole world!')
9189
->setTagline('Try and stop us from being awesome!')
9290
->setOrderId('OrderNr' . $orderId)
@@ -101,10 +99,17 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
10199
$paypage->setEffectiveInterestRate(4.99);
102100

103101
// ... a Basket is mandatory for InstallmentSecured
104-
$basketItem = (new BasketItem('Hat', 100.00, 119.00, 1))
105-
->setAmountGross(119.0)
106-
->setAmountVat(19.0);
107-
$basket = new Basket($orderId, 119.0, 'EUR', [$basketItem]);
102+
$basketItem = (new BasketItem())
103+
->setAmountPerUnitGross(119.00)
104+
->setVat(19.00)
105+
->setQuantity(1)
106+
->setBasketItemReferenceId('item1')
107+
->setTitle('Hat');
108+
109+
$basket = new Basket($orderId);
110+
$basket->setTotalValueGross(119.00)
111+
->addBasketItem($basketItem)
112+
->setCurrencyCode('EUR');
108113

109114
if ($transactionType === 'charge') {
110115
$unzer->initPayPageCharge($paypage, $customer, $basket);

examples/InstallmentSecured/Controller.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,17 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
8787
->setEmail('[email protected]');
8888

8989
// A Basket is mandatory for Installment Secured payment type
90-
$basketItem = (new BasketItem('Hat', 100.00, 119.00, 1))
91-
->setAmountGross(119.0)
92-
->setAmountVat(19.0);
93-
$basket = (new Basket($orderId, 119.0, 'EUR', [$basketItem]))->setAmountTotalVat(19.0);
90+
$basketItem = (new BasketItem())
91+
->setAmountPerUnitGross(119.00)
92+
->setVat(19)
93+
->setQuantity(1)
94+
->setBasketItemReferenceId('item1')
95+
->setTitle('Hat');
96+
97+
$basket = new Basket($orderId);
98+
$basket->setTotalValueGross(119.00)
99+
->addBasketItem($basketItem)
100+
->setCurrencyCode('EUR');
94101

95102
// initialize the payment
96103
$authorize = $unzer->authorize(

examples/InvoiceSecured/Controller.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,17 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
7171
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));
7272

7373
// A Basket is mandatory for Invoice Secured payment type
74-
$basketItem = (new BasketItem('Hat', 100.00, 119.00, 1))
75-
->setAmountGross(119.0)
76-
->setAmountVat(19.0);
77-
$basket = new Basket($orderId, 119.0, 'EUR', [$basketItem]);
74+
$basketItem = (new BasketItem())
75+
->setAmountPerUnitGross(119.00)
76+
->setVat(19.00)
77+
->setQuantity(1)
78+
->setBasketItemReferenceId('item1')
79+
->setTitle('Hat');
80+
81+
$basket = new Basket($orderId);
82+
$basket->setTotalValueGross(119.00)
83+
->addBasketItem($basketItem)
84+
->setCurrencyCode('EUR');
7885

7986
$transaction = $unzer->charge(119.0, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket);
8087

examples/SepaDirectDebitSecured/Controller.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,17 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
6767
$orderId = 'o' . str_replace(['0.', ' '], '', microtime(false));
6868

6969
// A Basket is mandatory for SEPA direct debit secured payment type
70-
$basketItem = (new BasketItem('Hat', 100.00, 119.00, 1))
71-
->setAmountGross(119.0)
72-
->setAmountVat(19.0);
73-
$basket = new Basket($orderId, 119.0, 'EUR', [$basketItem]);
70+
$basketItem = (new BasketItem())
71+
->setAmountPerUnitGross(119.00)
72+
->setVat(19.00)
73+
->setQuantity(1)
74+
->setBasketItemReferenceId('item1')
75+
->setTitle('Hat');
76+
77+
$basket = new Basket($orderId);
78+
$basket->setTotalValueGross(119.00)
79+
->addBasketItem($basketItem)
80+
->setCurrencyCode('EUR');
7481

7582
$transaction = $unzer->charge(119.0, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket);
7683

examples/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function printMessage($type, $title, $text)
327327
server and redirected to a given RedirectUrl.
328328
</div>
329329
</div>
330-
<div class="ui attached white button" onclick="location.href='https://docs.unzer.com/accept-payments/accept-payments-payment-page';">
330+
<div class="ui attached white button" onclick="location.href='https://docs.unzer.com/online-payments/payment-pages/integrate-hpp/';">
331331
Documentation
332332
</div>
333333
<div id="tryHostedPayPageExample" class="ui bottom attached green button" onclick="location.href='HostedPayPage/';">
@@ -344,7 +344,7 @@ function printMessage($type, $title, $text)
344344
The Payment Page will be shown as an Overlay in your own shop.
345345
</div>
346346
</div>
347-
<div class="ui attached white button" onclick="location.href='https://docs.unzer.com/accept-payments/accept-payments-payment-page';">
347+
<div class="ui attached white button" onclick="location.href='https://docs.unzer.com/online-payments/payment-pages/integrate-epp/';">
348348
Documentation
349349
</div>
350350
<div id="tryEmbeddedPayPageExample" class="ui bottom attached green button" onclick="location.href='EmbeddedPayPage/';">

src/Resources/TransactionTypes/Authorization.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class Authorization extends AbstractTransactionType
6565
/**
6666
* Authorization constructor.
6767
*
68-
* @param float $amount
69-
* @param string $currency
70-
* @param string $returnUrl
68+
* @param float|null $amount
69+
* @param string|null $currency
70+
* @param string|null $returnUrl
7171
*/
7272
public function __construct($amount = null, $currency = null, $returnUrl = null)
7373
{
@@ -87,7 +87,7 @@ public function getAmount(): ?float
8787
}
8888

8989
/**
90-
* @param float $amount
90+
* @param float|null $amount
9191
*
9292
* @return self
9393
*/
@@ -120,7 +120,7 @@ public function getCurrency(): ?string
120120
}
121121

122122
/**
123-
* @param string $currency
123+
* @param string|null $currency
124124
*
125125
* @return self
126126
*/
@@ -177,7 +177,7 @@ public function getPaymentReference(): ?string
177177
}
178178

179179
/**
180-
* @param $paymentReference
180+
* @param string|null $paymentReference
181181
*
182182
* @return Authorization
183183
*/
@@ -265,7 +265,7 @@ protected function getResourcePath($httpMethod = HttpAdapterInterface::REQUEST_G
265265
/**
266266
* Full cancel of this authorization.
267267
*
268-
* @param null $amount
268+
* @param float|null $amount
269269
*
270270
* @return Cancellation
271271
*
@@ -280,7 +280,7 @@ public function cancel($amount = null): Cancellation
280280
/**
281281
* Charge authorization.
282282
*
283-
* @param null $amount
283+
* @param float|null $amount
284284
*
285285
* @return Charge
286286
*

0 commit comments

Comments
 (0)