PHP code example of krafsys / payment-manager

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

    

krafsys / payment-manager example snippets


use Krafsys\PaymentManager\PaymentManager;
use Krafsys\PaymentManager\DTO\PaymentRequest;

$manager = new PaymentManager([
    'paystack' => [
        'secret_key' => 'sk_test_xxx',
    ],
    'flutterwave' => [
        'secret_key' => 'FLWSECK_TEST-xxx',
        'webhook_secret' => 'your-configured-verif-hash',
    ],
    'monnify' => [
        'api_key' => 'MK_TEST_xxx',
        'secret_key' => 'xxx',
        'contract_code' => '123456789',
        'sandbox' => true,
    ],
    'kora' => [
        'secret_key' => 'sk_test_xxx',
    ],
    'bachs' => [
        'secret_key' => 'sk_test_xxx',
        'webhook_secret' => 'whsec_xxx',
        'sandbox' => true,
    ],
]);

$response = $manager->gateway('paystack')->initialize(new PaymentRequest(
    amount: 5000.00,          // major unit — Naira, not kobo. Each adapter converts internally.
    email: '[email protected]',
    reference: 'order_1029',  // optional — omit to auto-generate
    redirectUrl: 'https://yourapp.com/payments/callback',
    description: 'Order #1029',
));

if ($response->successful) {
    header('Location: ' . $response->checkoutUrl);
    exit;
}

$result = $manager->gateway('paystack')->verify('order_1029');

if ($result->isSuccessful()) {
    // $result->amount, $result->currency, $result->paidAt are all normalized
}

use Krafsys\PaymentManager\DTO\RefundRequest;

$refund = $manager->gateway('paystack')->refund(new RefundRequest(
    reference: 'order_1029',
    amount: 1000.00,   // omit for a full refund
    reason: 'Customer requested cancellation',
));

$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] ?? null; // header name differs per gateway, see table below

$gateway = $manager->gateway('paystack');

if (!$gateway->verifyWebhookSignature($rawBody, $signature)) {
    http_response_code(401);
    exit;
}

$event = $gateway->parseWebhookPayload(json_decode($rawBody, true));

if ($event->status === \Krafsys\PaymentManager\Enums\TransactionStatus::Success) {
    // fulfil the order using $event->reference
}

use Krafsys\PaymentManager\Laravel\Facades\PaymentManager;

$response = PaymentManager::gateway('flutterwave')->initialize($paymentRequest);
bash
php artisan vendor:publish --tag=payment-manager-config