funnydevjsc/cryptomus-laravel-integrate

1.0.5 2024-08-29 10:58 UTC

This package is auto-updated.

Last update: 2024-09-29 11:15:40 UTC


README

免费的 Laravel 包,帮助您集成 cryptomus.com 的支付

使用案例

  • 使用 cryptomus.com 创建支付链接
  • 解析来自 cryptomus.com 的结果
  • 示例 webhook

功能

  • 从 config/cryptomus.php 动态获取 cryptomus.com 凭据
  • 使用简单的一行代码轻松创建支付链接

要求

  • PHP:8.1 或更高版本
  • Laravel 9.0 或更高版本

快速开始

如果您希望在自己的 Laravel 应用程序中安装此包,请按照以下安装步骤操作

安装

步骤 1. 如果您还没有,请安装一个 Laravel 项目

https://laravel.net.cn/docs/installation

步骤 2. 使用 composer 需要当前包

composer require funnydevjsc/cryptomus-laravel-integrate

步骤 3. 发布控制器文件和配置文件

php artisan vendor:publish --provider="FunnyDev\Cryptomus\CryptomusServiceProvider" --tag="cryptomus"

如果发布文件失败,请在此包中创建路径 config/cryptomus.phpapp\Http\Controllers\CryptomusControllers.php 对应的文件。您还可以进一步自定义 CryptomusControllers.php 文件以适应您的项目。

步骤 4. 更新已发布的配置文件中的各种配置设置

发布包资产后,配置文件将位于 config/cryptomus.php。请联系 cryptomus.com 获取这些值以填充到配置文件中。

步骤 5. 添加中间件保护

app/Http/Kernel.php
<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    // Other kernel properties...
    
    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $routeMiddleware = [
        // Other middlewares...
         'cryptomus' => 'App\Http\Middleware\CryptomusMiddleware',
    ];
}

步骤 6. 添加路由

routes/api.php
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CryptomusController;

// Other routes properties...

Route::group(['middleware' => ['cryptomus']], function () {
    Route::post('/cryptomus/webhook', [CryptomusController::class, 'webhook']);
});

}

然后您的 IPN (Webhook) URL 将类似于 https://yourdomain.ltd/api/cryptomus/webhook,您应将其提供给 Cryptomus 的账户设置。如果您想将其提供给 routes/web.php,也可以,但请记住,Cryptomus 将检查与预注册 URL 匹配的 referer。因此,请确保您提供正确的网站 URL。

测试

<?php

namespace App\Console\Commands;

use FunnyDev\Cryptomus\CryptomusSdk;
use Illuminate\Console\Command;

class CryptomusTestCommand extends Command
{
    protected $signature = 'cryptomus:test';

    protected $description = 'Test Cryptomus SDK';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $instance = new CryptomusSdk();
        echo $instance->create_payment(
            'INV-test-01',
            100,
            'USDT',
            'BSC',
            'INV-test-01',
            'https://yourdomain.ltd/invoices/INV-test-01',
            'https://yourdomain.ltd/invoices/INV-test-01',
            'https://yourdomain.ltd/invoices/INV-test-01?success=true' // Remember that param success=true or any similar is just for toast notification, do not put any logical process here
        );
    }
}

反馈

Laravel Việt Nam 中尊重我们

贡献

有关详细信息,请参阅 CONTRIBUTING

安全

如果您发现任何安全相关的问题,请通过电子邮件 contact@funnydev.vn 或使用问题跟踪器。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件