This commit is contained in:
tokumeikoi 2021-05-07 01:17:55 +09:00
parent b3b0988730
commit dc6317db97
6 changed files with 15 additions and 7 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;
use App\Services\PaymentService;
use App\Utils\Helper;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Payment;
@ -56,7 +57,8 @@ class PaymentController extends Controller
if (!Payment::create([
'name' => $request->input('name'),
'payment' => $request->input('payment'),
'config' => $request->input('config')
'config' => $request->input('config'),
'uuid' => Helper::guid()
])) {
abort(500, '保存失败');
}

View File

@ -11,10 +11,10 @@ use App\Http\Controllers\Controller;
class PaymentController extends Controller
{
public function notify($method, $id, Request $request)
public function notify($method, $uuid, Request $request)
{
try {
$paymentService = new PaymentService($method, $id);
$paymentService = new PaymentService($method, null, $uuid);
$verify = $paymentService->notify($request->input());
if (!$verify) abort(500, 'verify error');
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {

View File

@ -21,7 +21,7 @@ class GuestRoute
// Telegram
$router->post('/telegram/webhook', 'Guest\\TelegramController@webhook');
// Payment
$router->match(['get', 'post'], '/payment/notify/{method}/{id}', 'Guest\\PaymentController@notify');
$router->match(['get', 'post'], '/payment/notify/{method}/{uuid}', 'Guest\\PaymentController@notify');
// Comm
$router->get ('/comm/config', 'Guest\\CommController@config');
});

View File

@ -7,17 +7,19 @@ use App\Models\Payment;
class PaymentService
{
public function __construct($method, $id = NULL)
public function __construct($method, $id = NULL, $uuid = NULL)
{
$this->method = $method;
$this->class = '\\App\\Payments\\' . $this->method;
if (!class_exists($this->class)) abort(500, 'gate is not found');
if ($id) $payment = Payment::find($id)->toArray();
if ($uuid) $payment = Payment::where('uuid', $uuid)->first()->toArray();
$this->config = [];
if (isset($payment)) {
$this->config = json_decode($payment['config'], true);
$this->config['enable'] = $payment['enable'];
$this->config['id'] = $payment['id'];
$this->config['uuid'] = $payment['uuid'];
};
$this->payment = new $this->class($this->config);
}
@ -31,7 +33,7 @@ class PaymentService
public function pay($order)
{
return $this->payment->pay([
'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['id']}"),
'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"),
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'],
'trade_no' => $order['trade_no'],
'total_amount' => $order['total_amount'],

View File

@ -119,6 +119,7 @@ CREATE TABLE `v2_order` (
DROP TABLE IF EXISTS `v2_payment`;
CREATE TABLE `v2_payment` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uuid` char(32) NOT NULL,
`payment` varchar(16) NOT NULL,
`name` varchar(255) NOT NULL,
`config` text NOT NULL,
@ -346,4 +347,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2021-04-28 08:53:45
-- 2021-05-06 16:14:04

View File

@ -408,3 +408,6 @@ CREATE TABLE `v2_payment` (
ALTER TABLE `v2_order`
ADD `payment_id` int(11) NULL AFTER `coupon_id`;
ALTER TABLE `v2_payment`
ADD `uuid` char(32) NOT NULL AFTER `id`;