cryptopayment / cryptomus-laravel-integrate-market
Laravel 包,用于 cryptomus.com
dev-main
2024-09-30 14:01 UTC
Requires
- php: ^8.1
- cryptomus/api-php-sdk: ^1.0
Requires (Dev)
- illuminate/http: ^8.83
- illuminate/routing: ^8.83
- illuminate/support: ^8.0
This package is not auto-updated.
Last update: 2024-10-01 12:20:48 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="cryptopayment\Cryptomus\CryptomusServiceProvider" --tag="cryptomus"
如果发布文件失败,请在此包中创建路径 config/cryptomus.php
和 app\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 cryptopayment\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 ); } }
贡献
有关详细信息,请参阅 CONTRIBUTING
安全
如果您发现任何安全问题,请使用问题跟踪器。
鸣谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件