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/ */
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');