Skip to content

Commit b0d3065

Browse files
authored
Merge pull request #73 from unzerdev/UMCS-419/update_basket
Umcs 419/update basket
2 parents e851194 + 51ffff3 commit b0d3065

File tree

16 files changed

+730
-40
lines changed

16 files changed

+730
-40
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6-
## [1.1.5,0](https://github.com/unzerdev/php-sdk/compare/1.1.4.2..1.1.5.0)
6+
## [1.1.5.0](https://github.com/unzerdev/php-sdk/compare/1.1.4.2..1.1.5.0)
7+
### Added
8+
* Add Support for basket `v2` resource.
79
### Changed
810
* Add support for payment state `create` which can occur when using payment pages.
911
* Several minor improvements.

src/Constants/ApiResponseCodes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ApiResponseCodes
6262
public const API_ERROR_RECURRING_PAYMENT_NOT_SUPPORTED = 'API.500.550.004';
6363
public const API_ERROR_WEBHOOK_EVENT_ALREADY_REGISTERED = 'API.510.310.009';
6464
public const API_ERROR_WEBHOOK_CAN_NOT_BE_FOUND = 'API.510.310.008';
65+
public const API_ERROR_BASKET_NOT_FOUND = 'API.600.410.024';
6566
public const API_ERROR_BASKET_ITEM_IMAGE_INVALID_URL = 'API.600.630.004';
6667
public const API_ERROR_RECURRING_ALREADY_ACTIVE = 'API.640.550.006';
6768
public const API_ERROR_INVALID_KEY = 'API.710.000.002';

src/Interfaces/ResourceServiceInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ public function fetchMetadata($metadata): Metadata;
146146
public function createBasket(Basket $basket): Basket;
147147

148148
/**
149-
* Fetches and returns the given Basket (by object or id).
149+
* Fetches and returns the given Basket (by object or id). Since the PAPI provides 2 basket versions, this method performs up to two request.
150+
* Firstly the basket gets fetched from the "v2" endpoint.
151+
* Only If PAPI returns a specific "basket not found" error the function tries to fetch from the "v1" basket endpoint.
152+
*
153+
* @see \UnzerSDK\Constants\ApiResponseCodes::API_ERROR_BASKET_NOT_FOUND
150154
*
151155
* @param Basket|string $basket Basket object or id of basket to be fetched.
152156
*

src/Resources/AbstractUnzerResource.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ public function setSpecialParams(array $specialParams): self
160160
return $this;
161161
}
162162

163+
/**
164+
* Returns the API version for this resource.
165+
*
166+
* @return string
167+
*/
168+
public function getApiVersion(): string
169+
{
170+
return Unzer::API_VERSION;
171+
}
172+
163173
/**
164174
* @param array $additionalAttributes
165175
*

src/Resources/Basket.php

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,30 @@
3131

3232
class Basket extends AbstractUnzerResource
3333
{
34-
/** @var float $amountTotalGross */
34+
/**
35+
* @var float $amountTotalGross
36+
*
37+
* @deprecated since 1.1.5.0 @see $totalValueGross.
38+
*/
3539
protected $amountTotalGross = 0.0;
3640

37-
/** @var float $amountTotalDiscount */
41+
/**
42+
* @var float $amountTotalDiscount
43+
*
44+
* @deprecated since 1.1.5.0 @see Please set $amountDiscountPerUnitGross for each element of $basketItems instead.
45+
*/
3846
protected $amountTotalDiscount = 0.0;
3947

40-
/** @var float $amountTotalVat */
48+
/**
49+
* @var float $amountTotalVat
50+
*
51+
* @deprecated since 1.1.5.0 Please set the $vat in percent for each element of $basketItems instead, if not already happened. The actual amount is not required anymore.
52+
*/
4153
protected $amountTotalVat = 0.0;
4254

55+
/** @var float $totalValueGross */
56+
protected $totalValueGross = 0.0;
57+
4358
/** @var string $currencyCode */
4459
protected $currencyCode;
4560

@@ -55,6 +70,8 @@ class Basket extends AbstractUnzerResource
5570
/**
5671
* Basket constructor.
5772
*
73+
* @deprecated since 1.1.5.0 Please call constructor without parameters and use setter functions instead.
74+
*
5875
* @param float $amountTotalGross
5976
* @param string $currencyCode
6077
* @param string $orderId
@@ -76,6 +93,8 @@ public function __construct(
7693

7794
/**
7895
* @return float
96+
*
97+
* @deprecated since 1.1.5.0 @see $getTotalValueGross.
7998
*/
8099
public function getAmountTotalGross(): float
81100
{
@@ -85,6 +104,8 @@ public function getAmountTotalGross(): float
85104
/**
86105
* @param float $amountTotalGross
87106
*
107+
* @deprecated since 1.1.5.0 @see $getTotalValueGross.
108+
*
88109
* @return Basket
89110
*/
90111
public function setAmountTotalGross(float $amountTotalGross): Basket
@@ -96,6 +117,27 @@ public function setAmountTotalGross(float $amountTotalGross): Basket
96117
/**
97118
* @return float
98119
*/
120+
public function getTotalValueGross(): float
121+
{
122+
return $this->totalValueGross;
123+
}
124+
125+
/**
126+
* @param float $totalValueGross
127+
*
128+
* @return Basket
129+
*/
130+
public function setTotalValueGross(float $totalValueGross): Basket
131+
{
132+
$this->totalValueGross = $totalValueGross;
133+
return $this;
134+
}
135+
136+
/**
137+
* @return float
138+
*
139+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
140+
*/
99141
public function getAmountTotalDiscount(): float
100142
{
101143
return $this->amountTotalDiscount;
@@ -104,6 +146,8 @@ public function getAmountTotalDiscount(): float
104146
/**
105147
* @param float $amountTotalDiscount
106148
*
149+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
150+
*
107151
* @return Basket
108152
*/
109153
public function setAmountTotalDiscount(float $amountTotalDiscount): Basket
@@ -114,6 +158,8 @@ public function setAmountTotalDiscount(float $amountTotalDiscount): Basket
114158

115159
/**
116160
* @return float
161+
*
162+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
117163
*/
118164
public function getAmountTotalVat(): float
119165
{
@@ -123,6 +169,8 @@ public function getAmountTotalVat(): float
123169
/**
124170
* @param float $amountTotalVat
125171
*
172+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
173+
*
126174
* @return Basket
127175
*/
128176
public function setAmountTotalVat(float $amountTotalVat): Basket
@@ -269,6 +317,17 @@ public function expose(): array
269317
return $returnArray;
270318
}
271319

320+
/**
321+
* {@inheritDoc}
322+
*/
323+
public function getApiVersion(): string
324+
{
325+
if (!empty($this->getTotalValueGross())) {
326+
return 'v2';
327+
}
328+
return parent::getApiVersion();
329+
}
330+
272331
/**
273332
* Returns the key of the last BasketItem in the Array.
274333
*

src/Resources/EmbeddedResources/BasketItem.php

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,45 @@ class BasketItem extends AbstractUnzerResource
3737
/** @var float $vat */
3838
protected $vat = 0.0;
3939

40-
/** @var float $amountDiscount */
40+
/**
41+
* @var float $amountDiscount
42+
*
43+
* @deprecated since 1.1.5.0 @see $amountDiscountPerUnitGross.
44+
*/
4145
protected $amountDiscount = 0.0;
4246

43-
/** @var float $amountGross */
47+
/** @var float $amountDiscountPerUnitGross */
48+
protected $amountDiscountPerUnitGross = 0.0;
49+
50+
/**
51+
* @var float $amountGross
52+
*
53+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
54+
*/
4455
protected $amountGross = 0.0;
4556

46-
/** @var float $amountVat */
57+
/**
58+
* @var float $amountVat
59+
*
60+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
61+
*/
4762
protected $amountVat = 0.0;
4863

49-
/** @var float $amountPerUnit */
64+
/**
65+
* @var float $amountPerUnit
66+
*
67+
* @deprecated since 1.1.5.0 @see amountPerUnitGross
68+
*/
5069
protected $amountPerUnit = 0.0;
5170

52-
/** @var float $amountNet */
71+
/** @var float $amountPerUnitGross */
72+
protected $amountPerUnitGross = 0.0;
73+
74+
/**
75+
* @var float $amountNet
76+
*
77+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
78+
*/
5379
protected $amountNet = 0.0;
5480

5581
/** @var string $unit */
@@ -70,6 +96,8 @@ class BasketItem extends AbstractUnzerResource
7096
/**
7197
* BasketItem constructor.
7298
*
99+
* @deprecated since 1.1.5.0 Please call constructor without parameters and use setter functions instead.
100+
*
73101
* @param string $title
74102
* @param float $amountNet
75103
* @param float $amountPerUnit
@@ -148,6 +176,8 @@ public function setVat(float $vat): BasketItem
148176

149177
/**
150178
* @return float
179+
*
180+
* @deprecated since 1.1.5.0 @see $getAmountDiscountPerUnitGross.
151181
*/
152182
public function getAmountDiscount(): float
153183
{
@@ -157,6 +187,8 @@ public function getAmountDiscount(): float
157187
/**
158188
* @param float $amountDiscount
159189
*
190+
* @deprecated since 1.1.5.0 @see $setAmountDiscountPerUnitGross.
191+
*
160192
* @return BasketItem
161193
*/
162194
public function setAmountDiscount(float $amountDiscount): BasketItem
@@ -167,6 +199,8 @@ public function setAmountDiscount(float $amountDiscount): BasketItem
167199

168200
/**
169201
* @return float
202+
*
203+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
170204
*/
171205
public function getAmountGross(): float
172206
{
@@ -176,6 +210,8 @@ public function getAmountGross(): float
176210
/**
177211
* @param float $amountGross
178212
*
213+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
214+
*
179215
* @return BasketItem
180216
*/
181217
public function setAmountGross(float $amountGross): BasketItem
@@ -187,6 +223,46 @@ public function setAmountGross(float $amountGross): BasketItem
187223
/**
188224
* @return float
189225
*/
226+
public function getAmountDiscountPerUnitGross(): float
227+
{
228+
return $this->amountDiscountPerUnitGross;
229+
}
230+
231+
/**
232+
* @param float $amountDiscountPerUnitGross
233+
*
234+
* @return BasketItem
235+
*/
236+
public function setAmountDiscountPerUnitGross(float $amountDiscountPerUnitGross): BasketItem
237+
{
238+
$this->amountDiscountPerUnitGross = $amountDiscountPerUnitGross;
239+
return $this;
240+
}
241+
242+
/**
243+
* @return float
244+
*/
245+
public function getAmountPerUnitGross(): float
246+
{
247+
return $this->amountPerUnitGross;
248+
}
249+
250+
/**
251+
* @param float $amountPerUnitGross
252+
*
253+
* @return BasketItem
254+
*/
255+
public function setAmountPerUnitGross(float $amountPerUnitGross): BasketItem
256+
{
257+
$this->amountPerUnitGross = $amountPerUnitGross;
258+
return $this;
259+
}
260+
261+
/**
262+
* @return float
263+
*
264+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
265+
*/
190266
public function getAmountVat(): float
191267
{
192268
return $this->amountVat;
@@ -195,6 +271,8 @@ public function getAmountVat(): float
195271
/**
196272
* @param float $amountVat
197273
*
274+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
275+
*
198276
* @return BasketItem
199277
*/
200278
public function setAmountVat(float $amountVat): BasketItem
@@ -205,6 +283,8 @@ public function setAmountVat(float $amountVat): BasketItem
205283

206284
/**
207285
* @return float
286+
*
287+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
208288
*/
209289
public function getAmountPerUnit(): float
210290
{
@@ -214,6 +294,8 @@ public function getAmountPerUnit(): float
214294
/**
215295
* @param float $amountPerUnit
216296
*
297+
* @deprecated since 1.1.5.0 @see setAmountPerUnitGross
298+
*
217299
* @return BasketItem
218300
*/
219301
public function setAmountPerUnit(float $amountPerUnit): BasketItem
@@ -224,6 +306,8 @@ public function setAmountPerUnit(float $amountPerUnit): BasketItem
224306

225307
/**
226308
* @return float
309+
*
310+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
227311
*/
228312
public function getAmountNet(): float
229313
{
@@ -233,6 +317,8 @@ public function getAmountNet(): float
233317
/**
234318
* @param float $amountNet
235319
*
320+
* @deprecated since 1.1.5.0 Property is redundant and is no longer needed.
321+
*
236322
* @return BasketItem
237323
*/
238324
public function setAmountNet(float $amountNet): BasketItem

0 commit comments

Comments
 (0)