Add api initializeCdmPayment

This commit is contained in:
Amir
2023-01-24 16:29:57 +08:00
parent c0f07de80c
commit daad4a64d5
2 changed files with 92 additions and 26 deletions
@@ -634,23 +634,30 @@ class LelongMobileController extends Controller
})
->first();
if ($payment != null) {
if ($payment->status == 2) {
$checkPayMethod = Resit::find($payment->resit_id);
$date_convert = strtotime($checkPayMethod->created_at);
$checkPayMethod['pay_time'] = date("H:i:s", $date_convert);
$status_payment_cawangan['resit'] = $checkPayMethod->toArray();
if ($checkPayMethod->billplz_id == "") {
$status_payment_cawangan['payment_method'] = "TUNAI";
$status_payment_cawangan['payment_method_opt'] = 1;
} elseif (str_starts_with($checkPayMethod->billplz_id, 'CDM')) {
$status_payment_cawangan['payment_method'] = "CDM";
$status_payment_cawangan['payment_method_opt'] = 3;
} else {
$status_payment_cawangan['payment_method'] = "ONLINE";
$status_payment_cawangan['payment_method_opt'] = 2;
$checkPayMethod = Resit::find($payment->resit_id);
$date_convert = strtotime($checkPayMethod->created_at);
$checkPayMethod['pay_time'] = date("H:i:s", $date_convert);
$status_payment_cawangan['resit'] = $checkPayMethod->toArray();
if ($checkPayMethod->billplz_id == "") {
$status_payment_cawangan['payment_method'] = "TUNAI";
$status_payment_cawangan['payment_method_opt'] = 1;
} elseif (str_starts_with($checkPayMethod->billplz_id, 'CDM')) {
$status_payment_cawangan['payment_method'] = "CDM";
$status_payment_cawangan['payment_method_opt'] = 3;
$file_resit = FileResit::where('user_id', $user_id)->where('lelong_id', $lelong_id)->where('kodcaw', $kodCawangan)->get();
foreach($file_resit as $index => $resit)
{
$date_convert = strtotime($resit->created_at);
$updatedDateTime = date("H:i:s", $date_convert);
$file_resit[$index]['masa_upload'] = $updatedDateTime;
}
$status_payment_cawangan['file_resit'] = $file_resit;
} else {
$status_payment_cawangan['status'] = 9; // status pending tunggu pengesahan
$status_payment_cawangan['payment_method'] = "ONLINE";
$status_payment_cawangan['payment_method_opt'] = 2;
}
if ($payment->disahkan_pada == NULL) {
$status_payment_cawangan['status'] = 9; // status pending tunggu pengesahan
}
} else {
$status_payment_cawangan['status'] = null;
@@ -1295,6 +1302,7 @@ class LelongMobileController extends Controller
$addfile->user_id = $request->user_id;
$addfile->lelong_id = $request->lelong_id;
$addfile->file_type = $file_type;
$addfile->kodcaw = $request->kodcaw;
$addfile->save();
$directory = "/{$request->user_id}/{$request->lelong_id}/";
@@ -1306,16 +1314,11 @@ class LelongMobileController extends Controller
$stored_path = Storage::disk('resit')->path("{$directory}{$resitImageFileName}.${imageExtension}");
$resitPhotoService = new ResitPhotoService();
// try {
$convertToWebP = $resitPhotoService->optimizeImageToWebP($stored_path, $directory, $resitImageFileName);
// } catch (\Exception $e)
// {
// return $e;
// }
try {
$convertToWebP = $resitPhotoService->optimizeImageToWebP($stored_path, $directory, $resitImageFileName);
} catch (\Exception $e) {
return $e;
}
Storage::disk('resit')->delete("{$directory}${resitImageFileName}.${imageExtension}");
@@ -1360,4 +1363,65 @@ class LelongMobileController extends Controller
return response()->json(['lelong' => $lelong]);
}
public function initializeCdmPayment(Request $request)
{
$current = Carbon::now();
$current = new Carbon();
$day = $current->day;
$month = $current->month;
$year = $current->format('y');
$this->addPhotoResit($request);
$previous_siri = Resit::orderBy('id','desc')->first();
if($previous_siri){
$nosiri = $previous_siri->id + 1;
}else{
$nosiri = 1;
}
$reference_no = 'LPKB' . $day . $month . $year . sprintf("%08d", $nosiri);
$cdm_reference = 'CDM' . sprintf('%06d', $nosiri);
$add_resit = new Resit();
$add_resit->user_id = $request->user_id;
$add_resit->lelong_id = $request->lelong_id;
$add_resit->reference_no = $reference_no;
$add_resit->invoice_id = $request->invoice_id;
$add_resit->invoice_no = $request->invoice_no;
$add_resit->billplz_id = $cdm_reference;
$add_resit->total_payment = $request->total;
$add_resit->resit_type = 2;
$add_resit->save();
$selectedSag = $request->sag;
foreach ($selectedSag as $index) {
$add_payment = new Payment;
$add_payment->user_id = $request->user_id;
$add_payment->lelong_id = $request->lelong_id;
$add_payment->kodcaw = $index['kodcaw'];
$add_payment->lelongbid_id = $index['lelongbid_id'];
$add_payment->norujukan = $index['norujukan'];
$add_payment->total_payment = $index['total_payment'];
$add_payment->status_payment_opt = 3; //bayar secara CDM 3
$add_payment->status = 2; //paybidwin
$add_payment->remark = 'CDM';
$add_payment->resit_id = $add_resit->id;
$add_payment->save();
$updateTagBid = LelongBid::where('norujukan', $index['norujukan'])->first();
$updateTagBid->status_payment = 2;
$updateTagBid->save();
$updateTagBidder = LelongBidder::where('lelongbid_id', $updateTagBid->id)
->where('user_id', $request->user_id)->first();
$updateTagBidder->status_payment = 2;
$updateTagBidder->payment_id = $add_payment->id;
$updateTagBidder->save();
}
return response()->json(['success' => true]);
}
}