PHP code example of iyzico / kolai-php

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

    

iyzico / kolai-php example snippets


use Kolai\Auth\{RequestVerifier, SignedRequest, Scope};

$verifier = new RequestVerifier($apiKey, $secretKey, $nonceStore, $psrLogger);

$request = SignedRequest::fromRequestUri(
    $headers['Authorization'] ?? '',
    $_SERVER['REQUEST_URI'],
    $rawBody                      // GET için ''
);

$verifier->verify($request, Scope::CREATE_ORDER);   // başarısızsa UnauthorizedException

use Kolai\Protocol\Envelope;

$envelope = new Envelope($platformFields);   // sade dizi, aşağıya bakın

$envelope->success($data, ['pagination' => $pagination]);
$envelope->fromException($kolaiException);
$envelope->unexpectedError();        // 500, nedenini sızdırmaz

throw Errors::productNotFound();          // 404 + 2001
throw Errors::insufficientStock();        // 409 + 4002
throw Errors::discountExceedsTotal();     // 400 + 4003

$ledger = $storedRefundLedger;          // ['tx1' => 50.00, ...]
$plan   = RefundAllocator::plan($itemTransactions, $ledger, $amount);

if ($plan['unallocated'] > RefundAllocator::EPSILON) {
    // İstek karşılanamıyor — hiçbir şey göndermeden durun.
}

$operationId = RefundAllocator::newOperationId();
foreach ($plan['steps'] as $step) {
    $result = $client->refund(
        $step['paymentTransactionId'],
        $step['amount'],
        $currency,
        RefundAllocator::conversationId($orderId, $step['paymentTransactionId'], $operationId)
    );
    if (!$result['success']) {
        break;                          // kalan bakiye defterde kalır, tekrar denenebilir
    }
    // Başarılı her adımdan SONRA defteri hemen kalıcı yazın:
    $ledger = RefundAllocator::record($ledger, $step['paymentTransactionId'], $step['amount']);
}

$logger->info('request started', ['body' => Redactor::payload($jsonParams)]);

$contract = ContractTemplates::render(
    ContractTemplates::DISTANCE_SALES,
    $storedTemplate,                       // null -> paketteki varsayılan
    ['seller_name' => 'Acme Ltd', 'seller_tax_id' => '1234567890']
);
// $contract['content']      -> alıcı/sipariş yer tutucuları duruyor
// $contract['placeholders'] -> tüketicinin doldurması gerekenler

ContractTemplates::unknownPlaceholders($content);   // ['{{kargo_firmasi}}']

composer