PHP code example of praisedare / monnify-sdk
1. Go to this page and download the library: Download praisedare/monnify-sdk 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/ */
praisedare / monnify-sdk example snippets
use PraiseDare\Monnify\Monnify;
$monnify = new Monnify([
'secret_key' => 'your_secret_key',
'api_key' => 'your_api_key',
'contract_code' => 'your_contract_code',
'environment' => 'sandbox', // or 'live'
]);
$paymentData = [
'amount' => 1000.00,
'customerName' => 'John Doe',
'customerEmail' => '[email protected] ',
'paymentReference' => 'TXN-' . uniqid(),
'paymentDescription' => 'Payment for services',
'currencyCode' => 'NGN',
'contractCode' => 'your_contract_code',
'redirectUrl' => 'https://yourwebsite.com/callback',
'paymentMethods' => ['CARD', 'ACCOUNT_TRANSFER', 'USSD']
];
$response = $monnify->payment()->initialize($paymentData);
$transactionReference = 'MNFY|20240101|123456789';
$response = $monnify->payment()->verify($transactionReference);
$webhookData = $request->getContent();
$signature = $request->header('MNFY-SIGNATURE');
if ($monnify->webhook()->verify($webhookData, $signature)) {
$payload = json_decode($webhookData, true);
// Process the webhook data
}
$config = [
'secret_key' => env('MONNIFY_SECRET_KEY'),
'api_key' => env('MONNIFY_API_KEY'),
'contract_code' => env('MONNIFY_CONTRACT_CODE'),
'environment' => env('MONNIFY_ENVIRONMENT', 'sandbox'),
'timeout' => 30, // HTTP timeout in seconds
'verify_ssl' => true, // SSL verification
];
$response = $monnify->payment()->initialize([
'amount' => 1000.00,
'customerName' => 'John Doe',
'customerEmail' => '[email protected] ',
'paymentReference' => 'TXN-' . uniqid(),
'paymentDescription' => 'Payment for services',
'currencyCode' => 'NGN',
'contractCode' => 'your_contract_code',
'redirectUrl' => 'https://yourwebsite.com/callback',
'paymentMethods' => ['CARD', 'ACCOUNT_TRANSFER', 'USSD']
]);
$response = $monnify->payment()->verify('MNFY|20240101|123456789');
$response = $monnify->payment()->getStatus('MNFY|20240101|123456789');
$response = $monnify->refund()->initiate([
'transactionReference' => 'MNFY|20240101|123456789',
'refundAmount' => 500.00,
'refundReason' => 'Customer request',
'refundReference' => 'REF-' . uniqid()
]);
$response = $monnify->refund()->getStatus('REF-' . uniqid());
$response = $monnify->settlement()->getAccounts();
$response = $monnify->settlement()->getTransactions([
'page' => 1,
'size' => 20,
'fromDate' => '2024-01-01',
'toDate' => '2024-01-31'
]);
$isValid = $monnify->webhook()->verify($webhookData, $signature);
$payload = $monnify->webhook()->parse($webhookData);
try {
$response = $monnify->payment()->initialize($paymentData);
} catch (PraiseDare\Monnify\Exceptions\MonnifyException $e) {
// Handle Monnify-specific errors
echo "Error: " . $e->getMessage();
echo "Code: " . $e->getCode();
} catch (Exception $e) {
// Handle general errors
echo "General Error: " . $e->getMessage();
}
[
'success' => true,
'data' => [
// Response data
],
'message' => 'Operation successful',
'code' => 'SUCCESS'
]