PHP code example of twelver313 / kapital-bank

1. Go to this page and download the library: Download twelver313/kapital-bank library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

twelver313 / kapital-bank example snippets


use Twelver313\KapitalBank\PaymentGateway;

$paymentGateway = new PaymentGateway([
  'login' => '<YOUR_LOGIN>',
  'password' => '<YOUR_PASSWORD>',
  'isDev' => true, // Optional flag for using Kapital-Bank's test environment
  /* You don't need to pass the option below. It was added just in case Kapital Bank changes host address */
  // 'paymentHost' => 'https://txpgtst.kapitalbank.az'
]);

$orderParams = [
  'amount' => 10, // i.e '10.00',
  'currency' => 'AZN', // Optional, 'AZN' by default
  'description' => 'Purchase order example', // Your description
  'redirectUrl' => '/your-redirect-url',
  'language' => 'az', // Optional, 'az' by default
];
/** Creating purchase order */
$order = $paymentGateway->createPurchaseOrder($orderParams);

/** Creating pre-auth order */
$order = $paymentGateway->createPreAuthOrder($orderParams);

/** Creating recurring order */
$order = $paymentGateway->createRecurringOrder($orderParams);

/** Navigate to payment page  */
$order->navigateToPaymentPage(); 

/** Or alternatively use other properties to accomplish your tasks */
$order->url;
$order->id;
$order->secret;
$order->password;

$response = $paymentGateway->refund([
  'id' => <ORDER_ID>,
  'password' => '<ORDER_PASSWORD>',
  'amount' => 10, // i.e 10.00
  'phase' => 'Single', // Optional, 'Single' by default
]);

// Response properties
$response->approvalCode; // Example: "963348"
$response->pmoResultCode; // Example: "1"
$response->match->{$property}; // Read Kapital-Bank's official documentation see possible properties to refer

use Twelver313\KapitalBank\OrderStatus

$orderStatus = $paymentGateway->getOrderStatus([
  'id' => <ORDER_ID>,
  'password' => '<ORDER_PASSWORD>' 
]);
$status = $orderStatus->status;

// Do any stuff depending on status
if ($status == OrderStatus::CANCELED) { // equivalent: $orderStatus->isCanceled()
  ...
}
if ($status == OrderStatus::DECLINED) { // equivalent: $orderStatus->isDeclined()
  ...
}
if ($status == OrderStatus::FULLY_PAID) { // equivalent: $orderStatus->isFullyPaid()
  ...
}
if ($status == OrderStatus::EXPIRED) { // equivalent: $orderStatus->isExpired()
  ...
}
if ($status == OrderStatus::REFUNDED) { // equivalent: $orderStatus->isRefunded()
  ...
}
if ($orderStatus->isOneOf([OrderStatus::CANCELED, OrderStatus::DECLINED])) {
  ...
}

$orderParams = [
  'id' => <ORDER_ID>,
  'password' => '<ORDER_PASSWORD>' 
];
$orderStatus = $paymentGateway->getOrderStatus($orderParams);

/** Restoring order if it was not finished or expired */
if ($orderStatus->isPreparing()) {
  $order = $paymentGateway->restoreOrder($orderParams);
  $order->navigateToPaymentPage();
}