DONE: drop table shoraka financings, and improve UI checking on shoraka order status

This commit is contained in:
2026-10-26 15:01:56 +08:00
parent 9aee720bd0
commit 347d99d8bd
11 changed files with 157 additions and 380 deletions
+9 -5
View File
@@ -286,8 +286,12 @@ class GadaianController extends Controller
{
$auth_user = Auth::user();
$shoraka = app(\App\Services\ShorakaFinancingService::class);
if ($shoraka->local($request->norujukan_gadai)) {
return $shoraka->pendingResponse($request, $request->norujukan_gadai);
if ($shoraka->hasOrder($request->norujukan_gadai)) {
$message = 'Order Shoraka telah dihantar. Jangan hantar semula.';
if ($request->ajax() || $request->expectsJson()) {
abort(409, $message);
}
return redirect()->back()->with('error', $message);
}
$shoraka->ensureReady();
$caraTerima = strtoupper((string) $request->input('cara_terima', 'TUNAI'));
@@ -398,9 +402,9 @@ class GadaianController extends Controller
$request->session()->forget('norujukan');
$request->session()->forget('borang_online_printed');
$request->session()->flash('activate_tab', 'SAG_baru');
if ($caraTerima === 'ONLINE') {
$request->session()->flash('message', 'Gadai berjaya. Pembiayaan online menunggu semakan PC.');
}
$request->session()->flash('message', $caraTerima === 'ONLINE'
? 'Gadai berjaya. Pembiayaan online menunggu semakan PC.'
: 'Pembiayaan berjaya dihantar.');
return redirect()->route('customer_info');
}
+3 -89
View File
@@ -23,7 +23,7 @@ class ShorakaController extends Controller
$filters = $request->validate([
'kodcaw' => 'nullable|string|max:30',
'norujukan' => 'nullable|string|max:100',
'state' => 'nullable|in:WAITING,PROCESSING,REVIEW,DONE',
'status' => 'nullable|in:PENDING,Active,Completed,Cancelled,UNKNOWN,FAILED',
'date_from' => 'nullable|date_format:Y-m-d',
'date_to' => 'nullable|date_format:Y-m-d' . ($request->filled('date_from') ? '|after_or_equal:date_from' : ''),
]);
@@ -43,101 +43,15 @@ class ShorakaController extends Controller
public function show(string $norujukan, ShorakaFinancingService $service)
{
$record = $service->local($norujukan);
$data = null;
$error = null;
try {
$data = $service->api()->get($service->url($norujukan))->throw()->json()['data'];
$data = $service->snapshot($norujukan);
} catch (Throwable $exception) {
$error = 'Maklumat Shoraka tidak dapat diambil. Bayaran dan SAG masih ditahan.';
}
$cawangan_info = ['details_caw' => Auth::user()->cawangan, 'kodcaw' => Auth::user()->cawangan];
return view('shoraka.show', compact('norujukan', 'record', 'data', 'error', 'cawangan_info'));
}
public function poll(Request $request, string $norujukan, ShorakaFinancingService $service)
{
$record = $service->local($norujukan);
abort_unless($record && ($record['teller'] ?? null) === Auth::user()->name && ($record['action'] ?? null) === 'gadai', 403);
if (($record['state'] ?? null) === 'DONE') {
return response()->json(['state' => 'done', 'redirect' => route('customer_info')]);
}
abort_unless(!empty($record['context']['temporary_gadai']), 409);
if (($record['state'] ?? null) === 'REVIEW') {
return response()->json(['state' => 'failed', 'message' => 'Penyelesaian memerlukan semakan operasi. Jangan ulang bayaran.']);
}
if (($record['state'] ?? null) === 'PROCESSING') {
return response()->json(['state' => 'pending']);
}
try {
$data = $service->api()->get($service->url($norujukan))->throw()->json()['data'];
$order = $data['order'] ?? null;
if ($order && !empty($order['order_id']) && ($order['status'] ?? '') !== 'Cancelled') {
$service->api()->post($service->url($norujukan, '/refresh'))->throw();
$data = $service->api()->get($service->url($norujukan))->throw()->json()['data'];
$order = $data['order'] ?? null;
}
$status = $order['status'] ?? null;
if (in_array($status, ['Cancelled', 'FAILED', 'UNKNOWN'], true) || !$order) {
return response()->json(['state' => 'failed', 'message' => !empty($data['simulation'])
? 'Simulasi gagal berjaya diuji. Tiada gadaian atau marhun disimpan dan tiada bayaran diproses.'
: 'Transaksi gagal atau hasil penghantaran belum dapat dipastikan. Hubungi operasi; jangan hantar semula.']);
}
if (!empty($data['can_complete'])) {
if ($request->input('progress') === 'check') {
return response()->json(['state' => 'ready']);
}
$result = $service->finish($request, $norujukan);
return response()->json(['state' => 'done', 'redirect' => $result->getTargetUrl()]);
}
if ($status === 'Completed') {
return response()->json(['state' => 'failed', 'message' => 'Komoditi selesai tetapi maklumat gadaian belum dapat disahkan. Hubungi operasi.']);
}
return response()->json(['state' => 'pending']);
} catch (Throwable $exception) {
$fresh = $service->local($norujukan);
if ($fresh && ($fresh['state'] ?? null) === 'REVIEW') {
return response()->json(['state' => 'failed', 'message' => 'Penyelesaian memerlukan semakan operasi. Jangan ulang bayaran.']);
}
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
&& $exception->getStatusCode() >= 400 && $exception->getStatusCode() < 500) {
return response()->json(['state' => 'failed', 'message' => $exception->getMessage()]);
}
if ($exception instanceof \Illuminate\Http\Client\RequestException
&& in_array($exception->response->status(), [404, 409], true)) {
return response()->json(['state' => 'failed', 'message' => 'Maklumat transaksi tidak dapat disahkan. Hubungi operasi; jangan hantar semula.']);
}
// Connection loss is not proof of a failed commodity trade.
return response()->json(['state' => 'pending']);
}
}
public function submit(string $norujukan, ShorakaFinancingService $service)
{
$record = $service->local($norujukan);
abort_unless($record && ($record['teller'] ?? null) === Auth::user()->name, 403);
$response = $service->api()->post($service->url($norujukan, '/submit'));
return redirect()->route('shoraka.show', compact('norujukan'))
->with('shoraka_message', $response->successful()
? 'Order dihantar. Semak status sebelum menyelesaikan pembiayaan.'
: (($response->json()['message'] ?? null) ?: 'Order belum berjaya. Semak status sebelum cuba semula.'));
}
public function refresh(string $norujukan, ShorakaFinancingService $service)
{
try {
$response = $service->api()->post($service->url($norujukan, '/refresh'));
$message = $response->successful() ? 'Status dikemas kini.'
: (($response->json()['message'] ?? null) ?: 'Status tidak dapat dikemas kini.');
} catch (Throwable $exception) {
$message = 'Sambungan terganggu. Jangan hantar order semula.';
}
return redirect()->route('shoraka.show', compact('norujukan'))->with('shoraka_message', $message);
}
public function finish(Request $request, string $norujukan, ShorakaFinancingService $service)
{
return $service->finish($request, $norujukan);
return view('shoraka.show', compact('norujukan', 'data', 'error', 'cawangan_info'));
}
public function certificate(string $norujukan, ShorakaFinancingService $service)