PHP code example of djstar7 / kpay-sdk

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

    

djstar7 / kpay-sdk example snippets


use Kpay\Sdk\KpayClient;

$kpay = new KpayClient(
    baseUrl: 'https://admin.kpay.site', // sans /api
    apiKey: getenv('KPAY_API_KEY'),
    secretKey: getenv('KPAY_SECRET_KEY'),
    gatewaySecret: getenv('KPAY_GATEWAY_SECRET'),
    maxDuration: 300,                    // SEUL paramètre configurable (s)
);

$res = $kpay->initPayment([
    'amount' => 5000,
    'externalId' => 'ORDER-123',
    'returnUrl' => 'https://monsite.com/retour',
    'cancelUrl' => 'https://monsite.com/annule',
]);
// → rediriger vers $res['gatewayUrl']

use Kpay\Sdk\Laravel\Kpay;

$res = Kpay::initPayment(['amount' => 5000, 'returnUrl' => route('kpay.return')]);
return redirect()->away($res['gatewayUrl']);

if (! Kpay::verifyReturnSignature($request->query())) abort(400);

$final = Kpay::awaitFinalStatus($paymentId, 'payment'); // s'arrête au
// statut terminal (COMPLETED|FAILED|CANCELLED|EXPIRED|REFUNDED) ou à
// l'échéance max_duration
if (($final['status'] ?? null) === 'COMPLETED') { /* livrer */ }
bash
php artisan vendor:publish --tag=kpay-config