rtraselbd/bkash-php

A PHP library for integrating with the bKash payment gateway

v1.0.0 2023-10-22 08:12 UTC

This package is auto-updated.

Last update: 2024-09-13 11:40:49 UTC


README

The bKash PHP library is a convenient way to integrate the bKash payment gateway into your PHP applications. It provides methods for creating and verifying payments. With this library, you can offer your users a seamless and secure way to make payments using the bKash platform.

Table of Contents

Installation

You can easily install the bKash PHP library via Composer:

composer require rtraselbd/bkash-php

Usage

To get started with the bKash PHP library, follow these steps:

  1. Initialize the bKash Object: Create an instance of the bKash class by providing your bKash API credentials in an array.

     use RT\bKash\bKash;
    
     require 'vendor/autoload.php';
    
     $credential = [
        'username'      => 'your-bKash-username',
        'password'      => 'your-bKash-password',
        'app_key'       => 'your-app-key',
        'app_secret'    => 'your-app-secret',
     ];
     $bKash = new bKash($credential);
  2. Create a Payment Request: Use the createPayment method to create a payment request. Provide the required payment request data, including the amount, success URL, and brand name.

    $requestData = [
        'amount'        => 10,
        'success_url'   => 'https://your-website.com/success.php',
        'brand_name'    => 'YourBrandName',
    ];
    
    try {
        $bKashURL = $bKash->createPayment($requestData);
        // Redirect the user to the bKash payment URL
        header('Location: ' . $bKashURL);
    } catch (Exception $e) {
        // Handle any exceptions or errors here
        $error = $e->getMessage();
    }
  3. Verify a Payment: To verify a payment, retrieve the paymentID from the query parameters and use the verifyPayment method.

    $paymentID = $_GET['paymentID'];
    
    try {
        $response = $bKash->verifyPayment($paymentID);
    } catch (Exception $e) {
        // Handle any exceptions or errors here
        $error = $e->getMessage();
    }

License

This library is open-source and licensed under the MIT License. You are free to use and modify it in accordance with the terms of the license.

Feel free to contribute, report issues, or suggest improvements! Your feedback and contributions are highly appreciated.