-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added transaction Capture and Void functions
Added isAuthorized() function to transaction Result object
- Loading branch information
Andy Pieters
committed
Mar 14, 2017
1 parent
e1f9e14
commit 3521f99
Showing
7 changed files
with
260 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2015 Andy Pieters <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
require_once '../../vendor/autoload.php'; | ||
require_once '../config.php'; | ||
|
||
$transactionId = $_GET['transactionId']; | ||
try { | ||
$result = \Paynl\Transaction::capture($transactionId); | ||
} catch (\Paynl\Error\Error $e) { | ||
echo $e->getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2015 Andy Pieters <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
require_once '../../vendor/autoload.php'; | ||
require_once '../config.php'; | ||
|
||
$transactionId = $_GET['transactionId']; | ||
try { | ||
$result = \Paynl\Transaction::void($transactionId); | ||
} catch (\Paynl\Error\Error $e) { | ||
echo $e->getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2015 Andy Pieters <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Paynl\Api\Transaction; | ||
|
||
use Paynl\Error; | ||
/** | ||
* Description of Approve | ||
* | ||
* @author Andy Pieters <[email protected]> | ||
*/ | ||
class Capture extends Transaction | ||
{ | ||
protected $apiTokenRequired = true; | ||
protected $serviceIdRequired = false; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $transactionId; | ||
|
||
/** | ||
* Get data to send to the api | ||
* | ||
* @return array | ||
* @throws Error\Required | ||
*/ | ||
protected function getData() { | ||
if(empty($this->transactionId)){ | ||
throw new Error\Required('TransactionId is niet geset'); | ||
} | ||
$this->data['transactionId'] = $this->transactionId; | ||
return parent::getData(); | ||
} | ||
|
||
/** | ||
* Set the transactionId | ||
* | ||
* @param string $transactionId | ||
*/ | ||
public function setTransactionId($transactionId){ | ||
$this->transactionId = $transactionId; | ||
} | ||
|
||
/** | ||
* Do the request | ||
* | ||
* @param null $endpoint | ||
* @param null $version | ||
* @return array the result | ||
*/ | ||
public function doRequest($endpoint = null, $version = null) { | ||
return parent::doRequest('transaction/capture'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2015 Andy Pieters <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Paynl\Api\Transaction; | ||
|
||
use Paynl\Error; | ||
/** | ||
* Description of Approve | ||
* | ||
* @author Andy Pieters <[email protected]> | ||
*/ | ||
class Void extends Transaction | ||
{ | ||
protected $apiTokenRequired = true; | ||
protected $serviceIdRequired = false; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $transactionId; | ||
|
||
/** | ||
* Get data to send to the api | ||
* | ||
* @return array | ||
* @throws Error\Required | ||
*/ | ||
protected function getData() { | ||
if(empty($this->transactionId)){ | ||
throw new Error\Required('TransactionId is niet geset'); | ||
} | ||
$this->data['transactionId'] = $this->transactionId; | ||
return parent::getData(); | ||
} | ||
|
||
/** | ||
* Set the transactionId | ||
* | ||
* @param string $transactionId | ||
*/ | ||
public function setTransactionId($transactionId){ | ||
$this->transactionId = $transactionId; | ||
} | ||
|
||
/** | ||
* Do the request | ||
* | ||
* @param null $endpoint | ||
* @param null $version | ||
* @return array the result | ||
*/ | ||
public function doRequest($endpoint = null, $version = null) { | ||
return parent::doRequest('transaction/voidAuthorization'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,23 +18,16 @@ | |
|
||
namespace Paynl\Result\Transaction; | ||
|
||
use Paynl\Result\Result; | ||
use Paynl\Error\Error; | ||
use Paynl\Result\Result; | ||
|
||
/** | ||
* Description of Transaction | ||
* | ||
* @author Andy Pieters <[email protected]> | ||
*/ | ||
class Transaction extends Result | ||
{ | ||
/** | ||
* @return string The transaction id | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->data['transactionId']; | ||
} | ||
|
||
/** | ||
* @return bool Transaction is paid | ||
*/ | ||
|
@@ -69,6 +62,24 @@ public function isCanceled() | |
return $this->data['paymentDetails']['state'] < 0; | ||
} | ||
|
||
public function isAuthorized() | ||
{ | ||
return $this->data['paymentDetails']['state'] == 95; | ||
} | ||
|
||
public function void(){ | ||
if(!$this->isAuthorized()){ | ||
throw new Error('Cannod void transaction, status is not authorized'); | ||
} | ||
return \Paynl\Transaction::void($this->getId()); | ||
} | ||
public function capture(){ | ||
if(!$this->isAuthorized()){ | ||
throw new Error('Cannod capture transaction, status is not authorized'); | ||
} | ||
return \Paynl\Transaction::capture($this->getId()); | ||
} | ||
|
||
/** | ||
* @param bool|true $allowPartialRefunds | ||
* | ||
|
@@ -95,14 +106,6 @@ public function isPartiallyRefunded() | |
return $this->data['paymentDetails']['stateName'] == 'PARTIAL_REFUND'; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isBeingVerified() | ||
{ | ||
return $this->data['paymentDetails']['stateName'] == 'VERIFY'; | ||
} | ||
|
||
/** | ||
* @return float Paid amount in original currency | ||
*/ | ||
|
@@ -191,13 +194,9 @@ public function getExtra3() | |
return $this->data['statsDetails']['extra3']; | ||
} | ||
|
||
private function _reload(){ | ||
$result = \Paynl\Transaction::get($this->getId()); | ||
$this->data = $result->getData(); | ||
} | ||
|
||
public function approve(){ | ||
if($this->isBeingVerified()){ | ||
public function approve() | ||
{ | ||
if ($this->isBeingVerified()) { | ||
$result = \Paynl\Transaction::approve($this->getId()); | ||
$this->_reload(); //status is changed, so refresh the object | ||
return $result; | ||
|
@@ -206,8 +205,31 @@ public function approve(){ | |
} | ||
} | ||
|
||
public function decline(){ | ||
if($this->isBeingVerified()){ | ||
/** | ||
* @return bool | ||
*/ | ||
public function isBeingVerified() | ||
{ | ||
return $this->data['paymentDetails']['stateName'] == 'VERIFY'; | ||
} | ||
|
||
/** | ||
* @return string The transaction id | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->data['transactionId']; | ||
} | ||
|
||
private function _reload() | ||
{ | ||
$result = \Paynl\Transaction::get($this->getId()); | ||
$this->data = $result->getData(); | ||
} | ||
|
||
public function decline() | ||
{ | ||
if ($this->isBeingVerified()) { | ||
$result = \Paynl\Transaction::decline($this->getId()); | ||
$this->_reload();//status is changed, so refresh the object | ||
return $result; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters