PHP code example of integrify / azericard

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


use Integrify\Azericard\AzericardClient;
use Integrify\Azericard\AzericardConfig;

$client = new AzericardClient(AzericardConfig::fromEnvironment());

// Açarı fayldan deyil, birbaşa mətndən vermək də olar:
$config = new AzericardConfig(
    merchantId: 'TERM0001',
    privateKey: AzericardConfig::parsePrivateKey($pem),
    transferKey: $sharedKey,
    merchantName: 'MyShop',
    merchantUrl: 'https://shop.az',
    callbackUrl: 'https://shop.az/callback',
);

$form = $client->authorize(
    amount: 10.5,
    currency: '944',      // AZN
    order: '123456',      // 6–32 rəqəm, gün ərzində unikal
    description: 'Sifariş #123456',
);

echo $form->toHtml();   // özünü göndərən forma

$form->url;      // https://testmpi.3dsecure.az/cgi-bin/cgi_link
$form->method;   // POST
$form->fields;   // ['AMOUNT' => '10.5', ..., 'P_SIGN' => '...']

use Integrify\Azericard\Enum\AuthorizationType;
use Integrify\Azericard\Enum\ResponseType;

$form = $client->authorize(10.5, '944', '123456', 'Sifariş', AuthorizationType::Freeze);

// callback gəldikdən sonra — rrn və intRef oradan gəlir:
$client->finalize(10.5, '944', '123456', $data->rrn, $data->internalReference, ResponseType::AcceptPayment);

$form = $client->authorizeAndSaveCard(10.5, '944', '123456', 'Sifariş');
// callback-də `token` gəlir

$form = $client->authorizeWithSavedCard(10.5, '944', '123457', 'Təkrar', $token);

use Integrify\Azericard\Callback;

$callback = new Callback(AzericardConfig::fromEnvironment());

$data = $callback->decodeAuth($_POST);

if ($data->isSuccessful()) {
    // $data->order, $data->rrn, $data->internalReference, $data->token
}

$data = $callback->decodeTransfer($_POST);   // imza uyğun gəlməsə SignatureMismatch

$form = $client->startTransfer(
    merchant: 'MyShop',
    srn: 'SRN001',
    amount: 10.5,
    currency: '944',
    receiverCredentials: 'Əli Əliyev',
    redirectLink: 'https://shop.az/done',
);

// callback gəldikdən sonra:
$result = $client->confirmTransfer('MyShop', 'SRN001', 10.5, '944');
// və ya
$result = $client->declineTransfer('MyShop', 'SRN001', 10.5, '944');

$callback->verifyTransferResult($result);   // imzanı yoxlayır

$status = $client->getTransactionStatus(AuthorizationType::Direct, '123456');

$status->isSuccessful();
$status->statusMessage;
$status->rrn;
$status->internalReference;

$client->confirmTransfer('Shop', 'SRN001', 10.5, '944', new DateTimeImmutable('now'));

$form = $client->authorize(10.5, '944', '123456', 'Test');

$form->fields['AMOUNT'];    // '10.5'
$form->fields['P_SIGN'];    // imza

use Integrify\Azericard\Signature;

Signature::macSource(['10.5', '944']);   // '410.53944'