PHP code example of paymint / paymint-php

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

    

paymint / paymint-php example snippets




use PayMint\PayMintClient;

$paymint = new PayMintClient('sec_live_your_secret_key');

// Initialize Checkout
$checkout = $paymint->checkout()->initialize([
    'amount'       => 5000,
    'email'        => '[email protected]',
    'reference'    => 'ORDER_12345', // Optional unique reference
    'redirect_url' => 'https://mywebsite.com/payment/callback',
    'name'         => 'John Doe',     // Optional
    'phone'        => '08012345678', // Optional
]);

// Redirect customer to the payment page
header('Location: ' . $checkout['data']['authorization_url']);
exit;

// Verify Payment upon return
$payment = $paymint->checkout()->verify('ORDER_12345');

if ($payment['data']['status'] === 'successful') {
    // Transaction is verified! Give value to customer
}

$response = $paymint->virtualAccounts()->create([
    'name'  => 'John Doe',
    'email' => '[email protected]',
    'phone' => '08012345678',
    'bvn'   => '12345678901' // Optional
]);

print_r($response);

$payload   = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_PAYMINT_SIGNATURE'] ?? '';

if (!$paymint->webhooks()->verifySignature($payload, $signature)) {
    http_response_code(401);
    die('Invalid signature detected.');
}

// Process webhook safely!
echo "Webhook verified successfully!";
bash
composer