PHP code example of opsofts / laravel-monnify

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

    

opsofts / laravel-monnify example snippets


use Opsofts\LaravelMonnify\Facades\Monnify;

// Initialize a transaction
$transaction = Monnify::initializeTransaction([
    'amount' => 5000,
    'customerName' => $customer->name,
    'customerEmail' => $customer->email,
    'paymentReference' => $orderReference, // must be unique per attempt
    'paymentDescription' => 'Order #1234',
    'redirectUrl' => route('payment.callback'),
    'paymentMethods' => ['CARD', 'ACCOUNT_TRANSFER'],
]);
// redirect the payer to $transaction['responseBody']['checkoutUrl']

// Verify -- by your own paymentReference (default) or Monnify's transactionReference
$result = Monnify::verifyTransaction($orderReference);
// or: Monnify::verifyTransaction($transactionReference, type: 'transactionReference');

if ($result['responseBody']['paymentStatus'] === 'PAID'
    && $result['responseBody']['amountPaid'] >= $expectedAmount) {
    // mark the order/payment as paid
}
// PARTIALLY_PAID / OVERPAID / PENDING / FAILED / REVERSED / EXPIRED are the
// other possible statuses -- see Monnify's docs for how to handle each.

// Refund (full or partial) --