PHP code example of weexduunx / laravel-aida-gateway
1. Go to this page and download the library: Download weexduunx/laravel-aida-gateway 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/ */
weexduunx / laravel-aida-gateway example snippets
use Weexduunx\AidaGateway\Facades\Aida;
// Utiliser le gateway par défaut
$response = Aida::pay(
phoneNumber: '+221771234567',
amount: 5000,
description: 'Paiement pour commande #12345'
);
// Utiliser un gateway spécifique
$response = Aida::gateway('wave')->pay(
phoneNumber: '+221771234567',
amount: 5000,
description: 'Paiement Wave'
);
// Vérifier le résultat
if ($response->isSuccessful()) {
echo "Transaction ID: " . $response->getTransactionId();
echo "Statut: " . $response->getStatus();
// Récupérer l'URL de paiement si disponible
$paymentUrl = $response->getData()['payment_url'] ?? null;
if ($paymentUrl) {
return redirect($paymentUrl);
}
} else {
echo "Erreur: " . $response->getMessage();
}
use Weexduunx\AidaGateway\Events\PaymentSuccessful;
use Weexduunx\AidaGateway\Events\PaymentFailed;
use Weexduunx\AidaGateway\Events\PaymentPending;
// Dans EventServiceProvider
protected $listen = [
PaymentSuccessful::class => [
\App\Listeners\SendPaymentConfirmation::class,
],
PaymentFailed::class => [
\App\Listeners\NotifyPaymentFailure::class,
],
PaymentPending::class => [
\App\Listeners\LogPendingPayment::class,
],
];
namespace App\Listeners;
use Weexduunx\AidaGateway\Events\PaymentSuccessful;
class SendPaymentConfirmation
{
public function handle(PaymentSuccessful $event)
{
$transaction = $event->transaction;
// Envoyer une notification au client
// Mettre à jour la commande
// etc.
}
}
use Weexduunx\AidaGateway\Http\Middleware\SecureTransaction;
// Dans un contrôleur
Route::post('/payment', [PaymentController::class, 'process'])
->middleware(SecureTransaction::class);
use Weexduunx\AidaGateway\Models\Transaction;
// Récupérer toutes les transactions réussies
$successfulTransactions = Transaction::successful()->get();
// Filtrer par gateway
$waveTransactions = Transaction::byGateway('wave')->get();
// Récupérer les transactions en attente
$pendingTransactions = Transaction::pending()->get();
// Récupérer une transaction spécifique
$transaction = Transaction::where('transaction_id', 'TXN_123')->first();
// Vérifier le statut
if ($transaction->isSuccessful()) {
echo "Transaction réussie";
}
// Obtenir le montant formaté
echo $transaction->formatted_amount; // "5,000.00 XOF"
// Obtenir le nom du gateway
echo $transaction->gateway_display_name; // "Orange Money"
use Weexduunx\AidaGateway\Exceptions\GatewayNotFoundException;
use Weexduunx\AidaGateway\Exceptions\GatewayNotEnabledException;
try {
$response = Aida::gateway('invalid_gateway')->pay(...);
} catch (GatewayNotFoundException $e) {
// Gateway non supporté
} catch (GatewayNotEnabledException $e) {
// Gateway désactivé dans la configuration
}