Rules for creating payment gateway of bkash
If you want to setup Bkash Payment Gateway you need to follow some steps. Below I am giving a step by step guide on how you can integrate Bkash Payment Gateway. For this we will use Bkash's Merchant API.
1. Essentials for Bkash API Integration
Bkash Merchant Account: You must have a Bkash Merchant Account. If not you can apply for Bkash Merchant.
API Credentials: Bkash will provide you API Username, API Password, App Key, and App Secret after Merchant Account setup.
SSL Certificate: An SSL certificate is mandatory for Bkash payment gateway.
Webhook URL: You need to set a Webhook URL to receive payment notifications.
2. Payment Gateway Integration Process
Step 1: Environment Setup
First setup your PHP environment or any other server-side environment.
composer.json file (if using PHP)
json
Copy code
{
"require": {
"guzzlehttp/guzzle": "^7.0"
}
}
Then run composer install.
ধাপ ২: ফাইল এবং ডিরেক্টরি স্ট্রাকচার
plaintext
Copy code
project-root/
├── index.php
├── bkash/
│ ├── config.php
│ ├── token.php
│ ├── create_payment.php
│ ├── execute_payment.php
│ └── query_payment.php
└── success.php
ধাপ ৩: Bkash API Configuration (bkash/config.php)
php
Copy code
return [
'base_url' => 'https://checkout.sandbox.bka.sh/v1.2.0-beta',
'username' => 'YOUR_BKASH_USERNAME',
'password' => 'YOUR_BKASH_PASSWORD',
'app_key' => 'YOUR_APP_KEY',
'app_secret' => 'YOUR_APP_SECRET',
'callback_url' => 'https://fqrhost.com/success.php'
];
?>
ধাপ ৪: Access Token Generate (bkash/token.php)
php
Copy code
$config = include('config.php');
function generateToken() {
global $config;
$url = $config['base_url'] . '/checkout/token/grant';
$headers = [
'Content-Type:application/json',
'username:' . $config['username'],
'password:' . $config['password']
];
$data = [ 'app_key' => $config['app_key'], 'app_secret' => $config['app_secret'] ]; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); curl_close($curl); $response = json_decode($result, true); return $response['id_token']; </p> <p>}</p> <p>$token = generateToken();<br> ?><br> ধাপ ৫: Create Payment (bkash/create_payment.php)<br> php<br> Copy code<br> <?php<br> include('token.php');</p> <p>function createPayment($amount) {<br> global $config, $token;<br> $url = $config['base_url'] . '/checkout/payment/create';<br> $headers = [<br> 'Content-Type:application/json',<br> 'authorization:' . $token,<br> 'x-app-key:' . $config['app_key']<br> ];</p> <pre class="brush:php;toolbar:false">$data = [ 'amount' => $amount, 'currency' => 'BDT', 'intent' => 'sale', 'merchantInvoiceNumber' => 'INV-' . uniqid(), 'callbackURL' => $config['callback_url'] ]; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); curl_close($curl); return json_decode($result, true); </p> <p>}</p> <p>$response = createPayment(1000); // ১০০০ টাকা পেমেন্ট<br> header('Location: ' . $response['bkashURL']);<br> ?><br> ধাপ ৬: Execute Payment (bkash/execute_payment.php)<br> php<br> Copy code<br> <?php<br> include('token.php');</p> <p>function executePayment($paymentID) {<br> global $config, $token;<br> $url = $config['base_url'] . '/checkout/payment/execute/' . $paymentID;<br> $headers = [<br> 'Content-Type:application/json',<br> 'authorization:' . $token,<br> 'x-app-key:' . $config['app_key']<br> ];</p> <pre class="brush:php;toolbar:false">$curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); curl_close($curl); return json_decode($result, true);
}
if (isset($_GET['paymentID'])) {
$response = executePayment($_GET['paymentID']);
echo '
$data = [ 'app_key' => $config['app_key'], 'app_secret' => $config['app_secret'] ]; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); curl_close($curl); $response = json_decode($result, true); return $response['id_token']; ';
}
?>
Step 7: Success Page (success.php)
php
Copy code
echo "Payment Successful!";
?>
3. System Testing
You can test your system using Bkash's Sandbox Environment.
To use Production Mode, update your API Key and URL from Bkash.
4. Webhook setup (optional)
Bkash can use Webhook URL for payment updates. A notification will be sent to you with payment information.buy domain hosting
The above is the detailed content of Rules for creating payment gateway of bkash. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
