PHP code example of mavunta / laravel-mavunta

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

    

mavunta / laravel-mavunta example snippets


use Mavunta\Laravel\Facades\Mavunta;

$intent = Mavunta::paymentIntents()->create([
    'amount' => (string) $order->total,
    'currency' => 'KES',
    'settlement_currency' => 'USDT',
    'payment_methods' => ['mpesa', 'card', 'mavunta_balance'],
    'merchant_reference' => (string) $order->id,
]);

return redirect()->away($intent['checkout_url']);

use Mavunta\Laravel\Events\MavuntaWebhookReceived;

Event::listen(function (MavuntaWebhookReceived $event) {
    if ($event->type() === 'payment_intent.paid') {
        $orderId = $event->data()['merchant_reference'] ?? null;
        // fulfil the order; dedupe on $event->id()
    }
});