From 617a34448c0b20e7d8a9de4840d15e77fd47d12d Mon Sep 17 00:00:00 2001 From: woutse Date: Wed, 11 Aug 2021 10:57:35 +0200 Subject: [PATCH] Added support for products parameter in capture --- samples/transaction/capture.php | 6 +++++- src/Api/Transaction/Capture.php | 19 +++++++++++++++++++ src/Transaction.php | 7 ++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/samples/transaction/capture.php b/samples/transaction/capture.php index 6ac24f77..85c70d7e 100644 --- a/samples/transaction/capture.php +++ b/samples/transaction/capture.php @@ -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(); } diff --git a/src/Api/Transaction/Capture.php b/src/Api/Transaction/Capture.php index a7ac1823..2c09b508 100644 --- a/src/Api/Transaction/Capture.php +++ b/src/Api/Transaction/Capture.php @@ -29,6 +29,11 @@ class Capture extends Transaction */ private $tracktrace; + /** + * @var array + */ + private $products; + /** * Set the transactionId * @@ -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 @@ -79,6 +94,10 @@ protected function getData() $this->data['tracktrace'] = $this->tracktrace; } + if (!empty($this->products)) { + $this->data['products'] = $this->products; + } + return parent::getData(); } diff --git a/src/Transaction.php b/src/Transaction.php index 864ed934..5bf4fc3c 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -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(); @@ -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();