Skip to content

Commit

Permalink
Update paypal http client (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhdcodes authored Feb 19, 2022
1 parent c91ece0 commit f6a5f11
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 105 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"php": "^7.4|^8.0|^8.1",
"ext-json": "*",
"brick/money": "^0.5.2",
"phpjuice/paypal-http-client": "1.0.0"
"phpjuice/paypal-http-client": "^1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
Expand Down
8 changes: 8 additions & 0 deletions src/Concerns/HasCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PayPal\Checkout\Concerns;

use PayPal\Checkout\Orders\Item;

trait HasCollection
{
/**
Expand Down Expand Up @@ -50,6 +52,11 @@ public function offsetUnset(string $offset)
unset($this->items[$offset]);
}

/**
* @param mixed $offset
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
Expand All @@ -61,6 +68,7 @@ public function offsetSet($offset, $value)

/**
* @param string $offset
* @return mixed|Item|null
*/
public function offsetGet(string $offset)
{
Expand Down
33 changes: 11 additions & 22 deletions src/Orders/AmountBreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,54 +65,43 @@ public function toArray(): array
];

if ($this->hasDiscount()) {
/** @var Money $discount */
$discount = $this->getDiscount();
$data['breakdown']['discount'] = [
'currency_code' => $this->discount->getCurrency()->getCurrencyCode(),
'value' => (string) $this->discount->getAmount(),
'currency_code' => $discount->getCurrency()->getCurrencyCode(),
'value' => (string) $discount->getAmount(),
];
}

return $data;
}

/**
* @return bool
*/
public function hasDiscount(): bool
{
return (bool) $this->discount;
}

/**
* return's discount.
* @return Money
*/
public function getDiscount(): Money
public function getDiscount(): ?Money
{
return $this->discount;
}

/**
* @param Money $discount
*/
public function setDiscount(Money $discount)
public function setDiscount(Money $discount): AmountBreakdown
{
$this->discount = $discount;

return $this;
}

/**
* return's item_total.
* @return Money
*/
public function getItemTotal(): Money
{
return $this->item_total;
}

/**
* @param Money $item_total
*/
public function setItemTotal(Money $item_total)
public function setItemTotal(Money $item_total): AmountBreakdown
{
$this->item_total = $item_total;

return $this;
}
}
103 changes: 22 additions & 81 deletions src/Orders/ApplicationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,47 +106,34 @@ class ApplicationContext implements Arrayable, Jsonable
protected string $user_action = ACTION_CONTINUE;

/**
* Create a new collection.
*
* @param string|null $brand_name
* @param string|null $locale
* @param string|null $landing_page
* @param string|null $shipping_preference
* @param string $locale
* @param string $landing_page
* @param string $shipping_preference
* @param string|null $return_url
* @param string|null $cancel_url
*/
public function __construct(
?string $brand_name = null,
?string $locale = 'en-US',
?string $landing_page = NO_PREFERENCE,
?string $shipping_preference = NO_SHIPPING,
string $locale = 'en-US',
string $landing_page = NO_PREFERENCE,
string $shipping_preference = NO_SHIPPING,
?string $return_url = null,
?string $cancel_url = null
) {
$this->setBrandName($brand_name);
$this->setLocale($locale);
$this->setLandingPage($landing_page);
$this->setShippingPreference($shipping_preference);
$this->setReturnUrl($return_url);
$this->setCancelUrl($cancel_url);
$this->brand_name = $brand_name;
$this->locale = $locale;
$this->landing_page = $landing_page;
$this->shipping_preference = $shipping_preference;
$this->return_url = $return_url;
$this->cancel_url = $cancel_url;
}

/**
* Create a new collection.
*
* @param string|null $brand_name
* @param string|null $locale
* @param string|null $landing_page
* @param string|null $shipping_preference
* @param string|null $return_url
* @param string|null $cancel_url
* @return ApplicationContext
*/
public static function create(
?string $brand_name = null,
?string $locale = 'en-US',
?string $landing_page = NO_PREFERENCE,
?string $shipping_preference = NO_SHIPPING,
string $locale = 'en-US',
string $landing_page = NO_PREFERENCE,
string $shipping_preference = NO_SHIPPING,
?string $return_url = null,
?string $cancel_url = null
): ApplicationContext {
Expand Down Expand Up @@ -183,55 +170,36 @@ function ($item) {
);
}

/**
* gets brand_name.
*/
public function getBrandName(): ?string
{
return $this->brand_name;
}

/**
* sets the brand_name.
*/
public function setBrandName($brand_name): self
public function setBrandName(string $brand_name): self
{
$this->brand_name = $brand_name;

return $this;
}

/**
* gets brand_name.
*/
public function getLocale(): string
{
return $this->locale;
}

/**
* sets the locale.
*/
public function setLocale($locale): self
public function setLocale(string $locale): self
{
$this->locale = $locale;

return $this;
}

/**
* gets shipping_preference.
*/
public function getShippingPreference(): string
{
return $this->shipping_preference;
}

/**
* sets the shipping_preference.
* @noinspection PhpUnused
*/
public function setShippingPreference($shipping_preference): self
public function setShippingPreference(string $shipping_preference): self
{
$validOptions = [GET_FROM_FILE, NO_SHIPPING, SET_PROVIDED_ADDRESS];
if (!in_array($shipping_preference, $validOptions)) {
Expand All @@ -243,19 +211,12 @@ public function setShippingPreference($shipping_preference): self
return $this;
}

/**
* gets landing_page.
* @noinspection PhpUnused
*/
public function getLandingPage(): string
{
return $this->landing_page;
}

/**
* sets the landing_page.
*/
public function setLandingPage($landing_page): self
public function setLandingPage(string $landing_page): self
{
$validOptions = [LOGIN, BILLING, NO_PREFERENCE];
if (!in_array($landing_page, $validOptions)) {
Expand All @@ -267,19 +228,12 @@ public function setLandingPage($landing_page): self
return $this;
}

/**
* gets user_action.
*/
public function getUserAction(): string
{
return $this->user_action;
}

/**
* sets the user_action.
* @noinspection PhpUnused
*/
public function setUserAction($user_action): self
public function setUserAction(string $user_action): self
{
$validOptions = [ACTION_CONTINUE, ACTION_PAY_NOW];
if (!in_array($user_action, $validOptions)) {
Expand All @@ -290,37 +244,24 @@ public function setUserAction($user_action): self
return $this;
}

/**
* gets return_url.
* @noinspection PhpUnused
*/
public function getReturnUrl(): ?string
{
return $this->return_url;
}

/**
* sets the return_url.
*/
public function setReturnUrl($return_url): self
public function setReturnUrl(string $return_url): self
{
$this->return_url = $return_url;

return $this;
}

/**
* gets cancel_url.
*/
public function getCancelUrl(): ?string
{
return $this->cancel_url;
}

/**
* sets the cancel_url.
*/
public function setCancelUrl($cancel_url): self
public function setCancelUrl(string $cancel_url): self
{
$this->cancel_url = $cancel_url;

Expand Down
7 changes: 6 additions & 1 deletion src/Orders/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,15 @@ public function toArray(): array
fn(PurchaseUnit $purchase_unit) => $purchase_unit->toArray(),
$this->purchase_units
),
'application_context' => $this->application_context->toArray(),
'application_context' => $this->application_context ? $this->application_context->toArray() : null,
];
}

/**
* @param mixed $offset
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
Expand Down

0 comments on commit f6a5f11

Please sign in to comment.