rtraselbd/bkash-php

bKash支付网关的PHP库集成

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

This package is auto-updated.

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


README

bKash PHP库是一种方便将bKash支付网关集成到您的PHP应用程序中的方式。它提供了创建和验证支付的方法。使用此库,您可以提供用户通过bKash平台进行无缝且安全的支付方式。

目录

安装

您可以通过Composer轻松安装bKash PHP库。

composer require rtraselbd/bkash-php

用法

要开始使用bKash PHP库,请按照以下步骤操作:

  1. 初始化bKash对象:通过提供一个包含您的bKash API凭证的数组来创建一个bKash类的实例。

     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. 创建支付请求:使用createPayment方法创建支付请求。提供所需的支付请求数据,包括金额、成功URL和品牌名称。

    $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. 验证支付:要验证支付,从查询参数中检索paymentID并使用verifyPayment方法。

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

许可证

此库是开源的,并使用MIT许可证授权。您可以在许可证条款的范围内自由使用和修改它。

请随时贡献、报告问题或提出改进建议!您的反馈和贡献非常受欢迎。