PHP code example of mainul / pay-station-disbursement

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

    

mainul / pay-station-disbursement example snippets


use Mainul12501\BkashDisbursement\Data\DisbursementPayload;
use Mainul12501\BkashDisbursement\Facades\BkashDisbursement;

$response = BkashDisbursement::disburse(new DisbursementPayload(
    invoiceNumber: '1213456789199973',
    bankType: 1,
    bankId: 2,
    accountNumber: '01726315133',
    amount: '20.00',
));

$response->transactionId;   // 73KIO6OC
$response->invoiceNumber;   // 1213456789199973
$response->amount;          // 20
$response->charge;          // 0.14
$response->transactionTime; // 2026-01-15 12:30:00
$response->message;         // The amount has been disbursed successfully

$response = BkashDisbursement::disburse([
    'invoice_number' => '1213456789199973',
    'bank_type' => 1,
    'bank_id' => 2,
    'acc_no' => '01726315133',
    'amount' => '20.00',
]);

use Mainul12501\BkashDisbursement\Facades\BkashDisbursement;

$status = BkashDisbursement::status('178881732008099');

if ($status->isSuccessful()) {
    // Disbursement completed successfully.
    $status->transactionId;
    $status->amount;
}

if ($status->isNotFound()) {
    // No transaction matched the invoice number.
}

$status->message;

use Mainul12501\BkashDisbursement\Contracts\BkashDisbursementClient;

class CheckDisbursementStatusAction
{
    public function __construct(
        private readonly BkashDisbursementClient $client,
    ) {
    }

    public function handle(string $invoiceNumber): string
    {
        return $this->client->status($invoiceNumber)->message;
    }
}

use Mainul12501\BkashDisbursement\Contracts\BkashDisbursementClient;

$client = app(BkashDisbursementClient::class)
    ->withCredentials(
        merchantId: 'another-merchant-id',
        password: 'another-hashed-password',
        requestFromMerchantPortalKey: 'another-portal-key',
    );

$response = $client->disburse([
    'invoice_number' => 'INV-2026-0001',
    'bank_type' => 1,
    'bank_id' => 2,
    'acc_no' => '01726315133',
    'amount' => '20.00',
]);

use Mainul12501\BkashDisbursement\Exceptions\ApiException;
use Mainul12501\BkashDisbursement\Exceptions\HttpRequestException;
use Mainul12501\BkashDisbursement\Exceptions\InvalidConfigurationException;
use Mainul12501\BkashDisbursement\Exceptions\RequestValidationException;
use Mainul12501\BkashDisbursement\Exceptions\UnexpectedResponseException;
use Mainul12501\BkashDisbursement\Facades\BkashDisbursement;

try {
    $response = BkashDisbursement::disburse([
        'invoice_number' => 'INV-2026-0001',
        'bank_type' => 1,
        'bank_id' => 2,
        'acc_no' => '01726315133',
        'amount' => '20.00',
    ]);
} catch (RequestValidationException $e) {
    // Local payload validation failed before the HTTP request was sent.
    $errors = $e->errors; // array keyed by field name
} catch (InvalidConfigurationException $e) {
    // Required credentials are missing from config or runtime overrides.
    $message = $e->getMessage();
} catch (HttpRequestException $e) {
    // The remote API returned a non-2xx response or could not be reached.
    $status = $e->httpStatus;     // ?int
    $body   = $e->responseBody;   // ?string
} catch (ApiException $e) {
    // The remote API returned an application-level failure (e.g. duplicate invoice).
    $apiCode     = $e->apiStatusCode; // ?string
    $apiResponse = $e->response;      // array
} catch (UnexpectedResponseException $e) {
    // The remote API returned a malformed or non-JSON response.
    $body = $e->responseBody; // ?string
}
bash
php artisan vendor:publish --tag=bkash-disbursement-config