Revisi transaksi pembeli
This commit is contained in:
parent
ceb5cf414e
commit
548c74965d
@ -192,10 +192,14 @@ class UserTransactionController extends Controller
|
|||||||
'callbacks' => [
|
'callbacks' => [
|
||||||
'finish' => route('user-pembeli.index'),
|
'finish' => route('user-pembeli.index'),
|
||||||
],
|
],
|
||||||
'enabled_payments' => ['credit_card', 'gopay', 'qris'],
|
'enabled_payments' => [
|
||||||
|
'credit_card', 'shopeepay', 'gopay', 'other_qris'
|
||||||
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$client = new Client();
|
$client = new Client([
|
||||||
|
'verify' => false
|
||||||
|
]);
|
||||||
|
|
||||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||||
|
|
||||||
@ -208,7 +212,7 @@ class UserTransactionController extends Controller
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $response->getBody();
|
$result = json_decode($response->getBody(), true);
|
||||||
|
|
||||||
Transaction::where('id', $query->id)->update([
|
Transaction::where('id', $query->id)->update([
|
||||||
'token' => $result['token'],
|
'token' => $result['token'],
|
||||||
@ -415,16 +419,18 @@ class UserTransactionController extends Controller
|
|||||||
|
|
||||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withOptions([
|
||||||
|
'verify' => false
|
||||||
|
])->withHeaders([
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Authorization' => "Basic $auth",
|
'Authorization' => "Basic $auth",
|
||||||
])->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
])->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||||
|
|
||||||
$result = json_decode($response->body(), true);
|
$result = json_decode($response->body(), true);
|
||||||
|
|
||||||
if ($result['transaction'] == 'settlement') {
|
if ($result['transaction_status'] == 'settlement') {
|
||||||
$transaction = 'success';
|
$transaction = 'success';
|
||||||
} elseif ($result['transaction'] == 'capture') {
|
} elseif ($result['transaction_status'] == 'capture') {
|
||||||
if ($result['fraud_status'] == 'accept') {
|
if ($result['fraud_status'] == 'accept') {
|
||||||
$transaction = 'success';
|
$transaction = 'success';
|
||||||
} elseif ($result['fraud_status'] == 'challenge') {
|
} elseif ($result['fraud_status'] == 'challenge') {
|
||||||
@ -436,11 +442,10 @@ class UserTransactionController extends Controller
|
|||||||
|
|
||||||
$query1 = Transaction::where('id', $request->id)->update([
|
$query1 = Transaction::where('id', $request->id)->update([
|
||||||
'metode_pembayaran' => $result['payment_type'],
|
'metode_pembayaran' => $result['payment_type'],
|
||||||
'tanggal_transaksi' => now(),
|
'tanggal_transaksi' => $result['transaction_time'],
|
||||||
'status_transaksi' => $transaction,
|
'status_transaksi' => $transaction,
|
||||||
'status_pembayaran' => $result['transaction_status'],
|
'status_pembayaran' => $result['transaction_status'],
|
||||||
'fraud_status' => $result['fraud_status'],
|
'fraud_status' => $result['fraud_status'],
|
||||||
'reference_id' => $result['reference_id'],
|
|
||||||
'signature_key' => $result['signature_key'],
|
'signature_key' => $result['signature_key'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -516,7 +521,9 @@ class UserTransactionController extends Controller
|
|||||||
{
|
{
|
||||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withOptions([
|
||||||
|
'verify' => false
|
||||||
|
])->withHeaders([
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Authorization' => "Basic $auth",
|
'Authorization' => "Basic $auth",
|
||||||
])->post('https://api.sandbox.midtrans.com/v2/' . $request->id . '/cancel');
|
])->post('https://api.sandbox.midtrans.com/v2/' . $request->id . '/cancel');
|
||||||
@ -526,10 +533,17 @@ class UserTransactionController extends Controller
|
|||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
if(in_array($result['status_code'],['412','401'])){
|
||||||
|
Transaction::where('id', $request->id)->update([
|
||||||
|
'status_transaksi' => 'failure',
|
||||||
|
'status_pembayaran' => 'cancel',
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
Transaction::where('id', $request->id)->update([
|
Transaction::where('id', $request->id)->update([
|
||||||
'status_transaksi' => 'failure',
|
'status_transaksi' => 'failure',
|
||||||
'status_pembayaran' => $result['transaction_status'],
|
'status_pembayaran' => $result['transaction_status'],
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
TransactionDescription::create([
|
TransactionDescription::create([
|
||||||
'transaction_id' => $request->id,
|
'transaction_id' => $request->id,
|
||||||
@ -554,6 +568,7 @@ class UserTransactionController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => false,
|
'status' => false,
|
||||||
'message' => 'Transaksi gagal dibatalkan',
|
'message' => 'Transaksi gagal dibatalkan',
|
||||||
|
'data' => $result
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ return new class extends Migration
|
|||||||
$table->double('total_harga'); // gross amount
|
$table->double('total_harga'); // gross amount
|
||||||
$table->double('total_bayar');
|
$table->double('total_bayar');
|
||||||
$table->string('signature_key')->nullable();
|
$table->string('signature_key')->nullable();
|
||||||
$table->string('reference_id')->nullable();
|
|
||||||
$table->string('token')->nullable();
|
$table->string('token')->nullable();
|
||||||
$table->string('metode_pembayaran')->nullable();
|
$table->string('metode_pembayaran')->nullable();
|
||||||
$table->string('fraud_status')->nullable();
|
$table->string('fraud_status')->nullable();
|
||||||
|
@ -140,124 +140,8 @@
|
|||||||
const token = $(this).data('token');
|
const token = $(this).data('token');
|
||||||
const csrfToken = $('meta[name="csrf-token"]').attr('content');
|
const csrfToken = $('meta[name="csrf-token"]').attr('content');
|
||||||
|
|
||||||
// snap.pay(token, {
|
snap.pay(token, {
|
||||||
// onSuccess: function(result) {
|
onSuccess: function(result) {
|
||||||
// // $.ajaxSetup({
|
|
||||||
// // headers: {
|
|
||||||
// // 'X-CSRF-TOKEN': csrfToken
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
|
|
||||||
// // $.ajax({
|
|
||||||
// // url: "{{ route('user-pembeli.pay', ':id') }}"
|
|
||||||
// // .replace(':id', id),
|
|
||||||
// // type: "POST",
|
|
||||||
// // contentType: false,
|
|
||||||
// // processData: false,
|
|
||||||
// // success: function(response) {
|
|
||||||
// // Swal.fire({
|
|
||||||
// // title: response.status ? 'Berhasil' :
|
|
||||||
// // 'Gagal',
|
|
||||||
// // text: response.message,
|
|
||||||
// // icon: response.status ? 'success' :
|
|
||||||
// // 'error',
|
|
||||||
// // confirmButtonText: 'OK'
|
|
||||||
// // }).then(function() {
|
|
||||||
// // location.reload();
|
|
||||||
// // });
|
|
||||||
// // console.log(response);
|
|
||||||
// // },
|
|
||||||
// // error: function(error) {
|
|
||||||
// // Swal.fire({
|
|
||||||
// // title: 'Gagal',
|
|
||||||
// // text: 'Gagal mengupdate pembayaran ke database',
|
|
||||||
// // icon: 'error'
|
|
||||||
// // });
|
|
||||||
// // console.log(result);
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
// console.log(result);
|
|
||||||
// },
|
|
||||||
// onPending: function(result) {
|
|
||||||
// // $.ajaxSetup({
|
|
||||||
// // headers: {
|
|
||||||
// // 'X-CSRF-TOKEN': csrfToken
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
|
|
||||||
// // $.ajax({
|
|
||||||
// // url: "{{ route('user-pembeli.pay', ':id') }}"
|
|
||||||
// // .replace(':id', id),
|
|
||||||
// // type: "POST",
|
|
||||||
// // contentType: false,
|
|
||||||
// // processData: false,
|
|
||||||
// // success: function(response) {
|
|
||||||
// // Swal.fire({
|
|
||||||
// // title: 'Berhasil',
|
|
||||||
// // text: response.message,
|
|
||||||
// // icon: 'info',
|
|
||||||
// // confirmButtonText: 'OK'
|
|
||||||
// // });
|
|
||||||
// // console.log(response);
|
|
||||||
// // },
|
|
||||||
// // error: function(error) {
|
|
||||||
// // Swal.fire({
|
|
||||||
// // title: 'Gagal',
|
|
||||||
// // text: 'Gagal mengupdate pembayaran ke database',
|
|
||||||
// // icon: 'error'
|
|
||||||
// // });
|
|
||||||
// // console.log(error);
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
// console.log(result);
|
|
||||||
// },
|
|
||||||
// onError: function(result) {
|
|
||||||
// // $.ajaxSetup({
|
|
||||||
// // headers: {
|
|
||||||
// // 'X-CSRF-TOKEN': csrfToken
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
|
|
||||||
// // $.ajax({
|
|
||||||
// // url: "{{ route('user-pembeli.pay', ':id') }}"
|
|
||||||
// // .replace(':id', id),
|
|
||||||
// // type: "POST",
|
|
||||||
// // contentType: false,
|
|
||||||
// // processData: false,
|
|
||||||
// // success: function(response) {
|
|
||||||
// // Swal.fire({
|
|
||||||
// // title: 'Gagal',
|
|
||||||
// // text: response.message,
|
|
||||||
// // icon: 'error',
|
|
||||||
// // });
|
|
||||||
// // console.log(response);
|
|
||||||
// // },
|
|
||||||
// // error: function(error) {
|
|
||||||
// // Swal.fire({
|
|
||||||
// // title: 'Gagal',
|
|
||||||
// // text: 'Gagal mengupdate pembayaran ke database',
|
|
||||||
// // icon: 'error'
|
|
||||||
// // });
|
|
||||||
// // console.log(error);
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
// // Swal.fire({
|
|
||||||
// // title: 'Gagal',
|
|
||||||
// // text: 'Terjadi kesalahan karena ' + result,
|
|
||||||
// // icon: 'error'
|
|
||||||
// // });
|
|
||||||
// console.log(result);
|
|
||||||
// },
|
|
||||||
// onClose: function(error) {
|
|
||||||
// Swal.fire({
|
|
||||||
// title: 'Ditunda',
|
|
||||||
// text: 'Kamu menutup halaman pembayaran. Silahkan lakukan pembayaran nanti',
|
|
||||||
// icon: 'info'
|
|
||||||
// });
|
|
||||||
// console.log(error);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/etwtznjn.json" trigger="loop" colors="primary:#0ab39c,secondary:#405189" style="width:120px;height:120px"></lord-icon><div class="mt-4 pt-2 fs-15"><h4>Form Anda sedang diproses!</h4><p class="text-muted mx-4 mb-0">Mohon tunggu...</p></div></div>',
|
html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/etwtznjn.json" trigger="loop" colors="primary:#0ab39c,secondary:#405189" style="width:120px;height:120px"></lord-icon><div class="mt-4 pt-2 fs-15"><h4>Form Anda sedang diproses!</h4><p class="text-muted mx-4 mb-0">Mohon tunggu...</p></div></div>',
|
||||||
allowEscapeKey: false,
|
allowEscapeKey: false,
|
||||||
@ -281,9 +165,11 @@
|
|||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: response.status ? 'Berhasil' : 'Gagal',
|
title: response.status ? 'Berhasil' :
|
||||||
|
'Gagal',
|
||||||
text: response.message,
|
text: response.message,
|
||||||
icon: response.status ? 'success' : 'error'
|
icon: response.status ? 'success' :
|
||||||
|
'error'
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
if (response.status) {
|
if (response.status) {
|
||||||
location.reload();
|
location.reload();
|
||||||
@ -300,6 +186,87 @@
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
console.log(result);
|
||||||
|
},
|
||||||
|
onPending: function(result) {
|
||||||
|
// $.ajaxSetup({
|
||||||
|
// headers: {
|
||||||
|
// 'X-CSRF-TOKEN': csrfToken
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// $.ajax({
|
||||||
|
// url: "{{ route('user-pembeli.pay', ':id') }}"
|
||||||
|
// .replace(':id', id),
|
||||||
|
// type: "POST",
|
||||||
|
// contentType: false,
|
||||||
|
// processData: false,
|
||||||
|
// success: function(response) {
|
||||||
|
// Swal.fire({
|
||||||
|
// title: 'Berhasil',
|
||||||
|
// text: response.message,
|
||||||
|
// icon: 'info',
|
||||||
|
// confirmButtonText: 'OK'
|
||||||
|
// });
|
||||||
|
// console.log(response);
|
||||||
|
// },
|
||||||
|
// error: function(error) {
|
||||||
|
// Swal.fire({
|
||||||
|
// title: 'Gagal',
|
||||||
|
// text: 'Gagal mengupdate pembayaran ke database',
|
||||||
|
// icon: 'error'
|
||||||
|
// });
|
||||||
|
// console.log(error);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
console.log(result);
|
||||||
|
},
|
||||||
|
onError: function(result) {
|
||||||
|
// $.ajaxSetup({
|
||||||
|
// headers: {
|
||||||
|
// 'X-CSRF-TOKEN': csrfToken
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// $.ajax({
|
||||||
|
// url: "{{ route('user-pembeli.pay', ':id') }}"
|
||||||
|
// .replace(':id', id),
|
||||||
|
// type: "POST",
|
||||||
|
// contentType: false,
|
||||||
|
// processData: false,
|
||||||
|
// success: function(response) {
|
||||||
|
// Swal.fire({
|
||||||
|
// title: 'Gagal',
|
||||||
|
// text: response.message,
|
||||||
|
// icon: 'error',
|
||||||
|
// });
|
||||||
|
// console.log(response);
|
||||||
|
// },
|
||||||
|
// error: function(error) {
|
||||||
|
// Swal.fire({
|
||||||
|
// title: 'Gagal',
|
||||||
|
// text: 'Gagal mengupdate pembayaran ke database',
|
||||||
|
// icon: 'error'
|
||||||
|
// });
|
||||||
|
// console.log(error);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// Swal.fire({
|
||||||
|
// title: 'Gagal',
|
||||||
|
// text: 'Terjadi kesalahan karena ' + result,
|
||||||
|
// icon: 'error'
|
||||||
|
// });
|
||||||
|
console.log(result);
|
||||||
|
},
|
||||||
|
onClose: function(error) {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Ditunda',
|
||||||
|
text: 'Kamu menutup halaman pembayaran. Silahkan lakukan pembayaran nanti',
|
||||||
|
icon: 'info'
|
||||||
|
});
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#table-3').on('click', '#cancel', function() {
|
$('#table-3').on('click', '#cancel', function() {
|
||||||
@ -332,7 +299,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "{{ route('user-pembeli.cancel', ':id') }}",
|
url: "{{ route('user-pembeli.cancel') }}",
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: {
|
data: {
|
||||||
id: id
|
id: id
|
||||||
|
Loading…
Reference in New Issue
Block a user