PHP code example of yasserbenaioua / chargily-epay-laravel

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

    

yasserbenaioua / chargily-epay-laravel example snippets


use YasserBenaioua\Chargily\Models\ChargilyWebhookCall;

return [

    /*
    * Chargily Api Key
    * You can found it on your epay.chargily.com.dz Dashboard.
    */
    'key' => env('CHARGILY_API_KEY'),

    /*
    * Chargily Api Secret
    * Your Chargily secret, which is used to verify incoming requests from Chargily.
    * You can found it on your epay.chargily.com.dz Dashboard.
    */
    'secret' => env('CHARGILY_API_SECRET'),

    /*
    * This is where client redirected after payment processing.
    */
    'back_url' => 'valid-url-to-redirect-after-payment',

    /*
    * This is where you receive payment informations.
    */
    'webhook_url' => 'valid-url-to-receive-payment-informations',

    /*
     * You can define the job that should be run when a chargily webhook hits your application
     * here.
     */
    'jobs' => [
        // \App\Jobs\HandleChargilyWebhook::class,
    ],

    /*
     * This model will be used to store all incoming webhooks.
     * It should be or extend `YasserBenaioua\Chargily\Models\ChargilyWebhookCall`
     */
    'model' => ChargilyWebhookCall::class,

    /*
     * When running `php artisan model:prune` all stored Chargily webhook calls
     * that were successfully processed will be deleted.
     *
     * More info on pruning: https://laravel.com/docs/8.x/eloquent#pruning-models
     */
    'prune_webhook_calls_after_days' => 10,

    /*
     * When disabled, the package will not verify if the signature is valid.
     * This can be handy in local environments.
     */
    'verify_signature' => env('CHARGILY_SIGNATURE_VERIFY', true),
];

Route::chargilyWebhook('webhook-route-configured-at-the-chargily-config-file');

protected $except = [
    'webhook-route-configured-at-the-chargily-config-file',
];

use YasserBenaioua\Chargily\Chargily;

$chargily = new Chargily([
    //mode
    'mode' => 'EDAHABIA', //OR CIB
    //payment details
    'payment' => [
        'number' => 'payment-number-from-your-side', // Payment or order number
        'client_name' => 'client name', // Client name
        'client_email' => '[email protected]', // This is where client receive payment receipt after confirmation
        'amount' => 75, //this the amount must be greater than or equal 75
        'discount' => 0, //this is discount percentage between 0 and 99
        'description' => 'payment-description', // this is the payment description
    ]
]);

use YasserBenaioua\Chargily\Chargily;

$chargily = new Chargily([
    //mode
    'mode' => 'EDAHABIA', //OR CIB
    //payment details
    'payment' => [
        'number' => 'payment-number-from-your-side', // Payment or order number
        'client_name' => 'client name', // Client name
        'client_email' => '[email protected]', // This is where client receive payment receipt after confirmation
        'amount' => 75, //this the amount must be greater than or equal 75
        'discount' => 0, //this is discount percentage between 0 and 99
        'description' => 'payment-description', // this is the payment description
    ]
]);

$redirectUrl = $chargily->getRedirectUrl();
//like : https://epay.chargily.com.dz/checkout/random_token_here

return redirect($redirectUrl);

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use YasserBenaioua\Chargily\Models\ChargilyWebhookCall;

class HandleChargilyWebhook implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(
        public ChargilyWebhookCall $webhookCall
    ) {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // do your work here

        // you can access the payload of the webhook call with `$this->webhookCall->payload`
    }
}


// config/chargily.php

'jobs' => [
    \App\Jobs\HandleChargilyWebhook::class,
],

$schedule->command('model:prune', [
    '--model' => [\YasserBenaioua\Chargily\Models\ChargilyWebhookCall::class],
])->daily();
bash
php artisan vendor:publish --provider="YasserBenaioua\Chargily\ChargilyServiceProvider" --tag="chargily-config"
bash
php artisan vendor:publish --provider="YasserBenaioua\Chargily\ChargilyServiceProvider" --tag="chargily-migrations"
bash
php artisan migrate