Skip to content

Commit 5efbcda

Browse files
committed
Midtrans Callback Function
1 parent 7c5868d commit 5efbcda

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

app/Http/Controllers/User/CheckoutController.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,55 @@ public function getSnapRedirect(Checkout $checkout)
195195
}
196196
}
197197

198+
public function midtransCallback(Request $request)
199+
{
200+
$notif = new Midtrans\Notification();
201+
202+
$transaction_status = $notif->transaction_status;
203+
$fraud = $notif->fraud_status;
204+
205+
$checkout_id = explode('-', $notif->order_id)[0];
206+
$checkout = Checkout::find($checkout_id);
207+
208+
if ($transaction_status == 'capture') {
209+
if ($fraud == 'challenge') {
210+
// TODO Set payment status in merchant's database to 'challenge'
211+
$checkout->payment_status = 'pending';
212+
}
213+
else if ($fraud == 'accept') {
214+
// TODO Set payment status in merchant's database to 'success'
215+
$checkout->payment_status = 'paid';
216+
}
217+
}
218+
else if ($transaction_status == 'cancel') {
219+
if ($fraud == 'challenge') {
220+
// TODO Set payment status in merchant's database to 'failure'
221+
$checkout->payment_status = 'failed';
222+
}
223+
else if ($fraud == 'accept') {
224+
// TODO Set payment status in merchant's database to 'failure'
225+
$checkout->payment_status = 'failed';
226+
}
227+
}
228+
else if ($transaction_status == 'deny') {
229+
// TODO Set payment status in merchant's database to 'failure'
230+
$checkout->payment_status = 'failed';
231+
}
232+
else if ($transaction_status == 'settlement') {
233+
// TODO set payment status in merchant's database to 'Settlement'
234+
$checkout->payment_status = 'paid';
235+
}
236+
else if ($transaction_status == 'pending') {
237+
// TODO set payment status in merchant's database to 'Pending'
238+
$checkout->payment_status = 'pendiing';
239+
}
240+
else if ($transaction_status == 'expire') {
241+
// TODO set payment status in merchant's database to 'expire'
242+
$checkout->payment_status = 'failed';
243+
}
244+
245+
$checkout->save();
246+
return view('checkout/success');
247+
}
248+
198249
}

routes/web.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030

3131
// socialite routes
3232
Route::get('sign-in-google', [UserController::class, 'google'])->name('user.login.google');
33-
3433
Route::get('auth/google/callback', [UserController::class, 'handleProviderCallback'])->name('user.google.callback');
3534

35+
// midtrans routes
36+
Route::get('payment/success', [UserController::class, 'midtransCallback']);
37+
Route::post('payment/success', [UserController::class, 'midtransCallback']);
3638

3739
Route::middleware('auth')->group(function(){
3840
// Checkout routes

0 commit comments

Comments
 (0)