Skip to content

Commit f6a5f11

Browse files
authored
Update paypal http client (#27)
1 parent c91ece0 commit f6a5f11

File tree

5 files changed

+48
-105
lines changed

5 files changed

+48
-105
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"php": "^7.4|^8.0|^8.1",
2121
"ext-json": "*",
2222
"brick/money": "^0.5.2",
23-
"phpjuice/paypal-http-client": "1.0.0"
23+
"phpjuice/paypal-http-client": "^1.0"
2424
},
2525
"require-dev": {
2626
"squizlabs/php_codesniffer": "^3.4",

src/Concerns/HasCollection.php

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PayPal\Checkout\Concerns;
44

5+
use PayPal\Checkout\Orders\Item;
6+
57
trait HasCollection
68
{
79
/**
@@ -50,6 +52,11 @@ public function offsetUnset(string $offset)
5052
unset($this->items[$offset]);
5153
}
5254

55+
/**
56+
* @param mixed $offset
57+
* @param mixed $value
58+
* @return void
59+
*/
5360
public function offsetSet($offset, $value)
5461
{
5562
if (is_null($offset)) {
@@ -61,6 +68,7 @@ public function offsetSet($offset, $value)
6168

6269
/**
6370
* @param string $offset
71+
* @return mixed|Item|null
6472
*/
6573
public function offsetGet(string $offset)
6674
{

src/Orders/AmountBreakdown.php

+11-22
Original file line numberDiff line numberDiff line change
@@ -65,54 +65,43 @@ public function toArray(): array
6565
];
6666

6767
if ($this->hasDiscount()) {
68+
/** @var Money $discount */
69+
$discount = $this->getDiscount();
6870
$data['breakdown']['discount'] = [
69-
'currency_code' => $this->discount->getCurrency()->getCurrencyCode(),
70-
'value' => (string) $this->discount->getAmount(),
71+
'currency_code' => $discount->getCurrency()->getCurrencyCode(),
72+
'value' => (string) $discount->getAmount(),
7173
];
7274
}
7375

7476
return $data;
7577
}
7678

77-
/**
78-
* @return bool
79-
*/
8079
public function hasDiscount(): bool
8180
{
8281
return (bool) $this->discount;
8382
}
8483

85-
/**
86-
* return's discount.
87-
* @return Money
88-
*/
89-
public function getDiscount(): Money
84+
public function getDiscount(): ?Money
9085
{
9186
return $this->discount;
9287
}
9388

94-
/**
95-
* @param Money $discount
96-
*/
97-
public function setDiscount(Money $discount)
89+
public function setDiscount(Money $discount): AmountBreakdown
9890
{
9991
$this->discount = $discount;
92+
93+
return $this;
10094
}
10195

102-
/**
103-
* return's item_total.
104-
* @return Money
105-
*/
10696
public function getItemTotal(): Money
10797
{
10898
return $this->item_total;
10999
}
110100

111-
/**
112-
* @param Money $item_total
113-
*/
114-
public function setItemTotal(Money $item_total)
101+
public function setItemTotal(Money $item_total): AmountBreakdown
115102
{
116103
$this->item_total = $item_total;
104+
105+
return $this;
117106
}
118107
}

src/Orders/ApplicationContext.php

+22-81
Original file line numberDiff line numberDiff line change
@@ -106,47 +106,34 @@ class ApplicationContext implements Arrayable, Jsonable
106106
protected string $user_action = ACTION_CONTINUE;
107107

108108
/**
109-
* Create a new collection.
110-
*
111109
* @param string|null $brand_name
112-
* @param string|null $locale
113-
* @param string|null $landing_page
114-
* @param string|null $shipping_preference
110+
* @param string $locale
111+
* @param string $landing_page
112+
* @param string $shipping_preference
115113
* @param string|null $return_url
116114
* @param string|null $cancel_url
117115
*/
118116
public function __construct(
119117
?string $brand_name = null,
120-
?string $locale = 'en-US',
121-
?string $landing_page = NO_PREFERENCE,
122-
?string $shipping_preference = NO_SHIPPING,
118+
string $locale = 'en-US',
119+
string $landing_page = NO_PREFERENCE,
120+
string $shipping_preference = NO_SHIPPING,
123121
?string $return_url = null,
124122
?string $cancel_url = null
125123
) {
126-
$this->setBrandName($brand_name);
127-
$this->setLocale($locale);
128-
$this->setLandingPage($landing_page);
129-
$this->setShippingPreference($shipping_preference);
130-
$this->setReturnUrl($return_url);
131-
$this->setCancelUrl($cancel_url);
124+
$this->brand_name = $brand_name;
125+
$this->locale = $locale;
126+
$this->landing_page = $landing_page;
127+
$this->shipping_preference = $shipping_preference;
128+
$this->return_url = $return_url;
129+
$this->cancel_url = $cancel_url;
132130
}
133131

134-
/**
135-
* Create a new collection.
136-
*
137-
* @param string|null $brand_name
138-
* @param string|null $locale
139-
* @param string|null $landing_page
140-
* @param string|null $shipping_preference
141-
* @param string|null $return_url
142-
* @param string|null $cancel_url
143-
* @return ApplicationContext
144-
*/
145132
public static function create(
146133
?string $brand_name = null,
147-
?string $locale = 'en-US',
148-
?string $landing_page = NO_PREFERENCE,
149-
?string $shipping_preference = NO_SHIPPING,
134+
string $locale = 'en-US',
135+
string $landing_page = NO_PREFERENCE,
136+
string $shipping_preference = NO_SHIPPING,
150137
?string $return_url = null,
151138
?string $cancel_url = null
152139
): ApplicationContext {
@@ -183,55 +170,36 @@ function ($item) {
183170
);
184171
}
185172

186-
/**
187-
* gets brand_name.
188-
*/
189173
public function getBrandName(): ?string
190174
{
191175
return $this->brand_name;
192176
}
193177

194-
/**
195-
* sets the brand_name.
196-
*/
197-
public function setBrandName($brand_name): self
178+
public function setBrandName(string $brand_name): self
198179
{
199180
$this->brand_name = $brand_name;
200181

201182
return $this;
202183
}
203184

204-
/**
205-
* gets brand_name.
206-
*/
207185
public function getLocale(): string
208186
{
209187
return $this->locale;
210188
}
211189

212-
/**
213-
* sets the locale.
214-
*/
215-
public function setLocale($locale): self
190+
public function setLocale(string $locale): self
216191
{
217192
$this->locale = $locale;
218193

219194
return $this;
220195
}
221196

222-
/**
223-
* gets shipping_preference.
224-
*/
225197
public function getShippingPreference(): string
226198
{
227199
return $this->shipping_preference;
228200
}
229201

230-
/**
231-
* sets the shipping_preference.
232-
* @noinspection PhpUnused
233-
*/
234-
public function setShippingPreference($shipping_preference): self
202+
public function setShippingPreference(string $shipping_preference): self
235203
{
236204
$validOptions = [GET_FROM_FILE, NO_SHIPPING, SET_PROVIDED_ADDRESS];
237205
if (!in_array($shipping_preference, $validOptions)) {
@@ -243,19 +211,12 @@ public function setShippingPreference($shipping_preference): self
243211
return $this;
244212
}
245213

246-
/**
247-
* gets landing_page.
248-
* @noinspection PhpUnused
249-
*/
250214
public function getLandingPage(): string
251215
{
252216
return $this->landing_page;
253217
}
254218

255-
/**
256-
* sets the landing_page.
257-
*/
258-
public function setLandingPage($landing_page): self
219+
public function setLandingPage(string $landing_page): self
259220
{
260221
$validOptions = [LOGIN, BILLING, NO_PREFERENCE];
261222
if (!in_array($landing_page, $validOptions)) {
@@ -267,19 +228,12 @@ public function setLandingPage($landing_page): self
267228
return $this;
268229
}
269230

270-
/**
271-
* gets user_action.
272-
*/
273231
public function getUserAction(): string
274232
{
275233
return $this->user_action;
276234
}
277235

278-
/**
279-
* sets the user_action.
280-
* @noinspection PhpUnused
281-
*/
282-
public function setUserAction($user_action): self
236+
public function setUserAction(string $user_action): self
283237
{
284238
$validOptions = [ACTION_CONTINUE, ACTION_PAY_NOW];
285239
if (!in_array($user_action, $validOptions)) {
@@ -290,37 +244,24 @@ public function setUserAction($user_action): self
290244
return $this;
291245
}
292246

293-
/**
294-
* gets return_url.
295-
* @noinspection PhpUnused
296-
*/
297247
public function getReturnUrl(): ?string
298248
{
299249
return $this->return_url;
300250
}
301251

302-
/**
303-
* sets the return_url.
304-
*/
305-
public function setReturnUrl($return_url): self
252+
public function setReturnUrl(string $return_url): self
306253
{
307254
$this->return_url = $return_url;
308255

309256
return $this;
310257
}
311258

312-
/**
313-
* gets cancel_url.
314-
*/
315259
public function getCancelUrl(): ?string
316260
{
317261
return $this->cancel_url;
318262
}
319263

320-
/**
321-
* sets the cancel_url.
322-
*/
323-
public function setCancelUrl($cancel_url): self
264+
public function setCancelUrl(string $cancel_url): self
324265
{
325266
$this->cancel_url = $cancel_url;
326267

src/Orders/Order.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ public function toArray(): array
192192
fn(PurchaseUnit $purchase_unit) => $purchase_unit->toArray(),
193193
$this->purchase_units
194194
),
195-
'application_context' => $this->application_context->toArray(),
195+
'application_context' => $this->application_context ? $this->application_context->toArray() : null,
196196
];
197197
}
198198

199+
/**
200+
* @param mixed $offset
201+
* @param mixed $value
202+
* @return void
203+
*/
199204
public function offsetSet($offset, $value)
200205
{
201206
if (is_null($offset)) {

0 commit comments

Comments
 (0)