PHP code example of integrify / kapitalbank

1. Go to this page and download the library: Download integrify/kapitalbank 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/ */

    

integrify / kapitalbank example snippets


use Integrify\Environment;
use Integrify\Kapitalbank\KapitalClient;
use Integrify\Kapitalbank\KapitalConfig;

$client = new KapitalClient(KapitalConfig::fromEnvironment());

// və ya açıq şəkildə
$client = new KapitalClient(new KapitalConfig(
    username: 'merchant',
    password: 'secret',
    environment: Environment::Prod,
    redirectUrl: 'https://shop.az/done',
));

$order = $client->createOrder(amount: 10.5, currency: 'AZN', description: 'Sifariş');

$order->id;              // 1231
$order->password;        // sifarişin öz parolu (merchant parolu DEYİL)
$order->redirectUrl();   // müştərini bura yönləndirin

$info = $client->getOrderInformation($order->id);

$info->status();        // OrderStatus|null
$info->isFullyPaid();   // bool

$detailed = $client->getDetailedOrderInformation($order->id);

$detailed->srcToken?->card?->brand;   // 'VISA'
$detailed->cardToken();               // sonrakı ödənişlər üçün token
$detailed->authorizedChargeAmount;    // bloklanmış məbləğ
$detailed->clearedChargeAmount;       // faktiki silinmiş məbləğ

$order = $client->saveCard(1, 'AZN', 'Kart qeydiyyatı');
// müştərini $order->redirectUrl()-ə yönləndirin

// təsdiqdən sonra:
$detailed = $client->getDetailedOrderInformation($order->id);
$token = $detailed->cardToken();

$client->clearingOrder($order->id, 1);       // bloklanmışı sil
// və ya
$client->fullReverseOrder($order->id);       // bloklanmışı azad et

$result = $client->payWithSavedCard($token, 10.5, 'AZN', 'Təkrar ödəniş');

$result->isApproved();      // bool
$result->resultMessage();   // 'Approved'
$result->approvalCode;

$client->createOrder(10, 'AZN', 'D');        // "10"
$client->createOrder('10.50', 'AZN', 'D');   // "10.50"

use Integrify\Kapitalbank\Exception\RequestRejected;

try {
    $client->refundOrder($orderId, 10);
} catch (RequestRejected $rejection) {
    $rejection->errorCode;       // 'InvalidOrderState'
    $rejection->code();          // ErrorCode::InvalidOrderState, tanınmasa null
    $rejection->description;     // bankın izahı
    $rejection->details;         // errorDetails, varsa
    $rejection->getPrevious();   // orijinal RequestFailed — cavab burada
}

$info->status;             // xam sətir — bank yeni dəyər əlavə etsə də sınmır
$info->status();           // OrderStatus|null
$result->pmoResultCode;    // bankın xam kodu, məs. '1'
$result->resultMessage();  // 'Approved', tanınmayan kod üçün null

use Integrify\Http\RecordingTransport;
use Integrify\Response;

$transport = new RecordingTransport();
$client = new KapitalClient($config, $transport);

$transport->queue(Response::json([
    'order' => ['id' => 1231, 'password' => 'p', 'hppUrl' => 'https://txpgtst.kapitalbank.az'],
]));

$client->createOrder(10.5, 'AZN', 'D');

$transport->lastRequest()->body['order'];   // göndərilmiş payload