PHP code example of mavunta / mavunta-php
1. Go to this page and download the library: Download mavunta/mavunta-php 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 / mavunta-php example snippets
use Mavunta\Mavunta;
$mavunta = new Mavunta(['apiKey' => getenv('MAVUNTA_SECRET_KEY')]);
$intent = $mavunta->paymentIntents->create([
'amount' => '2500',
'currency' => 'KES',
'settlement_currency' => 'USDT',
'payment_methods' => ['mpesa', 'card', 'mavunta_balance'],
'merchant_reference' => 'ORDER-1001',
]);
header('Location: ' . $intent['checkout_url']);
$mavunta->auth->verify();
$mavunta->rates->retrieve();
$mavunta->quotes->create(['source_currency' => 'KES', 'target_asset' => 'USDT', 'amount' => '2500']);
$mavunta->paymentIntents->create($params, ['idempotencyKey' => 'order-1001']);
$mavunta->paymentIntents->retrieve('pi_...');
$mavunta->paymentIntents->all(['limit' => 20, 'status' => 'paid']);
$mavunta->paymentIntents->cancel('pi_...');
$mavunta->paymentIntents->refundRequest('pi_...', ['reason' => 'Customer returned item']);
$mavunta->paymentLinks->create(['title' => 'Deposit', 'amount' => '15000', 'currency' => 'KES']);
$mavunta->paymentLinks->retrieve('pl_...');
$payload = file_get_contents('php://input');
try {
$event = $mavunta->webhooks->verify(
$payload,
$_SERVER['HTTP_MAVUNTA_SIGNATURE'],
$_SERVER['HTTP_MAVUNTA_TIMESTAMP'],
getenv('MAVUNTA_WEBHOOK_SECRET')
);
if ($event['type'] === 'payment_intent.paid') {
// fulfil the order (dedupe on $event['id'])
}
http_response_code(200);
} catch (\Mavunta\MavuntaError $e) {
http_response_code(400);
}
try {
$mavunta->paymentIntents->create(['amount' => '0', 'currency' => 'KES']);
} catch (\Mavunta\MavuntaError $e) {
error_log($e->type . ' ' . $e->apiCode . ' ' . $e->getMessage() . ' ' . $e->getRequestId());
}
bash
composer