PHP code example of runner / nezha-cashier
1. Go to this page and download the library: Download runner/nezha-cashier library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
runner / nezha-cashier example snippets
use Runner\NezhaCashier\Cashier;
// 按格式组装好配置
$config = [
'app_id' => 'xxxx',
'app_private_key' => 'xxxxx',
'alipay_public_key' => 'xxxxx',
];
// 创建实例, 传入要使用的 Gateway
$cashier = new Cashier('alipay_web', $config);
// 组装 ChargeRequestForm
$data = [
'order_id' => '151627101400000071',
'subject' => 'testing',
'amount' => 1,
'currency' => 'CNY',
'description' => 'testing description',
'return_url' => 'https://www.baidu.com',
'expired_at' => '2018-01-23 19:00:00',
];
$form = $cashier->charge($data);
// 以 laravel 为例
return redirect($form->get('charge_url'));
$form = $cashier->query([
'order_id' => '151627101400000071',
]);
var_dump('paid' === $form->get('status'));
$form = $cashier->notify('charge');
var_dump('paid' === $form->get('status'));
var_dump($form->get('trade_sn')); // 取得第三方交易号
$form = $cashier->refund([
'order_id' => '151627101400000071',
'refund_id' => '3151627101400000071',
'total_amount' => 1,
'refund_amount' => 1,
]);