74 lines
3.2 KiB
PHP
74 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\KomuditiTransaksi;
|
|
use App\Services\ShorakaGadaiService;
|
|
use App\Services\ShorakaService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ShorakaGadaiController extends ShorakaController
|
|
{
|
|
public function readiness(ShorakaService $shoraka)
|
|
{
|
|
return response()->json(['provider' => 'shoraka', 'ready' => $shoraka->configured()]);
|
|
}
|
|
|
|
public function showGadai(string $kodcaw, string $norujukan, ShorakaGadaiService $gadaiService)
|
|
{
|
|
$gadai = $gadaiService->gadai($kodcaw, $norujukan);
|
|
$order = $gadaiService->transaction($kodcaw, $norujukan);
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => [
|
|
'norujukan' => $norujukan, 'kodcaw' => $kodcaw,
|
|
'order_amount' => $gadai->pinjaman, 'murabaha_amount' => $gadai->hargajualan,
|
|
'order' => $order ? $this->orderData($order) : null,
|
|
'details' => $order ? $order->response_payload : null,
|
|
'simulation' => $order && strpos((string) $order->order_id, 'SIM-') === 0,
|
|
'can_complete' => $gadai->exists && $order && $order->status === 'Completed'
|
|
&& number_format((float) $gadai->pinjaman, 2, '.', '') === $order->order_amount
|
|
&& number_format((float) $gadai->hargajualan, 2, '.', '') === $order->murabaha_amount,
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function submitGadai(string $kodcaw, string $norujukan, ShorakaGadaiService $gadaiService, ShorakaService $shoraka)
|
|
{
|
|
$gadai = $gadaiService->gadai($kodcaw, $norujukan);
|
|
$existing = $gadaiService->transaction($kodcaw, $norujukan);
|
|
if ($existing) {
|
|
return $this->duplicate($existing);
|
|
}
|
|
// Historical commodity purchases must never be traded again.
|
|
if (KomuditiTransaksi::on('mysql7')->where('norujukan', $norujukan)->exists()
|
|
|| $gadai->cetak || $gadai->sttebus) {
|
|
abort(409, 'Gadaian lama atau telah selesai tidak boleh dihantar sebagai order baharu.');
|
|
}
|
|
$temporary = app(\App\Services\ShorakaNewGadaiService::class)->pending($kodcaw, $norujukan);
|
|
if ($temporary && $gadai->exists) {
|
|
abort(409, 'Rujukan sementara bertindih dengan gadaian sedia ada. Semakan operasi diperlukan.');
|
|
}
|
|
if ($temporary && !$temporary['prepared']) {
|
|
abort(409, 'Sila sahkan semula amaun gadaian selepas perubahan marhun.');
|
|
}
|
|
$request = new Request($gadaiService->payload($gadai));
|
|
$request->attributes->set('shoraka_kodcaw', $kodcaw);
|
|
$request->attributes->set('shoraka_new', !$gadai->exists);
|
|
return $this->submit($request, $shoraka);
|
|
}
|
|
|
|
public function refreshGadai(string $kodcaw, string $norujukan, ShorakaGadaiService $gadaiService, ShorakaService $shoraka)
|
|
{
|
|
$gadaiService->gadai($kodcaw, $norujukan);
|
|
$gadaiService->transaction($kodcaw, $norujukan);
|
|
return $this->refresh($norujukan, $shoraka);
|
|
}
|
|
|
|
public function certificateGadai(string $kodcaw, string $norujukan, ShorakaGadaiService $gadaiService, ShorakaService $shoraka)
|
|
{
|
|
$gadaiService->assertCompleted($kodcaw, $norujukan);
|
|
return $this->certificate($norujukan, $shoraka);
|
|
}
|
|
}
|