Skip to content

Commit

Permalink
Added getAmount and getCurrencyAmount to the transaction result
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Pieters committed Apr 10, 2018
1 parent 7d1c409 commit bbff85a
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions src/Result/Transaction/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,31 @@ public function isCanceled()
return $this->data['paymentDetails']['state'] < 0;
}

public function isAuthorized()
public function void()
{
return $this->data['paymentDetails']['state'] == 95;
}

public function void(){
if(!$this->isAuthorized()){
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()){

public function isAuthorized()
{
return $this->data['paymentDetails']['state'] == 95;
}

/**
* @return string The transaction id
*/
public function getId()
{
return $this->data['transactionId'];
}

public function capture()
{
if ( ! $this->isAuthorized()) {
throw new Error('Cannod capture transaction, status is not authorized');
}

Expand Down Expand Up @@ -108,6 +119,22 @@ public function isPartiallyRefunded()
return $this->data['paymentDetails']['stateName'] === 'PARTIAL_REFUND';
}

/**
* @return float The amount of the transaction (in EUR)
*/
public function getAmount()
{
return $this->data['paymentDetails']['amount'] / 100;
}

/**
* @return float The amount of the transaction (in the currency)
*/
public function getCurrencyAmount()
{
return $this->data['paymentDetails']['currenyAmount'] / 100;
}

/**
* @return float Paid amount in original currency
*/
Expand Down Expand Up @@ -198,12 +225,13 @@ public function getExtra3()

public function approve()
{
if (!$this->isBeingVerified()) {
if ( ! $this->isBeingVerified()) {
throw new Error("Cannot approve transaction because it does not have the status 'verify'");
}

$result = \Paynl\Transaction::approve($this->getId());
$this->_reload(); //status is changed, so refresh the object

return $result;
}

Expand All @@ -215,28 +243,21 @@ 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());
$result = \Paynl\Transaction::get($this->getId());
$this->data = $result->getData();
}

public function decline()
{
if (!$this->isBeingVerified()) {
if ( ! $this->isBeingVerified()) {
throw new Error("Cannot decline transaction because it does not have the status 'verify'");
}

$result = \Paynl\Transaction::decline($this->getId());
$this->_reload();//status is changed, so refresh the object

return $result;
}

Expand Down

0 comments on commit bbff85a

Please sign in to comment.