定制 nictbd/php-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nictbd/php-sdk

Composer 安装命令:

composer require nictbd/php-sdk

包简介

NICTBD.COM PHP SDK for Payment Gateway integration

README 文档

README

Official PHP SDK for NICTBD.COM Payment Gateway.

Requirements

  • PHP 8.1 or higher
  • cURL extension enabled
  • Valid NICTBD.COM merchant API credentials

Installation

composer require nictbd/php-sdk

Basic Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Nictbd\Client;

$client = new Client([
    'base_url' => 'https://nictbd.com',
    'store_id' => 'STORE_ID',
    'api_key' => 'API_KEY',
    'secret_key' => 'SECRET_KEY',
]);

$response = $client->createPayment([
    'amount' => 100,
    'tran_id' => 'INV001',
    'currency' => 'BDT',
    'customer_name' => 'Customer Name',
    'customer_mobile' => '01700000000',
    'customer_email' => 'customer@example.com',
    'success_url' => 'https://merchant.com/payment/success',
    'failed_url' => 'https://merchant.com/payment/failed',
    'cancel_url' => 'https://merchant.com/payment/cancel',
    'webhook_url' => 'https://merchant.com/api/payment/webhook',
]);

if (($response['status'] ?? null) === 'success') {
    header('Location: ' . $response['payment_url']);
    exit;
}

echo $response['message'] ?? 'Payment create failed';

Laravel Configuration

Add credentials to your .env file:

NICTBD_BASE_URL=https://nictbd.com
NICTBD_STORE_ID=STORE_ID
NICTBD_API_KEY=API_KEY
NICTBD_SECRET_KEY=SECRET_KEY

Add this to config/services.php:

'nictbd' => [
    'base_url' => env('NICTBD_BASE_URL', 'https://nictbd.com'),
    'store_id' => env('NICTBD_STORE_ID'),
    'api_key' => env('NICTBD_API_KEY'),
    'secret_key' => env('NICTBD_SECRET_KEY'),
],

Laravel controller example:

use Nictbd\Client;

public function pay()
{
    $client = new Client([
        'base_url' => config('services.nictbd.base_url'),
        'store_id' => config('services.nictbd.store_id'),
        'api_key' => config('services.nictbd.api_key'),
        'secret_key' => config('services.nictbd.secret_key'),
    ]);

    $response = $client->createPayment([
        'amount' => 100,
        'tran_id' => 'INV' . now()->format('YmdHis'),
        'currency' => 'BDT',
        'customer_name' => 'Customer Name',
        'customer_mobile' => '01700000000',
        'customer_email' => 'customer@example.com',
        'success_url' => route('payment.success'),
        'failed_url' => route('payment.failed'),
        'cancel_url' => route('payment.cancel'),
        'webhook_url' => route('payment.webhook'),
    ]);

    if (($response['status'] ?? null) === 'success') {
        return redirect()->away($response['payment_url']);
    }

    return back()->with('error', $response['message'] ?? 'Payment create failed');
}

Verify Payment

$response = $client->verifyPayment('INV001');

if (($response['status'] ?? null) === 'success') {
    // Payment verified successfully.
}

Webhook Signature Verification

use Nictbd\Signature;

$isValid = Signature::verifyWebhook(
    $payload['tran_id'] ?? '',
    $payload['amount'] ?? '',
    $payload['status'] ?? '',
    $payload['signature'] ?? '',
    'SECRET_KEY'
);

if (! $isValid) {
    http_response_code(401);
    exit('Invalid signature');
}

Notes

  • Keep your Secret Key only on your backend server.
  • Never expose Secret Key in frontend JavaScript, mobile app source code or public repository.
  • Always verify webhook signature before updating order status.
  • Use unique tran_id for every payment request.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-13