mirror of
https://github.com/v2board/v2board.git
synced 2025-06-14 21:57:50 +08:00
rewrite: payment
This commit is contained in:
@ -4,8 +4,10 @@ namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\OrderSave;
|
||||
use App\Models\Payment;
|
||||
use App\Services\CouponService;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\PaymentService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
@ -175,71 +177,20 @@ class OrderController extends Controller
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
switch ($method) {
|
||||
// return type => 0: QRCode / 1: URL / 2: No action
|
||||
case 0:
|
||||
// alipayF2F
|
||||
if (!(int)config('v2board.alipay_enable')) {
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
return response([
|
||||
'type' => 0,
|
||||
'data' => $this->alipayF2F($tradeNo, $order->total_amount)
|
||||
]);
|
||||
case 2:
|
||||
// stripeAlipay
|
||||
if (!(int)config('v2board.stripe_alipay_enable')) {
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->stripeAlipay($order)
|
||||
]);
|
||||
case 3:
|
||||
// stripeWepay
|
||||
if (!(int)config('v2board.stripe_wepay_enable')) {
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
return response([
|
||||
'type' => 0,
|
||||
'data' => $this->stripeWepay($order)
|
||||
]);
|
||||
case 4:
|
||||
// bitpayX
|
||||
if (!(int)config('v2board.bitpayx_enable')) {
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->bitpayX($order)
|
||||
]);
|
||||
case 5:
|
||||
if (!(int)config('v2board.mgate_enable')) {
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->mgate($order)
|
||||
]);
|
||||
case 6:
|
||||
if (!(int)config('v2board.stripe_card_enable')) {
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
return response([
|
||||
'type' => 2,
|
||||
'data' => $this->stripeCard($order, $request->input('token'))
|
||||
]);
|
||||
case 7:
|
||||
if (!(int)config('v2board.epay_enable')) {
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->epay($order)
|
||||
]);
|
||||
default:
|
||||
abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
}
|
||||
$payment = Payment::find($method);
|
||||
if (!$payment || $payment->enable !== 1) abort(500, __('user.order.checkout.pay_method_not_use'));
|
||||
$paymentService = new PaymentService($payment->payment, $payment->id);
|
||||
$result = $paymentService->pay([
|
||||
'trade_no' => $tradeNo,
|
||||
'total_amount' => $order->total_amount,
|
||||
'user_id' => $order->user_id,
|
||||
'stripe_token' => $request->input('token')
|
||||
]);
|
||||
$order->update(['payment_id' => $method]);
|
||||
return response([
|
||||
'type' => $result['type'],
|
||||
'data' => $result['data']
|
||||
]);
|
||||
}
|
||||
|
||||
public function check(Request $request)
|
||||
@ -258,65 +209,15 @@ class OrderController extends Controller
|
||||
|
||||
public function getPaymentMethod()
|
||||
{
|
||||
$data = [];
|
||||
if ((int)config('v2board.alipay_enable')) {
|
||||
$alipayF2F = new \StdClass();
|
||||
$alipayF2F->name = '支付宝';
|
||||
$alipayF2F->method = 0;
|
||||
$alipayF2F->icon = 'alipay';
|
||||
array_push($data, $alipayF2F);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_alipay_enable')) {
|
||||
$stripeAlipay = new \StdClass();
|
||||
$stripeAlipay->name = '支付宝';
|
||||
$stripeAlipay->method = 2;
|
||||
$stripeAlipay->icon = 'alipay';
|
||||
array_push($data, $stripeAlipay);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_wepay_enable')) {
|
||||
$stripeWepay = new \StdClass();
|
||||
$stripeWepay->name = '微信';
|
||||
$stripeWepay->method = 3;
|
||||
$stripeWepay->icon = 'wechat';
|
||||
array_push($data, $stripeWepay);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.bitpayx_enable')) {
|
||||
$bitpayX = new \StdClass();
|
||||
$bitpayX->name = config('v2board.bitpayx_name', '在线支付');
|
||||
$bitpayX->method = 4;
|
||||
$bitpayX->icon = 'wallet';
|
||||
array_push($data, $bitpayX);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.mgate_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = config('v2board.mgate_name', '在线支付');
|
||||
$obj->method = 5;
|
||||
$obj->icon = 'wallet';
|
||||
array_push($data, $obj);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_card_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = '信用卡';
|
||||
$obj->method = 6;
|
||||
$obj->icon = 'card';
|
||||
array_push($data, $obj);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.epay_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = config('v2board.epay_name', '在线支付');
|
||||
$obj->method = 7;
|
||||
$obj->icon = 'wallet';
|
||||
array_push($data, $obj);
|
||||
}
|
||||
$methods = Payment::select([
|
||||
'id',
|
||||
'name',
|
||||
'payment'
|
||||
])
|
||||
->where('enable', 1)->get();
|
||||
|
||||
return response([
|
||||
'data' => $data
|
||||
'data' => $methods
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user