PHP code example of thehocinesaad / laravel-chargily-epay

1. Go to this page and download the library: Download thehocinesaad/laravel-chargily-epay 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/ */

    

thehocinesaad / laravel-chargily-epay example snippets


use  TheHocineSaad\LaravelChargilyEPay\Traits\Epayable;

class User extends Authenticatable
{
    use Epayable
}

use TheHocineSaad\LaravelChargilyEPay\Models\Epay_Invoice;

$configurations = [
        'user_id' => 1, // (optional) This is the user ID to be added as a foreign key, it's optional, if it's not provided its value will be NULL
        'mode' => 'CIB', // Payment method must be 'CIB' or 'EDAHABIA'
        'payment' => [
         'client_name' => 'client name here', // Client name
         'client_email' => '[email protected]', // This is where client receives payment receipt after confirmation
            'amount' => 2500, // Must be = or > than 75 
            'discount' => 0, // This is discount percentage, between 0 and 99
            'description' => 'payment for product', // This is the payment description
        ]
    ];

    $checkout_url = Epay_Invoice::make($configurations);

    $checkout_url = Epay_Invoice::make($configurations, ['product_id' => 1]);

$configurations = [
    'mode' => 'CIB',
    'payment' => [
        'amount' => 1000,
        'discount' => 0,
        'description' => 'payment for product',
    ]
];

$checkout_url = $request->user()->charge($configurations);

protected $except = [
        'webhook'
];

use TheHocineSaad\LaravelChargilyEPay\Epay_Webhook;

$webhookHandler = new Epay_Webhook;

if($webhookHandler -> invoiceIsPaied) {
    // Put here the logic you want to happen if the user actually made the payment.
}else {
    // Put here the logic you want to happen if the user canceled the payment.
}