This commit is contained in:
2023-03-08 09:16:04 +08:00
commit e78454540f
1318 changed files with 210569 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<?php
namespace Modules\Payment\Http\Controllers\Api;
use App\Api\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Modules\Payment\Models\Setting;
class GatewayController extends Controller
{
/**
* Notes : 获取支持的支付渠道
*
* @Date : 2021/8/26 3:50 下午
* @Author : <Jason.C>
* @return \Illuminate\Http\JsonResponse
*/
public function index(): JsonResponse
{
$setting = Setting::orderByDesc('in_use')->first();
return $this->success([
'alipay' => (bool) $setting->alipay_id,
'wechat' => (bool) $setting->wechat_id,
]);
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Modules\Payment\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Modules\Payment\Facades\Pay;
use Modules\Payment\Models\Payment;
class NotifyController extends Controller
{
protected Payment $payment;
public function alipay()
{
$alipay = Pay::alipay();
if (config('payment.version', 2) == 2) {
$data = $alipay->verify();
} else {
$data = $alipay->callback();
}
$this->getPaymentByTradeNo($data->out_trade_no);
//设置支付完成
if ($this->payment) {
$this->payment->paid();
$this->payment->order->pay();
}
return $alipay->success();
}
public function wechat()
{
$wechat = Pay::wechat();
if (config('payment.version', 2) == 2) {
$data = $wechat->verify();
$this->getPaymentByTradeNo($data->out_trade_no);
} else {
$data = $wechat->callback();
$this->getPaymentByTradeNo($data->resource['ciphertext']['out_trade_no']);
}
//设置支付完成
if ($this->payment) {
$this->payment->paid();
$this->payment->order->pay();
}
return $wechat->success();
}
public function getPaymentByTradeNo($tradeNo)
{
$this->payment = Payment::where('trade_id', $tradeNo)->first();
}
}