diff --git a/README.md b/README.md index 72d76978..385e1db2 100644 --- a/README.md +++ b/README.md @@ -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-####-####'); @@ -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, @@ -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(); ``` @@ -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 } ``` @@ -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'; diff --git a/src/Result/Transaction/Status.php b/src/Result/Transaction/Status.php index 8be1ed0b..4fb98e51 100644 --- a/src/Result/Transaction/Status.php +++ b/src/Result/Transaction/Status.php @@ -94,6 +94,14 @@ 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 */ @@ -101,4 +109,170 @@ 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']; + } + +} \ No newline at end of file