Skip to content

Commit

Permalink
Merge pull request #142 from paynl/feature/PLUG-567
Browse files Browse the repository at this point in the history
Added support for products parameter in capture
  • Loading branch information
woutse authored Aug 11, 2021
2 parents 3a451d0 + 617a344 commit 9b54e81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion samples/transaction/capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
$amount = $_GET['amount'];
$tracktrace = $_GET['tracktrace'];

$articleId = '1019';
$quantityToBeCaptured = '1';
$products[$articleId] = $quantityToBeCaptured;

try {
$result = \Paynl\Transaction::capture($transactionId, $amount, $tracktrace);
$result = \Paynl\Transaction::capture($transactionId, $amount, $tracktrace, $products);
} catch (\Paynl\Error\Error $e) {
echo $e->getMessage();
}
19 changes: 19 additions & 0 deletions src/Api/Transaction/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Capture extends Transaction
*/
private $tracktrace;

/**
* @var array
*/
private $products;

/**
* Set the transactionId
*
Expand Down Expand Up @@ -59,6 +64,16 @@ public function setTracktrace($tracktrace)
$this->tracktrace = $tracktrace;
}

/**
* Set the products
*
* @param array $products
*/
public function setProducts($products)
{
$this->products = $products;
}

/**
* @inheritdoc
* @throws Error\Required TransactionId is required
Expand All @@ -79,6 +94,10 @@ protected function getData()
$this->data['tracktrace'] = $this->tracktrace;
}

if (!empty($this->products)) {
$this->data['products'] = $this->products;
}

return parent::getData();
}

Expand Down
7 changes: 6 additions & 1 deletion src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,14 @@ public static function decline($transactionId)
* @param string $transactionId
* @param string|null $amount
* @param string|null $tracktrace
* @param array|null $products
* @return bool
* @throws Error\Api
* @throws Error\Error
* @throws Error\Required\ApiToken
* @throws Error\Required\ServiceId
*/
public static function capture($transactionId, $amount = null , $tracktrace = null )
public static function capture($transactionId, $amount = null , $tracktrace = null, $products = null)
{
$api = new Api\Capture();

Expand All @@ -530,6 +531,10 @@ public static function capture($transactionId, $amount = null , $tracktrace = nu
$api->setTracktrace($tracktrace);
}

if (!empty($products)) {
$api->setProducts($products);
}

$api->setTransactionId($transactionId);
$result = $api->doRequest();

Expand Down

0 comments on commit 9b54e81

Please sign in to comment.