pawelsome / coinpayment
CoinPayment PHP 客户端 for Laravel
2.0.0
2018-07-19 14:01 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.3
- nesbot/carbon: ^1.25
This package is not auto-updated.
Last update: 2024-09-20 22:33:12 UTC
README
CoinPayment 是一个 Laravel 模块,用于处理来自 CoinPayment 的交易,如创建交易、历史交易等。
要求
- Laravel ^5.6
- PHP >= ^7.1
- GuzzleHttp
- Nesbot/Carbon
安装
您可以通过 composer 安装此包
$ composer require hexters/coinpayment
发布供应商
$ php artisan vendor:publish --tag=coinpayment-publish
首先,您应该在 User
模型上添加 trait 类,并使用此 trait Hexters\CoinPayment\Entities\CoinPaymentuserRelation
,如下面的示例所示
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Hexters\CoinPayment\Entities\CoinPaymentuserRelation;
class User extends Authenticatable {
use Notifiable, CoinPaymentuserRelation;
...
安装 CoinPayment 配置
$ php artisan coinpayment:install
在您的 app > console > kernel
文件中设置检查交易成功的计划。示例
...
protected function schedule(Schedule $schedule) {
// If IPN is enable set the schedule for ->daily()
// And if IPN is disable set schedule for ->everyMinute()
$schedule->command('coinpayment:transaction-check')
->daily();
}
...
访问 计划文档
安装交易表
$ php artisan migrate
安装完成。
入门
创建交易按钮。示例放在您的控制器中
use CoinPayment; // use outside the class
...
/*
* @required true
*/
$trx['amountTotal'] = 50; // USD
$trx['note'] = 'Note for your transaction';
/*
* @required true
* @example first item
*/
$trx['items'][0] = [
'descriptionItem' => 'Product one',
'priceItem' => 10, // USD
'qtyItem' => 2,
'subtotalItem' => 20 // USD
];
/*
* @example secound item
*/
$trx['items'][1] = [
'descriptionItem' => 'Product two',
'priceItem' => 10, // USD
'qtyItem' => 3,
'subtotalItem' => 30 // USD
];
/*
* if you want to remember your data at a later date, you can add the parameter below
*/
$trx['payload'] = [
// your cusotm array here
'foo' => [
'foo' => 'bar'
]
];
$link_transaction = CoinPayment::url_payload($trx);
...
/*
* On your balde
* <a href="{{ $link_transaction }}" target="_blank">Pay Now</a>
*/
...
请接受来自 csrf 处理的路线,获取 app > Http > Middleware > VerifyCsrfToken.php
文件
...
protected $except = [
...
'/coinpayment/ipn'
...
];
...
打开 app > Jobs > coinPaymentCallbackProccedJob.php
文件以处理交易过程
并打开 app > Jobs > IPNHandlerCoinPaymentJob.php
文件以处理 IPN 过程