PHP code example of paymint / paymint-laravel

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


use PayMint\Laravel\Facades\PayMint;

class PaymentController extends Controller
{
    // Step 1: Initialize and redirect customer
    public function initiatePayment(Request $request)
    {
        $response = PayMint::checkout()->initialize([
            'amount'       => 5000,
            'email'        => $request->user()->email,
            'reference'    => 'ORDER_' . uniqid(),
            'redirect_url' => route('payment.callback'),
            'name'         => $request->user()->name,
        ]);

        return redirect($response['data']['authorization_url']);
    }

    // Step 2: Handle customer return & verify
    public function handleCallback(Request $request)
    {
        $reference = $request->query('reference');
        $payment = PayMint::checkout()->verify($reference);

        if (($payment['data']['status'] ?? '') === 'successful') {
            // Order is paid! Deliver value
            return view('payment.success');
        }

        return view('payment.failed');
    }
}

use PayMint\Laravel\Facades\PayMint;

$account = PayMint::virtualAccounts()->create([
    'name'  => 'Jane Doe',
    'email' => '[email protected]',
    'phone' => '08123456789'
]);

return response()->json($account);

use Illuminate\Http\Request;
use PayMint\Laravel\Facades\PayMint;
use Illuminate\Support\Facades\Route;

Route::post('/webhook/paymint', function (Request $request) {
    $payload = $request->getContent();
    $signature = $request->header('X-Paymint-Signature');

    if (!PayMint::webhooks()->verifySignature($payload, $signature)) {
        return response()->json(['error' => 'Invalid signature detected.'], 401);
    }

    $event = $request->input('event');
    if ($event === 'payment.success') {
        // Credit the customer's wallet or update order status
    }

    return response()->json(['status' => 'success']);
});