PHP code example of softscholar / laravel-payments

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

    

softscholar / laravel-payments example snippets


return [
    'mode' => env('PAYMENT_GATEWAY_MODE', 'sandbox'),
    'gateways' => [
        'nagad' => [
            'mode' => env('NAGAD_MODE', 'sandbox'),
            'merchant_id' => env('NAGAD_MERCHANT_ID', 'your-merchant-id'),
            'merchant_public_key' => env('NAGAD_PG_PUBLIC_KEY', 'your-merchant-public-key'),
            'merchant_private_key' => env('NAGAD_MERCHANT_PRIVATE_KEY', 'merchant-private-key'),
            'merchant_number' => env('NAGAD_MERCHANT_NUMBER', 'your-merchant-number'),
            'tokenization' => env('NAGAD_TOKENIZATION', false),
            'ssl_verify' => env('NAGAD_SSL_VERIFY', false), // on production set it to true
            'merchant_hex' => env('NAGAD_MERCHANT_HEX', 'your-merchant-hex'),
            'merchant_iv' => env('NAGAD_MERCHANT_IV', 'your-merchant-iv'),
        ],
    ],
    ...
];


use Softscholar\Payment\Services\Gateways\Nagad\Nagad;

        $merchantCallbackURL = route('gateways.nagad.callback');
        
        $checkoutData =  [
            'callback_url' => $merchantCallbackURL,
            'order_id' => $product->id . 'Ord' . time(),
            'customer_id' => $customerId, // must be greater than 4 digits
            'additional_info' => [
                'additionalFieldNameBN' => 'পণ্যের নাম',
                'additionalFieldNameEN' => 'Product Name',
                'additionalFieldValue' => $product->name,
            ],
            'amount' => $product->price,
        ];
        
    // create an instance of Nagad
    $nagad = new Nagad(
            $YourMerchantId,
            $YourMerchantPgKey,
            $YourMerchantPrivateKey,
            $YourMerchantHex,
            $YourMerchantIv,
            $YourMerchantNumber
        );

    /**
     * checkout method takes two parameters
        * 1. checkoutData
        * 2. checkoutType (optional) - default is 'regular'
        * Types: 'regular', 'authorize', 'tokenized'
        * For tokenized checkout, you will need to authorize the payment first by passing 'authorize' as the second parameter
        * After authorizing the payment, you will get a account details, store the thoose details and use them to tokenize the payment
        * once you have token then call the checkout method with 'tokenized' as the second parameter
     */
     
    // initiate the payment and get the redirect URL
     $redirectUrl = $nagad->checkout($checkoutData); // for regular checkout

    // for tokenization you will need to authorize the payment first
    // with zero(0) amount
    $checkoutData['amount'] = 0;
    $redirectUrl = $nagad->checkout($checkoutData, 'authorize');

    // store the account details and use them to tokenize the payment
    // once you have token then call the checkout method with 'tokenized' as the second parameter
    $redirectUrl = $nagad->checkout($checkoutData, 'tokenized');

'merchant' => 'your-merchant-id',
'order_id' => 'order-id',
'payment_ref_id' => 'payment-ref-id',
'status' => 'payment-status',
'status_code' => 'payment-status-code',
'message' => 'payment-message',
'payment_dt' => 'payment-date-time'
bash
php artisan vendor:publish --provider="Softscholar\Payment\PaymentServiceProvider"