Here is how you can work with our API.

1. Make Payment

  • Request method POST URL http://epay.chargily.com.dz/api/invoice

  • Request Headers:

    • X-Authorization: API_KEY
    • Accept: application/json
  • Request Parameters:

    NameDescriptionValidation
    clientYour client nameRequired; String; Min:3
    client_emailYour client emailRequired; Email
    invoice_numberOrder number used to check payment responseRequired
    amountOrder total amount, must be greater than or equal to 75Required; Numeric; Min:75
    discountDiscount percentageRequired; Numeric; Min:0; Max:99.99
    back_urlURL redirected to after payment is doneRequired; String; URL
    webhook_urlSource URL for payment response informationRequired; String; URL
    modePayment method (“EDAHABIA” or “CIB”)Required; In: EDAHABIA / CIB
    commentDescription for payment reasonRequired; String
  • Responses:

    • 201: Payment created successfully

      Response as ‘json’: checkout_url

      Example: {"checkout_url": "https://epay.chargily.com.dz/checkout/random_token_here"}

    • 401: Unauthorized

      Invalid API_KEY

    • 422: Invalid parameters

      The request was well-formed but was unable to be followed due to semantic errors

If the creation of the invoice is successful, make redirection to checkout_url

2. Payment Confirmation

We will send you operation response via the already sent “webhook_url”.

  • Method POST

  • Headers:

    Signature

  • Body:

    Invoice with payment status

  • Signature Validation:

    Incoming webhook request has a header that can be used to verify the payload. The name of the header containing the signature can be configured in the ‘Signature’ header key to validate signatures.

  • This is an example of how you will compute the signature in PHP:

    // Secret key can be found in your profile information
    $secret = "API_SECRET";
    // Get incoming webhook request body content
    $body_content = file_get_contents("php://input");
    //
    $computed_signature = hash_hmac('sha256', $body_content, $secret);
    // Get signature from header
    $signature = getallheaders()["Signature"];
    // Check computed signature
    $validated = hash_equals($computed_signature, $signature); // : bool
    
    if ($validated) {
        $payment = json_decode($body_content, true);
        //@Todo: check invoice status first ($payment["invoice"]["status"] === 'paid')
        if ($payment["invoice"]["status"] === 'paid') {
            //@Todo: confirm order
        } elseif ($payment["invoice"]["status"] === 'failed') {
            //@Todo: do anything when payment failed
        }
    }
    exit;