mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 23:19:05 +00:00
1. 优化支付文件框架为后续大改做准备; 2. 重构了支付宝面对面支付; - 本次重构解决了PHP版本>7.3 导致该支付无法使用的问题; - 自行开发的接入方式,简化&快捷化了代码; 3. 修正 Stripe 汇率API 查询的代码 & 部分报错代码; TODO: 1. 汇率查询API 应该集中统一化(Paypal & Stripe 都需要汇率转换); 2. 简化支付对接成本(单文件自动对接);
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace App\Payments;
|
||
|
||
use App\Payments\Library\Gateway;
|
||
use Auth;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Log;
|
||
use Response;
|
||
use Xhat\Payjs\Payjs as Pay;
|
||
|
||
class PayJs extends Gateway
|
||
{
|
||
private static $config;
|
||
|
||
public function __construct()
|
||
{
|
||
self::$config = [
|
||
'mchid' => sysConfig('payjs_mch_id'), // 配置商户号
|
||
'key' => sysConfig('payjs_key'), // 配置通信密钥
|
||
];
|
||
}
|
||
|
||
public function purchase($request): JsonResponse
|
||
{
|
||
$payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
|
||
|
||
$result = (new Pay($this::$config))->cashier([
|
||
'body' => sysConfig('subject_name') ?: sysConfig('website_name'),
|
||
'total_fee' => $payment->amount * 100,
|
||
'out_trade_no' => $payment->trade_no,
|
||
'notify_url' => route('payment.notify', ['method' => 'payjs']),
|
||
]);
|
||
|
||
// 获取收款二维码内容
|
||
$payment->update(['qr_code' => 1, 'url' => $result]);
|
||
|
||
//$this->addPamentCallback($payment->trade_no, null, $payment->amount * 100);
|
||
return Response::json(['status' => 'success', 'data' => $payment->trade_no, 'message' => '创建订单成功!']);
|
||
}
|
||
|
||
public function notify($request): void
|
||
{
|
||
$data = (new Pay($this::$config))->notify();
|
||
|
||
if ($data['return_code'] == 1) {
|
||
if ($this->paymentReceived($data['out_trade_no'])) {
|
||
exit('success');
|
||
}
|
||
} else {
|
||
Log::error('【PayJs】交易失败:'.var_export($data, true));
|
||
}
|
||
exit('fail');
|
||
}
|
||
}
|