Passer au contenu principal

Documentation Index

Fetch the complete documentation index at: https://developers.ligdicash.com/llms.txt

Use this file to discover all available pages before exploring further.

Ces exemples montrent un handler de callback complet : déduplication, re-vérification et traitement métier. Adaptez les détails (nom de table, logique métier) à votre application.
<?php

$rawBody = file_get_contents('php://input');
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';

// Supporter JSON et form-urlencoded
if (str_contains($contentType, 'application/json')) {
    $payload = json_decode($rawBody, true);
} else {
    parse_str($rawBody, $payload);
    // custom_data arrive en JSON stringifié en form-urlencoded
    if (isset($payload['custom_data']) && is_string($payload['custom_data'])) {
        $payload['custom_data'] = json_decode($payload['custom_data'], true) ?? $payload['custom_data'];
    }
}

$transactionId = null;
foreach ($payload['custom_data'] ?? [] as $entry) {
    if (($entry['keyof_customdata'] ?? null) === 'transaction_id') {
        $transactionId = $entry['valueof_customdata'] ?? null;
        break;
    }
}
if (!$transactionId) {
    http_response_code(400);
    exit;
}

// Déduplication
try {
    $pdo->exec("INSERT INTO processed_callbacks (transaction_id) VALUES ('$transactionId')");
} catch (PDOException $e) {
    // Déjà traité — doublon LigdiCash
    http_response_code(200);
    exit;
}

// Retrouver le token stocké à la création
$stmt = $pdo->prepare('SELECT token FROM transactions WHERE transaction_id = ?');
$stmt->execute([$transactionId]);
$row = $stmt->fetch();

if (!$row) {
    http_response_code(404);
    exit;
}

// Re-vérification
$params = http_build_query(['invoiceToken' => $row['token']]);
$ch = curl_init("https://app.ligdicash.com/pay/v01/redirect/checkout-invoice/confirm?$params");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Apikey: ' . $_ENV['LIGDICASH_API_KEY'],
        'Authorization: Bearer ' . $_ENV['LIGDICASH_AUTH_TOKEN'],
    ],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);

if (($result['status'] ?? '') === 'completed') {
    // Traitement métier
    $pdo->exec("UPDATE orders SET status = 'paid' WHERE transaction_id = '$transactionId'");
}

http_response_code(200);
Les exemples ci-dessus utilisent l’endpoint de confirmation payin redirect. Pour un payout, remplacez l’endpoint par GET /pay/v01/withdrawal/confirm/?withdrawalToken={token}. Voir Vérifier le statut d’un payout.

Pages associées