Skip to content

Instantly share code, notes, and snippets.

@aditagusta
Last active July 22, 2021 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aditagusta/f6c03c9b137104dad5375876916c4139 to your computer and use it in GitHub Desktop.
Save aditagusta/f6c03c9b137104dad5375876916c4139 to your computer and use it in GitHub Desktop.
Callback Mutasibank
public function callBack(Request $request)
{
$data = $request->all();
if($data['api_key'] === env('API_MUTASI_KEY'))
{
$toStorage = [
'hostname' => $_SERVER,
'header' => getallheaders(),
'body' => $request->all()
];
//save to storage
Storage::disk('local')->put('log-mutasibank'.'-'.date('YmdHis').'.json', json_encode($toStorage));
$success = $failed = 0;
foreach($data['data_mutasi'] as $k => $v){
if($v['type'] === 'CR'){
//check topup
$cek = DB::table('request_top_up')->whereJumlah($v['amount'])->first();
if($cek){
// ganti status
$status = DB::table('request_top_up')->whereId($cek->id)->update(['status' => 1,'approved_by' => 'Mutasibank']);
// tambah wallet member
$member = DB::table('users')->whereId($cek->user_id)->first();
if($member->saldo == 0)
{
$topup = $cek->jumlah;
} else {
$topup = $member->saldo + $cek->jumlah;
}
$update = DB::table('users')->whereId($cek->user_id)->update(['saldo' => $topup]);
$success++;
// input ke table record
$total_saldo = $member->saldo + $v['amount'];
$record = DB::table('record')
->insert([
'user_id' => $cek->user_id,
'cr' => $v['amount'],
'total_saldo' => $total_saldo,
'uraian' => 'TopUp '.$member->name,
'created_at' => \Carbon\Carbon::now()
]);
}else{
$failed++;
}
} elseif ($v['type'] === 'DB') {
// // jika melakukan pembelian melalui wallet uncang
// $cek = DB::table('request_top_up')->whereJumlah($v['amount'])->first();
// if($cek){
// // kurangi wallet member
// $member = DB::table('users')->whereId($cek->user_id)->first();
// if($member->saldo == 0)
// {
// $penggeluaran = $cek->jumlah;
// } else {
// $penggeluaran = $member->saldo - $cek->jumlah;
// }
// $update = DB::table('users')->whereId($cek->user_id)->update(['saldo' => $pengeluaran]);
// $success++;
// // input ke table record
// $total_saldo = $member->saldo + $v['amount'];
// $record = DB::table('record')
// ->insert([
// 'user_id' => $cek->user_id,
// 'db' => $v['amount'],
// 'total_saldo' => $total_saldo,
// 'created_at' => \Carbon\Carbon::now()
// ]);
// }else{
// $failed++;
// }
}
}
return response()->json(['status' => 200,'message' => 'Berhasil melakukan mutasi', 'data' => ['success' => $success, 'failed' => $failed]]);
}
return response()->json(['status' => 400,'message' => 'Gagal melakukan mutasi', 400]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment