PHP code example of pratikislem / trinkpos-php

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

    

pratikislem / trinkpos-php example snippets



TrinkposBootstrap::init();

use Trinkpos\Enum\Currency;
use Trinkpos\Enum\TransactionType;
use Trinkpos\Options;
use Trinkpos\Request\PaymentRequest;
use Trinkpos\TrinkposClient;

$client = new TrinkposClient(Options::sandbox('API_KEY', 'SECRET_KEY'));
// Canlı ortam: Options::production('API_KEY', 'SECRET_KEY')

$response = $client->payment(new PaymentRequest(
    transactionType: TransactionType::Auth,
    orderId: 'ORDER-12345',
    amount: 100.00,
    currency: Currency::TRY,
    cardNumber: '4000000000000001',
    cardHolderName: 'John Doe',
    expYear: 2030,
    expMonth: 12,
    cvv: '000',
    installment: 1,
    is3d: false,
));

if ($response->isApproved()) {
    echo $response->transactionId();
}

// 1) Başlat: is3d: true, okUrl/failUrl verin → müşteriyi yönlendirin.
$response = $client->payment($request3d);
header('Location: ' . $response->htmlUrl()); // 15 dakika geçerli

// 2) Banka, ok_url/fail_url'e form POST'u yapar:
$callback = \Trinkpos\ThreeD\CallbackResult::fromPost($_POST);

// 3) ⚠️ Callback İMZASIZDIR — tek başına asla güvenmeyin.
//    Onay kararını daima sunucudan-sunucuya doğrulamayla verin:
$verification = $client->verifyCallback($callback);
if ($verification->isApproved() && $callback->amountMatches($orderAmount)) {
    // siparişi onayla
}

use Trinkpos\Enum\ErrorSubCodes;
use Trinkpos\Enum\GatewayCodes;
use Trinkpos\Exception\ApiException;

try {
    $response = $client->payment($request);
    if (!$response->isApproved()) {
        // Banka reddi: '51' yetersiz bakiye, '54' süresi dolmuş kart…
        $code = $response->gatewayCode();        // GatewayCodes sabitleriyle karşılaştırın
        $mesaj = $response->gatewayMessageTr();  // veya gatewayMessageEn()
    }
} catch (ApiException $e) {
    if ($e->errorSubCode === ErrorSubCodes::DUPLICATE_ORDER_ID) {
        // sipariş no zaten kullanılmış
    }
}
bash
composer