Skip to content

Commit

Permalink
Merge pull request #136 from paynl/feature/PLUG-428
Browse files Browse the repository at this point in the history
Feature/plug 428
  • Loading branch information
woutse authored May 26, 2021
2 parents f82df61 + b486ec0 commit 51344e4
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 20 deletions.
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Set the configuration
```php
require __DIR__ . '/vendor/autoload.php';

// Replace tokenCode apitoken and serviceId with your own.
# Replace tokenCode apitoken and serviceId with your own.
\Paynl\Config::setTokenCode('AT-####-####');
\Paynl\Config::setApiToken('****************************************');
\Paynl\Config::setServiceId('SL-####-####');
Expand All @@ -74,11 +74,11 @@ require __DIR__ . '/vendor/autoload.php';
\Paynl\Config::setServiceId('SL-####-####');

$result = \Paynl\Transaction::start(array(
// required
# Required
'amount' => 10.00,
'returnUrl' => Paynl\Helper::getBaseUrl().'/return.php',

// optional
# Optional
'currency' => 'EUR',
'exchangeUrl' => Paynl\Helper::getBaseUrl().'/exchange.php',
'paymentMethod' => 10,
Expand Down Expand Up @@ -134,10 +134,10 @@ $result = \Paynl\Transaction::start(array(
),
));

// Save this transactionid and link it to your order
# Save this transactionid and link it to your order
$transactionId = $result->getTransactionId();

// Redirect the customer to this url to complete the payment
# Redirect the customer to this url to complete the payment
$redirect = $result->getRedirectUrl();
```

Expand All @@ -150,13 +150,11 @@ require __DIR__ . '/vendor/autoload.php';

$transaction = \Paynl\Transaction::getForReturn();

//manual transfer transactions are always pending when the user is returned
if( $transaction->isPaid() || $transaction->isPending()){
// redirect to thank you page

# Manual transfer transactions are always pending when the user is returned
if( $transaction->isPaid() || $transaction->isPending()) {
# Redirect to thank you page
} elseif($transaction->isCanceled()) {
// redirect back to checkout

# Redirect back to checkout
}
```

Expand All @@ -167,19 +165,19 @@ require __DIR__ . '/vendor/autoload.php';
\Paynl\Config::setTokenCode('AT-####-####');
\Paynl\Config::setApiToken('****************************************');

$transaction = \Paynl\Transaction::getForExchange();
$transaction = \Paynl\Transaction::status($transactionId);

if($transaction->isPaid() || $transaction->isAuthorized()){
// process the payment
} elseif($transaction->isCanceled()){
// payment canceled, restock items
if($transaction->isPaid() || $transaction->isAuthorized()) {
# Process the payment
} elseif($transaction->isCanceled()) {
# Payment canceled, restock items
}

// always start your response with TRUE|
# Always respond with TRUE|
echo "TRUE| ";

// Optionally you can send a message after TRUE|, you can view these messages in the logs.
// https://admin.pay.nl/logs/payment_state
# Optionally you can send a message after TRUE|, you can view these messages in the logs.
# https://admin.pay.nl/logs/payment_state
echo ($transaction->isPaid() || $transaction->isAuthorized())?'Paid':'Not paid';


Expand Down
176 changes: 175 additions & 1 deletion src/Result/Transaction/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,185 @@ public function getRefundedAmount()
return $this->data['paymentDetails']['refundAmount'] / 100;
}

/**
* @return string Currency in which the transaction is actually paid
*/
public function getPaidCurrency()
{
return $this->data['paymentDetails']['currency'];
}

/**
* @return float|int The amount that has been refunded in the used currency
*/
public function getRefundedCurrencyAmount()
{
return $this->data['paymentDetails']['refundCurrenyAmount'] / 100;
}
}

/**
* Checks whether the payment is being verified
*
* @return bool
*/
public function isBeingVerified()
{
return $this->data['paymentDetails']['stateName'] === 'VERIFY';
}

/**
* @return string The name of the payment method
*/
public function getPaymentMethodName()
{
return isset($this->data['paymentDetails']['paymentProfileName']) ? $this->data['paymentDetails']['paymentProfileName'] : '';
}

/**
* @return string The account number, or masked creditcard number
*/
public function getAccountNumber()
{
return $this->data['paymentDetails']['identifierPublic'];
}

/**
* Checks whether the payment is authorized
*
* @return bool
*/
public function isAuthorized()
{
return $this->data['paymentDetails']['state'] == 95;
}

/**
* @return string The name of the account holder
*/
public function getAccountHolderName()
{
return $this->data['paymentDetails']['identifierName'];
}

/**
* @return string The ordernumber of the order provided by the external integrator.
*/
public function getOrderNumber()
{
return $this->data['paymentDetails']['orderNumber'];
}

/**
* @return bool Transaction is paid
*/
public function isPaid()
{
return $this->data['paymentDetails']['stateName'] === 'PAID';
}

/**
* Checks whether the payment is pending
*
* @return bool
*/
public function isPending()
{
return $this->data['paymentDetails']['stateName'] === 'PENDING' || $this->data['paymentDetails']['stateName'] === 'VERIFY';
}

/**
* Alias for isCanceled
*
* @return bool Transaction is Canceled
*/
public function isCancelled()
{
return $this->isCanceled();
}

/**
*
* Check whether the status of the transaction is chargeback
*
* @return bool
*/
public function isChargeBack()
{
return $this->data['paymentDetails']['stateName'] === 'CHARGEBACK';
}

/**
* @return bool Transaction is Canceled
*/
public function isCanceled()
{
return $this->data['paymentDetails']['state'] < 0;
}

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


/**
* @param bool|true $allowPartialRefunds
*
* @return bool
*/
public function isRefunded($allowPartialRefunds = true)
{
if ($this->data['paymentDetails']['stateName'] === 'REFUND') {
return true;
}

if ($allowPartialRefunds && $this->data['paymentDetails']['stateName'] === 'PARTIAL_REFUND') {
return true;
}

return false;
}


/**
* Check whether the payment is partial refunded
*
* @return bool
*/
public function isPartiallyRefunded()
{
return $this->data['paymentDetails']['stateName'] === 'PARTIAL_REFUND';
}


/**
* Check whether the payment is a partial payment.
*
* @return bool
*/
public function isPartialPayment()
{
return $this->data['paymentDetails']['stateName'] === 'PARTIAL_PAYMENT';
}


/**
* @return string The account number, or masked creditcard number
*/
public function getAccountHash()
{
return $this->data['paymentDetails']['identifierHash'];
}

/**
* @return string The transaction description, as defined while starting the transaction
*/
public function getDescription()
{
return empty($this->data['paymentDetails']['description']) ? '' : $this->data['paymentDetails']['description'];
}

}

0 comments on commit 51344e4

Please sign in to comment.