PHP code example of amdadulhaq / bd-payment-laravel

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

    

amdadulhaq / bd-payment-laravel example snippets


use AmdadulHaq\BdPayment\Facades\Payment;
use AmdadulHaq\BdPayment\DataTransferObjects\PaymentRequest;

$response = Payment::initiate(new PaymentRequest(
    amount: 490.00,
    invoiceNumber: 'INV-1001',
    customerName: $user->name,
    customerEmail: $user->email,
    customerPhone: $user->phone,
    successUrl: route('payments.callback'),
    failUrl: route('payments.callback'),
    cancelUrl: route('payments.callback'),
));

// Redirect-based gateways (bkash/nagad/sslcommerz) hand back a checkout URL.
if ($response->redirectUrl) {
    return redirect($response->redirectUrl);
}

// The manual driver has no redirect — show the payer these instructions instead.
$response->message; // "Send the exact amount via bKash/Nagad Send Money to 01700..."

$result = Payment::verify($paymentId, [
    'transaction_id' => $request->input('transaction_id'), // manual driver
]);

if ($result->status->isSuccessful()) {
    // grant access
}

Payment::query($paymentId);

Payment::refund($paymentId, amount: 100.00);

Payment::driver('sslcommerz')->initiate($request);

use AmdadulHaq\BdPayment\Facades\Payment;

Route::post('/payments/ipn/sslcommerz', function (Request $request) {
    $result = Payment::driver('sslcommerz')->handleWebhook($request->all());

    if ($result->status->isSuccessful()) {
        // grant access
    }

    return response()->noContent();
})->withoutMiddleware([\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);

use AmdadulHaq\BdPayment\Facades\Payment;

Payment::extend('my-gateway', function ($app) {
    return new MyGatewayDriver(/* ... */);
});

interface PaymentDriver
{
    public function initiate(PaymentRequest $request): PaymentResponse;

    public function verify(string $gatewayPaymentId, array $payload = []): PaymentResponse;

    public function query(string $gatewayPaymentId): PaymentResponse;

    public function refund(string $gatewayPaymentId, ?float $amount = null): PaymentResponse;

    public function handleWebhook(array $payload): PaymentResponse;
}

use AmdadulHaq\BdPayment\Facades\Payment;

$fake = Payment::fake();

// ... code under test that calls Payment::initiate() ...

$fake->assertInitiated('INV-1001');
$fake->assertNothingInitiated();
bash
php artisan vendor:publish --tag=payment-config