File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/app/Controllers/PaymentController.php
Back
<?php /** * PaymentController * Customer-facing payment actions: show payment page, submit slip, cancel */ require_once __DIR__ . '/../Core/Controller.php'; require_once __DIR__ . '/../Services/PaymentService.php'; require_once __DIR__ . '/../Services/OrderService.php'; require_once __DIR__ . '/../Helpers/Auth.php'; require_once __DIR__ . '/../Helpers/Session.php'; require_once __DIR__ . '/../Helpers/Url.php'; class PaymentController extends Controller { private PaymentService $paymentService; public function __construct() { $this->paymentService = new PaymentService(); } /** * GET /payment/{order_no} * Show the payment page for a given order */ public function show(string $orderNo): void { $userId = Auth::id(); $payment = $this->paymentService->getPaymentByOrderNo($orderNo, $userId); if (!$payment) { Session::setFlash('danger', 'ไม่พบรายการชำระเงินนี้'); $this->redirect('/account/orders'); } // If already confirmed or cancelled — redirect to appropriate page if (in_array($payment['payment_status'], ['confirmed', 'refunded'], true)) { $this->redirect('/payment/' . $orderNo . '/success'); } if (in_array($payment['payment_status'], ['cancelled', 'expired'], true)) { Session::setFlash('warning', 'รายการชำระเงินนี้ถูกยกเลิกหรือหมดอายุแล้ว'); $this->redirect('/account/orders'); } $this->render('payment/show', [ 'payment' => $payment, 'orderNo' => $orderNo, 'pageTitle' => 'ชำระเงิน #' . $orderNo . ' - CARGOO', ], 'main'); } /** * POST /payment/submit-slip * Customer uploads a payment slip */ public function submitSlip(): void { $userId = Auth::id(); $orderNo = trim($_POST['order_no'] ?? ''); $note = trim($_POST['note'] ?? ''); $file = $_FILES['slip_image'] ?? null; if (!$orderNo) { $this->json(['success' => false, 'message' => 'ข้อมูลไม่ครบถ้วน'], 422); } if (!$file) { $this->json(['success' => false, 'message' => 'กรุณาเลือกไฟล์สลิปการโอนเงิน'], 422); } $result = $this->paymentService->submitSlip($userId, $orderNo, $file, $note ?: null); if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { $this->json($result, $result['success'] ? 200 : 422); } if ($result['success']) { Session::setFlash('success', $result['message']); } else { Session::setFlash('danger', $result['message']); } $this->redirect('/payment/' . $orderNo); } /** * POST /payment/cancel * Customer cancels a pending payment */ public function cancel(): void { $userId = Auth::id(); $paymentId = (int)($_POST['payment_id'] ?? 0); if (!$paymentId) { Session::setFlash('danger', 'ข้อมูลไม่ถูกต้อง'); $this->redirect('/account/orders'); } $result = $this->paymentService->cancelPayment($paymentId, $userId); if ($result['success']) { Session::setFlash('success', $result['message']); } else { Session::setFlash('danger', $result['message']); } $this->redirect('/account/orders'); } /** * GET /payment/{order_no}/success * Payment confirmation / success page */ public function success(string $orderNo): void { $userId = Auth::id(); $payment = $this->paymentService->getPaymentByOrderNo($orderNo, $userId); if (!$payment) { Session::setFlash('danger', 'ไม่พบรายการชำระเงินนี้'); $this->redirect('/account/orders'); } $this->render('payment/success', [ 'payment' => $payment, 'orderNo' => $orderNo, 'pageTitle' => 'ชำระเงินสำเร็จ #' . $orderNo . ' - CARGOO', ], 'main'); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings