Skip to content

Commit

Permalink
Merge pull request #110 from paynl/feature/PLUG-141
Browse files Browse the repository at this point in the history
Added optional amount and track and trace input by capture
  • Loading branch information
woutse authored Jun 17, 2020
2 parents bf054a5 + b0f74b5 commit 5a74613
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
5 changes: 4 additions & 1 deletion samples/transaction/capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
require_once '../config.php';

$transactionId = $_GET['transactionId'];
$amount = $_GET['amount'];
$tracktrace = $_GET['tracktrace'];

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

/**
* @var int amount in cents
*/
private $amount;

/**
* @var string
*/
private $tracktrace;

/**
* Set the transactionId
*
Expand All @@ -28,6 +38,26 @@ public function setTransactionId($transactionId)
$this->transactionId = $transactionId;
}

/**
* Set the amount(in cents) of the transaction
*
* @param int $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
}

/**
* Set the track and trace code
*
* @param string $tracktrace
*/
public function setTracktrace($tracktrace)
{
$this->tracktrace = $tracktrace;
}

/**
* @inheritdoc
* @throws Error\Required TransactionId is required
Expand All @@ -40,6 +70,14 @@ protected function getData()

$this->data['transactionId'] = $this->transactionId;

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

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

return parent::getData();
}

Expand Down
15 changes: 13 additions & 2 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,27 @@ public static function decline($transactionId)
/**
* Capture a transaction
*
* @param $transactionId
* @param string $transactionId
* @param string|null $amount
* @param string|null $tracktrace
* @return bool
* @throws Error\Api
* @throws Error\Error
* @throws Error\Required\ApiToken
* @throws Error\Required\ServiceId
*/
public static function capture($transactionId)
public static function capture($transactionId, $amount = null , $tracktrace = null )
{
$api = new Api\Capture();

if (isset($amount)) {
$api->setAmount(round($amount * 100));
}

if (isset($tracktrace)) {
$api->setTracktrace($tracktrace);
}

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

Expand Down

0 comments on commit 5a74613

Please sign in to comment.