raziul/sslcommerz-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

raziul/sslcommerz-laravel

Composer 安装命令:

composer require raziul/sslcommerz-laravel

包简介

SSLCommerz Laravel is a super easy package to integrate SSLCommerz on Laravel websites.

README 文档

README

Sslcommerz Laravel Package

Sslcommerz Laravel Package

Latest Version on Packagist Laravel Compatibility GitHub Tests Action Status Total Downloads License

This package provides an easy and convenient way to integrate SSLCommerz payment gateway into your Laravel application. With features like payment processing, payment validation, refunds, and hash verification, this package offers a simple API for developers to quickly implement payment functionality.

Features

  • Great Developer Experience
  • Initiate payments via SSLCommerz
  • Set callback URLs for success, failure, cancellation and IPN
  • Validate payment transactions
  • Refund payments and check refund status
  • Verify hash from SSLCommerz responses
  • Sandbox and live environment support

Requirements

  • PHP 8.2+
  • Laravel 10+
  • SSLCommerz Credentials

Installation

You can install the package via Composer:

composer require raziul/sslcommerz-laravel

Once installed, the service provider will be registered automatically.

Configuration

Add the following environment variables to your .env file:

SSLC_SANDBOX=true # or false for live
SSLC_STORE_ID=your_store_id
SSLC_STORE_PASSWORD=your_store_password
SSLC_STORE_CURRENCY='BDT'

# SSLCommerz route names (optional)
SSLC_ROUTE_SUCCESS='sslc.success'
SSLC_ROUTE_FAILURE='sslc.failure'
SSLC_ROUTE_CANCEL='sslc.cancel'
SSLC_ROUTE_IPN='sslc.ipn'

Optionally, You can publish the configuration file using the following command:

php artisan sslcommerz:install

This will publish the sslcommerz.php file to your config directory.

Getting Sandbox Credentials

SSLCommerz credentials are required to use this package. You can get sandbox credentials by following these steps:

  1. Create Sandbox Account: Visit the https://developer.sslcommerz.com/registration/ page to create an account.

  2. Obtain Credentials: After registration, you will receive your Store ID and Store Password via email or from the SSLCommerz dashboard.

  3. Set Up in .env: Copy these credentials and paste them into your .env file as shown in the Configuration step.

Important

Sandbox credentials are for testing purposes only. You should replace them with your live credentials and change SANDBOX=false before deploying to production.

💡 Usage

1. Defining Callback Routes

To handle different stages of the payment lifecycle, define your callback routes for success, failure, cancellation, and IPN (Instant Payment Notification):

Route::controller(SslcommerzController::class)
    ->prefix('sslcommerz') // prefix to avoid conflicts
    ->name('sslc.')
    ->group(function () {
        Route::post('success', 'success')->name('success');
        Route::post('failure', 'failure')->name('failure');
        Route::post('cancel', 'cancel')->name('cancel');
        Route::post('ipn', 'ipn')->name('ipn');
    });

We defined the sslc.success, sslc.failure, sslc.cancel, and sslc.ipn routes according to the configured route names. Now create the SslcommerzController controller and implement the success, failure, cancel, and ipn methods as required.

2. Initiating a Payment

Initiating a payment has never been easier. For example, you can use the following code:

use \Raziul\Sslcommerz\Facades\Sslcommerz;

$response = Sslcommerz::setOrder($amount, $invoiceId, $productName)
    ->setCustomer($customerName, $customerEmail, $customerPhone)
    ->setShippingInfo($itemsQuantity, $address)
    ->makePayment();

if ($response->success()) {
    // payment initiated, redirect to payment page
    return redirect($response->gatewayPageURL());
} else {
    // Handle payment failure
}

The makePayment method returns an instance of Raziul\Sslcommerz\Data\PaymentResponse class. Check the available methods for more details.

3. Validating a Payment

To validate a payment after a successful transaction:

use \Raziul\Sslcommerz\Facades\Sslcommerz;

$isValid = Sslcommerz::validatePayment($requestData, $transactionId, $amount);

if ($isValid) {
    // Payment is valid
} else {
    // Payment is invalid
}

4. Refunds

If you need to refund a payment, you can do so easily:

$refundResponse = Sslcommerz::refundPayment($bankTransactionId, $amount, $reason);

You can also check the refund status:

$refundStatus = Sslcommerz::checkRefundStatus($refundRefId);

5. Hash Verification

To verify the authenticity of the response from SSLCommerz, use the verifyHash method:

if (Sslcommerz::verifyHash($request->all())) {
    // Hash is valid
}

📖 Documentation

You can find detailed documentation, guides and examples on the Wiki.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

raziul/sslcommerz-laravel 适用场景与选型建议

raziul/sslcommerz-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.04k 次下载、GitHub Stars 达 73, 最近一次更新时间为 2024 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「sslcommerz」 「sslcommerz-laravel」 「sslcommerz-payment-gateway」 「laravel-sslcommerz」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 raziul/sslcommerz-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 raziul/sslcommerz-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 raziul/sslcommerz-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 73
  • 点击次数: 7
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 73
  • Watchers: 1
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-02