PHP code example of elongo / pay-php

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

    

elongo / pay-php example snippets


use Elongo\Pay\Client;

$pay = new Client('sk_live_votre_cle');

$session = $pay->checkout->create([
    'amount'              => 25000,
    'currency'            => 'CDF',
    'success_url'         => 'https://votre-app.cd/commande/ok',
    'cancel_url'          => 'https://votre-app.cd/commande/ko',
    'client_reference_id' => $commande->id,
    'metadata'            => ['commande_id' => $commande->id],
], idempotencyKey: "commande-{$commande->id}");

header('Location: '.$session['url']);

$session = $pay->checkout->retrieve('cs_live_…');
$payment = $pay->payments->retrieve('…');

use Elongo\Pay\Webhook;
use Elongo\Pay\Exception\ElongoPayException;

$payload = file_get_contents('php://input');
$header  = $_SERVER['HTTP_ELONGO_SIGNATURE'] ?? '';
$secret  = getenv('ELONGO_WEBHOOK_SECRET'); // whsec_…

try {
    $event = Webhook::constructEvent($payload, $header, $secret);
} catch (ElongoPayException) {
    http_response_code(400);
    exit;
}

if ($event['type'] === 'checkout.session.completed') {
    $session = $event['data'];
    // Marquer la commande $session['client_reference_id'] comme payée.
}

http_response_code(200);

// Environnement de test, ou transport personnalisé (tests, proxy).
$pay = new Client('sk_test_…', 'https://api.elongopay.cd', $transport);
bash
composer