PHP code example of filano / laravel-paygate-global

1. Go to this page and download the library: Download filano/laravel-paygate-global 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/ */

    

filano / laravel-paygate-global example snippets


use PayGate\LaravelPayGateGlobal\Facades\PayGateGlobal;

$response = PayGateGlobal::initiatePayment([
    'phone_number' => '+22890123456',
    'amount' => 1000,
    'identifier' => 'ORDER_' . time(),
    'network' => 'FLOOZ', // ou 'TMONEY'
    'description' => 'Achat produit XYZ'
]);

// Réponse
// {
//     "tx_reference": "TXN123456789",
//     "status": 0  // 0 = succès
// }

$paymentUrl = PayGateGlobal::generatePaymentUrl([
    'amount' => 5000,
    'identifier' => 'ORDER_123',
    'description' => 'Commande #123',
    'success_url' => url('/payment/success'), // URL après paiement réussi
    // ou 'return_url' => url('/payment/callback'), // Alternative
    'phone' => '+22890123456', // Optionnel - pré-remplir
    'network' => 'FLOOZ' // Optionnel - pré-sélectionner
]);

// Rediriger l'utilisateur
return redirect($paymentUrl);

// Par référence PayGateGlobal
$status = PayGateGlobal::checkPaymentStatus('TXN123456789');

// Par votre identifiant
$status = PayGateGlobal::checkPaymentStatusByIdentifier('ORDER_123');

// Réponse
// {
//     "tx_reference": "TXN123456789",
//     "status": 0,  // 0=succès, 2=en cours, 4=expiré, 6=annulé
//     "payment_method": "FLOOZ",
//     "amount": 1000
// }

$balance = PayGateGlobal::checkBalance();

// {
//     "flooz": 50000,
//     "tmoney": 25000
// }

$disbursement = PayGateGlobal::disburse([
    'phone_number' => '+22890123456',
    'amount' => 1000,
    'reason' => 'Remboursement commande ORDER_123',
    'network' => 'FLOOZ',
    'reference' => 'REF_' . time() // Optionnel
]);

// Obtenir l'URL de callback configurée
$callbackUrl = PayGateGlobal::getCallbackUrl();
echo $callbackUrl; // https://votre-site.com/paygate-global/webhook

// Dans un EventServiceProvider
use PayGate\LaravelPayGateGlobal\Events\PaymentReceived;

protected $listen = [
    PaymentReceived::class => [
        YourPaymentReceivedListener::class,
    ],
];



namespace App\Listeners;

use PayGate\LaravelPayGateGlobal\Events\PaymentReceived;
use Illuminate\Support\Facades\Log;

class YourPaymentReceivedListener
{
    public function handle(PaymentReceived $event)
    {
        Log::info('Paiement reçu', [
            'tx_reference' => $event->txReference,
            'identifier' => $event->identifier,
            'amount' => $event->amount,
            'phone_number' => $event->phoneNumber,
            'payment_method' => $event->paymentMethod,
        ]);

        // Mettre à jour votre commande
        // Order::where('identifier', $event->identifier)
        //     ->update(['status' => 'paid']);
    }
}

Schema::create('paygate_transactions', function (Blueprint $table) {
    $table->id();
    $table->string('tx_reference')->unique();
    $table->string('identifier');
    $table->decimal('amount', 15, 2);
    $table->string('phone_number');
    $table->enum('network', ['FLOOZ', 'TMONEY']);
    $table->integer('status')->default(2);
    // ... autres colonnes
});

// Messages de statut en français
$message = PayGateGlobal::getStatusMessage(0); // "Paiement réussi avec succès"
$message = PayGateGlobal::getTransactionStatusMessage(2); // "Jeton d'authentification invalide"

// Validation de signature webhook
$isValid = PayGateGlobal::validateWebhookSignature($payload, $signature);
bash
# Publier la configuration
php artisan vendor:publish --tag=paygate-global-config

# Publier les migrations (optionnel)
php artisan vendor:publish --tag=paygate-global-migrations

# Exécuter les migrations
php artisan migrate
env
# OBLIGATOIRE
PAYGATE_GLOBAL_AUTH_TOKEN=xxxx-xxxxx-468c-81aa-xxxxxxxx

# IMPORTANT - URL où PayGateGlobal enverra les notifications de paiement
# Si non définie, utilisera: https://votre-site.com/paygate-global/webhook
PAYGATE_GLOBAL_CALLBACK_URL=https://votre-site.com/paygate-global/webhook

# OPTIONNEL - Pour la sécurité des webhooks (recommandé)
PAYGATE_GLOBAL_WEBHOOK_SECRET=votre-secret-webhook

# OPTIONNEL - Paramètres avancés (valeurs par défaut)
PAYGATE_GLOBAL_TIMEOUT=30
PAYGATE_GLOBAL_LOG_REQUESTS=true

# DÉVELOPPEMENT UNIQUEMENT - SSL Certificate
# Désactiver la vérification SSL en environnement local (défaut: true)
PAYGATE_GLOBAL_VERIFY_SSL=false