PHP code example of inqord / paymenthelper

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

    

inqord / paymenthelper example snippets


use Inqord\PaymentHelper\Facades\PaymentHelper;
use Inqord\PaymentHelper\DataTransferObjects\PaymentRequest;

$checkoutUrl = PaymentHelper::initiate(new PaymentRequest([
    'transaction_id' => 'INV-12345',
    'amount'         => 500.00,
    'customer_name'  => 'John Doe',
    'customer_email' => '[email protected]',
    'customer_phone' => '01700000000',
    'success_url'    => route('payment.success'),
    'fail_url'       => route('payment.fail'),
    'cancel_url'     => route('payment.cancel'),
    
    // Optional Dynamic Shipping/Product Fields
    'currency'          => 'BDT',
    'customer_address'  => 'Dhanmondi, Dhaka',
    'customer_city'     => 'Dhaka',
    'customer_postcode' => '1205',
    'customer_country'  => 'Bangladesh',
    'shipping_method'   => 'NO',
    'num_of_item'       => 1,
    'product_category'  => 'Tuition Fee',
    'product_profile'   => 'general',
    'intent'            => 'sale', // Primarily used for bKash

    // Secure Gateway Metadata Passthrough
    'metadata'       => [
        'user_id' => 5,
        'item'    => 'premium_subscription'
    ]
]));

return redirect($checkoutUrl);

use Illuminate\Http\Request;
use Inqord\PaymentHelper\Facades\PaymentHelper;

public function paymentSuccess(Request $request)
{
    $verification = PaymentHelper::verify($request);

    if ($verification->isSuccessful()) {
        $transactionId = $verification->transactionId;
        $amount = $verification->amount;
        $metadata = $verification->metadata; // Contains 'user_id' and 'item' from above

        // Your database logic to mark the order as paid...
        return redirect('/dashboard')->with('success', 'Payment successful!');
    }

    return redirect('/dashboard')->with('error', 'Payment failed or declined.');
}
bash
php artisan paymenthelper:install