Skip to content

Commit

Permalink
Refactor setExpressCheckout method
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Jan 31, 2018
1 parent c210374 commit aa55db2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/Services/ExpressCheckout.php
Expand Up @@ -92,6 +92,30 @@ protected function setExpressCheckoutRecurringPaymentConfig($data, $subscription
]);
}

/**
* Set item subtotal if available.
*
* @param array $data
*/
protected function setItemSubTotal($data)
{
$this->subtotal = isset($data['subtotal']) ? $data['subtotal'] : $data['total'];
}

/**
* Set shipping amount if available.
*
* @param array $data
*/
protected function setShippingAmount($data)
{
if (isset($data['shipping'])) {
$this->post = $this->post->merge([
'PAYMENTREQUEST_0_SHIPPINGAMT' => $data['shipping'],
]);
}
}

/**
* Perform a SetExpressCheckout API call on PayPal.
*
Expand All @@ -104,8 +128,10 @@ protected function setExpressCheckoutRecurringPaymentConfig($data, $subscription
*/
public function setExpressCheckout($data, $subscription = false)
{
$this->setItemSubTotal($data);

$this->post = $this->setCartItems($data['items'])->merge([
'PAYMENTREQUEST_0_ITEMAMT' => isset($data['subtotal']) ? $data['subtotal'] : $data['total'],
'PAYMENTREQUEST_0_ITEMAMT' => $this->subtotal,
'PAYMENTREQUEST_0_AMT' => $data['total'],
'PAYMENTREQUEST_0_PAYMENTACTION' => $this->paymentAction,
'PAYMENTREQUEST_0_CURRENCYCODE' => $this->currency,
Expand All @@ -117,9 +143,7 @@ public function setExpressCheckout($data, $subscription = false)
'LOCALE' => $this->locale,
]);

if (isset($data['shipping'])) {
$this->post['PAYMENTREQUEST_0_SHIPPINGAMT'] = $data['shipping'];
}
$this->setShippingAmount($data);

$this->setExpressCheckoutRecurringPaymentConfig($data, $subscription);

Expand Down
7 changes: 7 additions & 0 deletions src/Traits/PayPalRequest.php
Expand Up @@ -50,6 +50,13 @@ trait PayPalRequest
*/
private $config;

/**
* Item subtotal.
*
* @var double
*/
private $subtotal;

/**
* Default currency for PayPal.
*
Expand Down

0 comments on commit aa55db2

Please sign in to comment.