Files
Xboard/app/Http/Controllers/V1/Guest/PaymentController.php
xboard 58868268dd feat: enhance plugin management
- Add command support for plugin management
- Optimize plugin management page layout
- Add email copy functionality for users
- Convert payment methods and Telegram Bot to plugin system
2025-07-26 18:49:58 +08:00

53 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers\V1\Guest;
use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Services\OrderService;
use App\Services\PaymentService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use App\Services\Plugin\HookManager;
class PaymentController extends Controller
{
public function notify($method, $uuid, Request $request)
{
HookManager::call('payment.notify.before', [$method, $uuid, $request]);
try {
$paymentService = new PaymentService($method, null, $uuid);
$verify = $paymentService->notify($request->input());
if (!$verify) {
HookManager::call('payment.notify.failed', [$method, $uuid, $request]);
return $this->fail([422, 'verify error']);
}
HookManager::call('payment.notify.verified', $verify);
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
return $this->fail([400, 'handle error']);
}
return (isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
} catch (\Exception $e) {
Log::error($e);
return $this->fail([500, 'fail']);
}
}
private function handle($tradeNo, $callbackNo)
{
$order = Order::where('trade_no', $tradeNo)->first();
if (!$order) {
return $this->fail([400202, 'order is not found']);
}
if ($order->status !== Order::STATUS_PENDING)
return true;
$orderService = new OrderService($order);
if (!$orderService->paid($callbackNo)) {
return false;
}
HookManager::call('payment.notify.success', $order);
return true;
}
}