Files
erahn-click/app/Http/Requests/PaymentRequest.php
T
2024-08-05 15:44:52 +08:00

66 lines
2.0 KiB
PHP

<?php
namespace App\Http\Requests;
use App\Http\Controllers\InformationController;
use App\Rules\PaymentRules\CawanganPermitUjrahPayment;
use App\Rules\PaymentRules\NorujukanBukanFasa2;
use App\Rules\PaymentRules\NorujukanContractNotExceed12Month;
use App\Rules\PaymentRules\NorujukanNotAttemptPaymentRecently;
use App\Rules\PaymentRules\NorujukanTidakAkanDilelong;
use App\Rules\PaymentRules\PaymentNotUjrah;
use App\Rules\PaymentRules\PilihMinimumSatuSAG;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Http;
class PaymentRequest extends FormRequest
{
public $selectedPembiayaan;
public $pembiayaanAkanDilelong;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$this->selectedPembiayaan = $this->getPembiayaanFromNorujukan();
$this->pembiayaanAkanDilelong = $this->getPembiayaanAkanDilelong();
return [
'totalSagInCartInput' => [
new PilihMinimumSatuSAG,
new NorujukanTidakAkanDilelong($this->pembiayaanAkanDilelong),
new NorujukanBukanFasa2($this->pembiayaanAkanDilelong),
new NorujukanNotAttemptPaymentRecently,
new CawanganPermitUjrahPayment($this->selectedPembiayaan),
// new PaymentNotUjrah($this->selectedPembiayaan),
new NorujukanContractNotExceed12Month($this->selectedPembiayaan),
]
];
}
public function getPembiayaanFromNorujukan()
{
$norujukanList = json_decode($this->totalSagInCartInput);
return array_map(fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x)->json()[0][0], $norujukanList);
}
public function getPembiayaanAkanDilelong()
{
return (new InformationController())->pembiayaanakandilelong()->getData();
}
}