Manual.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Utils\Payments;
  3. use App\Models\Payment;
  4. use App\Services\PaymentService;
  5. use App\Utils\Library\Templates\Gateway;
  6. use Auth;
  7. use Hashids\Hashids;
  8. use Illuminate\Contracts\View\View;
  9. use Illuminate\Http\JsonResponse;
  10. use Illuminate\Http\Request;
  11. use Response;
  12. class Manual extends PaymentService implements Gateway
  13. {
  14. public function purchase(Request $request): JsonResponse
  15. {
  16. $payment = $this->createPayment(Auth::id(), $request->input('id'), $request->input('amount'));
  17. $url = route('manual.checkout', ['payment' => $payment->trade_no]);
  18. $payment->update(['url' => $url]);
  19. return Response::json(['status' => 'success', 'url' => $url, 'message' => '创建订单成功!']);
  20. }
  21. public function redirectPage(string $trade_no): View
  22. {
  23. $payment = Payment::uid()->with(['order', 'order.goods'])->whereTradeNo($trade_no)->firstOrFail();
  24. $goods = $payment->order->goods;
  25. return view('user.components.payment.manual', [
  26. 'payment' => $payment,
  27. 'name' => $goods->name ?? trans('user.recharge_credit'),
  28. 'days' => $goods->days ?? 0,
  29. 'pay_type' => $payment->order->pay_type_label ?: 0,
  30. 'pay_type_icon' => $payment->order->pay_type_icon,
  31. ]);
  32. }
  33. public function inform(string $trade_no): JsonResponse
  34. {
  35. $payment = Payment::uid()->with(['order'])->whereTradeNo($trade_no)->firstOrFail();
  36. $payment->order->update(['status' => 1]);
  37. return Response::json(['status' => 'success', 'message' => '我们将在【24小时】内对购买/充值的款项进行开通!请耐心等待']);
  38. }
  39. public function notify(Request $request)
  40. {
  41. $code = $request->input('sign');
  42. $status = $request->input('status');
  43. if (isset($status, $code)) {
  44. $payment_info = (new Hashids(config('app.key'), 8))->decode($code);
  45. if ($payment_info) {
  46. $payment = Payment::findOrFail($payment_info[0]);
  47. if ($payment && $payment->order && $payment->order->status === 1) {
  48. if ($status) {
  49. $this->paymentReceived($payment->trade_no);
  50. } else {
  51. $payment->order->close();
  52. }
  53. }
  54. return view('components.payment.detail', ['order' => $payment->order->refresh(), 'user' => $payment->user->refresh()]);
  55. }
  56. }
  57. return view('auth.error', ['message' => 'No enough information']);
  58. }
  59. }