Files
ProxyPanel/app/Payments/CodePay.php
BrettonYe 0751b40f0a 优化/重构 支付相关代码
1. 优化支付文件框架为后续大改做准备;
2. 重构了支付宝面对面支付;
   - 本次重构解决了PHP版本>7.3 导致该支付无法使用的问题;
   - 自行开发的接入方式,简化&快捷化了代码;
3. 修正 Stripe 汇率API 查询的代码 & 部分报错代码;

TODO:
1. 汇率查询API 应该集中统一化(Paypal & Stripe 都需要汇率转换);
2. 简化支付对接成本(单文件自动对接);
2022-12-30 11:40:57 +08:00

51 lines
1.7 KiB
PHP

<?php
namespace App\Payments;
use App\Payments\Library\Gateway;
use Auth;
use Illuminate\Http\JsonResponse;
use Log;
use Response;
class CodePay extends Gateway
{
public function purchase($request): JsonResponse
{
$payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
$data = [
'id' => sysConfig('codepay_id'),
'pay_id' => $payment->trade_no,
'type' => $request->input('type'), //1支付宝支付 2QQ钱包 3微信支付
'price' => $payment->amount,
'page' => 1,
'outTime' => 900,
'notify_url' => route('payment.notify', ['method' => 'codepay']),
'return_url' => route('invoice'),
];
$data['sign'] = $this->aliStyleSign($data, sysConfig('codepay_key'));
$url = sysConfig('codepay_url').http_build_query($data);
$payment->update(['url' => $url]);
return Response::json(['status' => 'success', 'url' => $url, 'message' => '创建订单成功!']);
}
public function notify($request): void
{
$tradeNo = $request->input('pay_id');
if ($tradeNo && $request->input('pay_no')
&& $this->verify($request->except('method'), sysConfig('codepay_key'), $request->input('sign'), false)) {
if ($this->paymentReceived($tradeNo)) {
exit('success');
}
Log::error('【码支付】验签失败:'.var_export($request->all(), true));
} else {
Log::error('【码支付】交易失败:'.var_export($request->all(), true));
}
exit('fail');
}
}