PHP code example of sylapi / omnipay-tbibank

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

    

sylapi / omnipay-tbibank example snippets


use Omnipay\Omnipay;

// Inicjalizacja bramy
$gateway = Omnipay::create('TBIBank');

// Konfiguracja (dane testowe)
$gateway->setStoreId('tbitestapi_ro');
$gateway->setUsername('tbitestapi'); 
$gateway->setPassword('MZWlyiuAIbnyT0UO');
$gateway->setProviderCode('tbitestapi_ro');
$gateway->setTestMode(true);

// Aplikacja kredytowa
$response = $gateway->purchase([
    'amount' => '2500.00',
    'transactionReference' => 'order#12345',
    'customerFirstName' => 'Catalin',
    'customerLastName' => 'Test',
    'customerEmail' => '[email protected]'
])->send();

if ($response->isSuccessful() && $response->isRedirect()) {
    // Przekieruj klienta na platformę TBI
    header('Location: ' . $response->getRedirectUrl());
}

$gateway->setStoreId('tbitestapi_ro');
$gateway->setUsername('tbitestapi');
$gateway->setPassword('MZWlyiuAIbnyT0UO');
$gateway->setProviderCode('tbitestapi_ro');
$gateway->setTestMode(true);

$gateway->setStoreId('your_store_id');
$gateway->setUsername('your_username');
$gateway->setPassword('your_password');
$gateway->setProviderCode('your_store_id');
$gateway->setTestMode(false);

// Własny klucz publiczny do szyfrowania (bezpośrednia zawartość)
$gateway->setPublicKey('-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
-----END PUBLIC KEY-----');

$response = $gateway->purchase([
    'amount' => '2500.00',
    'transactionReference' => 'order#' . uniqid(),
    'description' => 'Smartwatch order',
    'notifyUrl' => 'https://your-domain.com/tbi/callback',
    
    // Dane klienta (wymagane)
    'customerFirstName' => 'Catalin',
    'customerLastName' => 'Test',
    'customerEmail' => '[email protected]',
    'customerPhone' => '0700000000',
    'customerCnp' => '',  // CNP może być pusty w testach
    
    // Adres rozliczeniowy
    'billingAddress' => 'Strada Test 123',
    'billingCity' => 'Bucuresti', 
    'billingCounty' => 'Bucuresti',
    
    // Produkty w koszyku
    'items' => [
        [
            'name' => 'Ceas smartwatch Polar Vantage V',
            'qty' => '1.0000',
            'price' => 2500.00,
            'category' => '8',
            'sku' => 'WATCH001',
            'ImageLink' => 'https://example.com/image.jpg'
        ]
    ]
])->send();

// Sprawdź rezultat
if ($response->isSuccessful()) {
    if ($response->isRedirect()) {
        // Przekieruj klienta na portal TBI
        $redirectUrl = $response->getRedirectUrl();
        header("Location: $redirectUrl");
        exit;
    }
} else {
    // Obsłuż błąd
    echo "Błąd: " . $response->getMessage();
}

// Endpoint callback'a: /tbi/callback
$response = $gateway->completePurchase([
    // TYLKO jeśli klucz prywatny ma hasło:
    // 'privateKeyPassword' => 'haslo_do_klucza'
])->send();

if ($response->isSuccessful()) {
    // Kredyt zatwierdzony
    $orderId = $response->getTransactionId();
    echo "Kredyt zatwierdzony dla zamówienia: $orderId";
    
    // Zaktualizuj status w bazie danych
    // updateOrderStatus($orderId, 'approved');
    
} elseif ($response->isCancelled()) {
    // Kredyt odrzucony/anulowany
    $orderId = $response->getTransactionId();
    $reason = $response->getRejectionReason();
    echo "Kredyt odrzucony: $reason";
    
    // updateOrderStatus($orderId, 'rejected', $reason);
}

$response = $gateway->void([
    'transactionReference' => 'order#12345'
])->send();

if ($response->isSuccessful()) {
    echo 'Zamówienie zostało anulowane';
} else {
    echo 'Błąd anulowania: ' . $response->getMessage();
}

$gateway->setTestMode(true); // Automatycznie użyje klucza testowego TBI

// Klucz publiczny (zawartość klucza bezpośrednio)
$gateway->setPublicKey('-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
-----END PUBLIC KEY-----');

// Klucz prywatny do callback'ów (zawartość klucza bezpośrednio)
$gateway->setPrivateKey('-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC...
-----END PRIVATE KEY-----');

// TYLKO jeśli klucz prywatny MA HASŁO (rzadko potrzebne)
// $gateway->setPrivateKeyPassword('haslo_ktorym_zaszyfrowano_klucz');