Invoice dan email
This commit is contained in:
parent
c1a837ca88
commit
dde663e95a
@ -102,6 +102,8 @@ class AdminRefundController extends Controller
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
Log::error($result['status_message']);
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Refund gagal dilakukan',
|
||||
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Login;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\verificationMail;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
@ -405,4 +406,18 @@ class LoginController extends Controller
|
||||
}
|
||||
//OCR
|
||||
}
|
||||
|
||||
public function email(){
|
||||
$verificationEmail = [
|
||||
'email' => 'Halo',
|
||||
'code' => 'kode'
|
||||
];
|
||||
return view('email.verification-email',compact('verificationEmail'));
|
||||
}
|
||||
|
||||
public function invoice(){
|
||||
return view('invoice.export-invoice', [
|
||||
'transaction' => Transaction::findOrFail('80d9b19b-ba17-4aea-8cad-c3b4661d33bc'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\RefundDescription;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RefundDescriptionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(RefundDescription $refundDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(RefundDescription $refundDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, RefundDescription $refundDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(RefundDescription $refundDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\TransactionDescription;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TransactionDescriptionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(TransactionDescription $transactionDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(TransactionDescription $transactionDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, TransactionDescription $transactionDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(TransactionDescription $transactionDescription)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
756
app/Http/Controllers/User/PembeliController.php
Normal file
756
app/Http/Controllers/User/PembeliController.php
Normal file
@ -0,0 +1,756 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\TransactionDescription;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class PembeliController extends Controller
|
||||
{
|
||||
public function indexPembeli()
|
||||
{
|
||||
return view('user.transaction.pembeli.index');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
$bulan = $now->format('F');
|
||||
$tahun = $now->year;
|
||||
$persentase_keuntungan = Setting::where('status', 'Active')
|
||||
->where('bulan', '=', $bulan)
|
||||
->where('tahun', '=', $tahun)
|
||||
->value('persentase');
|
||||
if (is_null($persentase_keuntungan)) {
|
||||
$persentase_keuntungan = Setting::where('status', 'Active')
|
||||
->latest()
|
||||
->value('persentase');
|
||||
}
|
||||
return view('user.transaction.pembeli.new-transaction', [
|
||||
'persentase_keuntungan' => $persentase_keuntungan,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$pembeli = auth()->user()->email;
|
||||
$penjual = $request->email_penjual;
|
||||
$nama_barang = $request->nama_barang;
|
||||
$satuan_barang = $request->satuan_barang;
|
||||
$deskripsi_transaksi = $request->deskripsi;
|
||||
$harga_barang = $request->harga_barang;
|
||||
$jumlah_barang = $request->jumlah_barang;
|
||||
|
||||
$nama_depan_pembeli = auth()->user()->nama_depan;
|
||||
$nama_belakang_pembeli = auth()->user()->nama_belakang;
|
||||
$nohp_pembeli = auth()->user()->nohp;
|
||||
$nama_penjual = User::where('email', $penjual)->value('nama_depan');
|
||||
$bank_penjual = User::where('email', $penjual)->value('nama_bank');
|
||||
$no_rek_penjual = User::where('email', $penjual)->value('no_rek');
|
||||
|
||||
if ($bank_penjual == '' && $no_rek_penjual == '') {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Penjual belum memiliki/memasukan nomor rek bank',
|
||||
]);
|
||||
}
|
||||
|
||||
$alamat = ucwords(strtolower(auth()->user()->alamat));
|
||||
|
||||
$now = Carbon::now();
|
||||
|
||||
$persentase_keuntungan = $request->persentase_keuntungan;
|
||||
|
||||
$total_harga = $request->total_harga;
|
||||
$total_keuntungan = $request->total_keuntungan;
|
||||
$total_bayar = $request->total_bayar;
|
||||
|
||||
$batas_pembayaran = $now->addDays(1)->toTimeString();
|
||||
$batas_konfirmasi_transaksi = $now->addDays(2)->toDateTimeString();
|
||||
$batas_pengiriman_barang_awal = $now->addDays(3)->toDateTimeString();
|
||||
$batas_pengiriman_barang_akhir = $now->addDays(4)->toDateTimeString();
|
||||
|
||||
$status = 'created';
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$query = Transaction::create([
|
||||
'pembeli' => $pembeli,
|
||||
'penjual' => $penjual,
|
||||
'nama_barang' => $nama_barang,
|
||||
'deskripsi_transaksi' => $deskripsi_transaksi,
|
||||
'satuan_barang' => $satuan_barang,
|
||||
'harga_barang' => $harga_barang,
|
||||
'jumlah_barang' => $jumlah_barang,
|
||||
'persentase_keuntungan' => $persentase_keuntungan,
|
||||
'total_keuntungan' => $total_keuntungan,
|
||||
'total_harga' => $total_harga,
|
||||
'total_bayar' => $total_bayar,
|
||||
'nama_bank_penjual' => $bank_penjual,
|
||||
'no_rek_penjual' => $no_rek_penjual,
|
||||
'status_transaksi' => $status,
|
||||
'batas_pembayaran' => $batas_pembayaran,
|
||||
'batas_konfirmasi_transaksi' => $batas_konfirmasi_transaksi,
|
||||
'batas_pengiriman_barang_awal' => $batas_pengiriman_barang_awal,
|
||||
'batas_pengiriman_barang_akhir' => $batas_pengiriman_barang_akhir,
|
||||
]);
|
||||
|
||||
$params = [
|
||||
'transaction_details' => [
|
||||
'order_id' => $query->id,
|
||||
'gross_amount' => $total_bayar,
|
||||
],
|
||||
'item_details' => [
|
||||
[
|
||||
'id' => $nama_barang . time(),
|
||||
'price' => $harga_barang,
|
||||
'quantity' => $jumlah_barang,
|
||||
'name' => $nama_barang,
|
||||
],
|
||||
[
|
||||
'id' => 'BA01',
|
||||
'price' => $total_keuntungan,
|
||||
'quantity' => 1,
|
||||
'name' => 'Biaya Admin',
|
||||
],
|
||||
],
|
||||
'customer_details' => [
|
||||
'firts_name' => $nama_depan_pembeli,
|
||||
'last_name' => $nama_belakang_pembeli,
|
||||
'email' => $pembeli,
|
||||
'phone' => $nohp_pembeli,
|
||||
'billing' => [
|
||||
'first_name' => $nama_depan_pembeli,
|
||||
'last_name' => $nama_belakang_pembeli,
|
||||
'email' => $pembeli,
|
||||
'phone' => $nohp_pembeli,
|
||||
'address' => $alamat,
|
||||
'city' => auth()->user()->village->district->city->name,
|
||||
'country_code' => 'IDN',
|
||||
],
|
||||
],
|
||||
'callbacks' => [
|
||||
'finish' => route('user-pembeli.index'),
|
||||
],
|
||||
'enabled_payments' => ['credit_card', 'shopeepay', 'gopay', 'other_qris'],
|
||||
];
|
||||
|
||||
$client = new Client([
|
||||
'verify' => false,
|
||||
]);
|
||||
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = $client->request('POST', 'https://app.sandbox.midtrans.com/snap/v1/transactions', [
|
||||
'body' => json_encode($params),
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
'authorization' => 'Basic ' . $auth,
|
||||
'content-type' => 'application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$result = json_decode($response->getBody(), true);
|
||||
|
||||
Transaction::where('id', $query->id)->update([
|
||||
'token' => $result['token'],
|
||||
]);
|
||||
|
||||
$contact = Contact::where('pemilik_kontak', $pembeli)
|
||||
->where('relasi_kontak', $penjual)
|
||||
->count();
|
||||
|
||||
if ($contact == 0) {
|
||||
Contact::create([
|
||||
'pemilik_kontak' => $pembeli,
|
||||
'relasi_kontak' => $penjual,
|
||||
]);
|
||||
}
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $query->id,
|
||||
'status' => $status,
|
||||
'user' => $pembeli,
|
||||
'judul' => 'fa fa-plus',
|
||||
'background' => 'bg-buyer',
|
||||
'deskripsi' => $nama_depan_pembeli . ' telah membuat transaksi baru dengan ' . $nama_penjual,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Berhasil menambahkan transaksi. Silahkan lakukan pembayaran.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal menambahkan transaksi.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function finishTransaction(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'finished',
|
||||
'status_pembayaran' => 'settlement',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'finished',
|
||||
'background' => 'bg-buyer',
|
||||
'user' => auth()->user()->email,
|
||||
'judul' => 'fas fa-check',
|
||||
'deskripsi' => 'Pesanan telah diselesaikan oleh ' . auth()->user()->nama_depan . '.',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pesanan telah diselesaikan oleh ' . auth()->user()->nama_depan . '.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function payTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
$code = substr($result['status_code'], 0, 1);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
if ($code == '4') {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di server.',
|
||||
'data' => $result,
|
||||
]);
|
||||
} else {
|
||||
if ($result['transaction_status'] == 'settlement') {
|
||||
$transaction = 'success';
|
||||
} elseif ($result['transaction_status'] == 'capture') {
|
||||
if ($result['fraud_status'] == 'accept') {
|
||||
$transaction = 'success';
|
||||
} elseif ($result['fraud_status'] == 'challenge') {
|
||||
$transaction = 'challenge';
|
||||
}
|
||||
} else {
|
||||
$transaction = 'failure';
|
||||
}
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'metode_pembayaran' => $result['payment_type'],
|
||||
'tanggal_transaksi' => $result['transaction_time'],
|
||||
'status_transaksi' => $transaction,
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'fraud_status' => $result['fraud_status'],
|
||||
'signature_key' => $result['signature_key'],
|
||||
]);
|
||||
|
||||
if ($transaction == 'success') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'success',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-money-bill',
|
||||
'deskripsi' => auth()->user()->nama_depan . ' telah sukses melakukan pembayaran. Transaksi diteruskan ke penjual.',
|
||||
'user' => auth()->user()->email,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pembayaran sukses',
|
||||
]);
|
||||
} elseif ($transaction == 'challenge') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'challenge',
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-clock',
|
||||
'deskripsi' => 'Transaksi ' . auth()->user()->email . ' terindikasi masalah, tunggu sesaat hingga admin menyetujui pembayaran.',
|
||||
'user' => 'admin@example.net',
|
||||
'keterangan' => $result['status_message'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Pembayaran ditunda hingga disetujui oleh admin.',
|
||||
]);
|
||||
} else {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'failure',
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Terjadi kegagalan pembayaran.',
|
||||
'user' => 'admin@example.net',
|
||||
'keterangan' => $result['status_message'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi pembayaran gagal',
|
||||
]);
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi pembayaran gagal.',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
|
||||
public function cancelTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->post('https://api.sandbox.midtrans.com/v2/' . $request->id . '/cancel');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
if (in_array($result['status_code'], ['412','401'])) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi gagal.',
|
||||
'data' => $result
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'failure',
|
||||
'status_pembayaran' => 'cancel'
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'cancel',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => auth()->user()->nama_depan . ' telah membatalkan transaksi.',
|
||||
'user' => auth()->user()->email,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Transaksi berhasil dibatalkan',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi gagal dibatalkan',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function pendingTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pembayaran di-pending, silahkan masuk lagi dan bayar secepat mungkin.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di bagian server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function complaintTransaction($id)
|
||||
{
|
||||
return view('user.refund.new-refund', compact('id'));
|
||||
}
|
||||
|
||||
public function onErrorTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
]);
|
||||
|
||||
if ($result['transaction_status'] == 'expire') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'cancel',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Pembayaran sudah expire',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Pembayaran sudah expire, silahkan buat transaksi baru.',
|
||||
]);
|
||||
} elseif ($result['transaction'] == 'failure') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'failure',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => auth()->user()->nama_depan . ' telah membatalkan transaksi.',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi kesalahan di server saat pembayaran.',
|
||||
'data' => $result,
|
||||
]);
|
||||
} else {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => $result['transaction_status'],
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Status tidak diketahui',
|
||||
'user' => 'admin@example.net',
|
||||
'keterangan' => $result['status_message'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Terjadi kesalahan di server',
|
||||
'data' => $result,
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di bagian server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function onCloseTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
$status = $result['transaction_status'] == null ? '' : $result['transaction_status'];
|
||||
|
||||
if ($status == '') {
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'On Close',
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
if ($result['transaction_status'] == 'expire') {
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'status_transaksi' => 'failure',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'cancel',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Pembayaran sudah expire',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Pembayaran sudah expire, silahkan buat transaksi baru.',
|
||||
]);
|
||||
} elseif ($result['transaction'] == 'failure') {
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'status_transaksi' => 'failure',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'failure',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => auth()->user()->nama_depan . ' telah membatalkan transaksi.',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi kesalahan di server saat pembayaran.',
|
||||
]);
|
||||
} else {
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'status_transaksi' => 'failure',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => $result['transaction_status'],
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Status tidak diketahui.',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Terjadi kesalahan di server',
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di bagian server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function listPembeli(Request $request)
|
||||
{
|
||||
try{
|
||||
$subQuery = Transaction::join('users','transactions.penjual','=','users.email')
|
||||
->where('transactions.pembeli',auth()->user()->email)
|
||||
->select(
|
||||
'transactions.id',
|
||||
DB::raw("CONCAT(users.nama_depan,' ',users.nama_belakang) as nama_penjual"),
|
||||
'transactions.nama_barang',
|
||||
'transactions.total_harga',
|
||||
'transactions.created_at',
|
||||
'transactions.status_transaksi',
|
||||
'transactions.token'
|
||||
);
|
||||
|
||||
if($request->has('search') && !empty($request->search['value'])){
|
||||
$searchPembeli = $request->search['value'];
|
||||
if(!is_numeric($searchPembeli)){
|
||||
$subQuery->where(function($a) use ($searchPembeli){
|
||||
$a->whereRaw("LOWER(CONCAT(users.nama_depan,' ',users.nama_belakang)) LIKE ?",['%'.strtolower($searchPembeli).'%'])
|
||||
->orWhereRaw('LOWER(transactions.nama_barang) LIKE ?',['%'.strtolower($searchPembeli).'%'])
|
||||
->orWhereRaw('LOWER(transactions.status_transaksi) LIKE ?',['%'.strtolower($searchPembeli).'%']);
|
||||
});
|
||||
}else{
|
||||
$subQuery->where(function($a) use ($searchPembeli){
|
||||
$a->where('transactions.total_harga','=',$searchPembeli);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$queryPembeli = Transaction::from(DB::raw("({$subQuery->toSql()}) as tmp"))
|
||||
->mergeBindings($subQuery->getQuery()) // Menggabungkan binding parameters
|
||||
->select('*')
|
||||
->get();
|
||||
|
||||
if ($request->ajax()) {
|
||||
return DataTables::of($queryPembeli)
|
||||
->addIndexColumn()
|
||||
->addColumn('action', function ($row) {
|
||||
$url = route('user-transaction.show', ['id' => $row->id]);
|
||||
$invoice = route('invoice.get',['id' => $row->id]);
|
||||
$html_code = '
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
....
|
||||
</button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$url.'">Detail</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$invoice.'">Invoice</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalTracking"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Tracking</a>
|
||||
</li>';
|
||||
|
||||
if($row->status_transaksi == 'created'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" id="bayar"
|
||||
data-id="'.$row->id.'"
|
||||
data-token="'.$row->token.'"
|
||||
href="#">Bayar</a>
|
||||
</li>
|
||||
<li><a href="#" data-id="'.$row->id.'"
|
||||
id="cancel" class="dropdown-item">Batal</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
if($row->status_transaksi == 'sent'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalFinish"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Selesaikan</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
$html_code .= '
|
||||
</ul>
|
||||
</div>';
|
||||
return $html_code;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
}catch(Throwable $e){
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json(['success' => false, 'message' => 'Terjadi Kesalahan pada sisi server']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
331
app/Http/Controllers/User/PenjualController.php
Normal file
331
app/Http/Controllers/User/PenjualController.php
Normal file
@ -0,0 +1,331 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Refund;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\TransactionDescription;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Throwable;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class PenjualController extends Controller
|
||||
{
|
||||
public function indexPenjual()
|
||||
{
|
||||
return view('user.transaction.penjual.index');
|
||||
}
|
||||
|
||||
public function listPenjual(Request $request){
|
||||
try{
|
||||
$subQuery = Transaction::join('users','transactions.pembeli','=','users.email')
|
||||
->where('transactions.penjual',auth()->user()->email)
|
||||
->select(
|
||||
'transactions.id',
|
||||
DB::raw("CONCAT(users.nama_depan,' ',users.nama_belakang) as nama_pembeli"),
|
||||
'transactions.nama_barang',
|
||||
'transactions.total_harga',
|
||||
'transactions.created_at',
|
||||
'transactions.status_transaksi',
|
||||
);
|
||||
|
||||
if($request->has('search') && !empty($request->search['value'])){
|
||||
$searchPenjual = $request->search['value'];
|
||||
if(!is_numeric($searchPenjual)){
|
||||
$subQuery->where(function($a) use ($searchPenjual){
|
||||
$a->whereRaw("LOWER(CONCAT(users.nama_depan,' ',users.nama_belakang)) LIKE ?",['%'.strtolower($searchPenjual).'%'])
|
||||
->orWhereRaw('LOWER(transactions.nama_barang) LIKE ?',['%'.strtolower($searchPenjual).'%'])
|
||||
->orWhereRaw('LOWER(transactions.status_transaksi) LIKE ?',['%'.strtolower($searchPenjual).'%']);
|
||||
});
|
||||
}else{
|
||||
$subQuery->where(function($a) use ($searchPenjual){
|
||||
$a->whereDay('transactions.created_at', '=', $searchPenjual)
|
||||
->orWhereMonth('transactions.created_at', '=', $searchPenjual)
|
||||
->orWhereYear('transactions.created_at', '=', $searchPenjual)
|
||||
->orWhere('transactions.total_harga', '=', $searchPenjual);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$queryPenjual = Transaction::from(DB::raw("({$subQuery->toSql()}) as tmp"))
|
||||
->mergeBindings($subQuery->getQuery()) // Menggabungkan binding parameters
|
||||
->select('*')
|
||||
->get();
|
||||
|
||||
if ($request->ajax()) {
|
||||
return DataTables::of($queryPenjual)
|
||||
->addIndexColumn()
|
||||
->addColumn('action', function ($row) {
|
||||
$url = route('user-transaction.show', ['id' => $row->id]);
|
||||
$invoice = route('invoice.get',['id' => $row->id]);
|
||||
$html_code = '
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
....
|
||||
</button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$url.'">Detail</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$invoice.'">Invoice</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalTracking"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Tracking</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item" id="denyTransaction"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Tolak Transaksi</a>
|
||||
</li>';
|
||||
|
||||
if($row->status_transaksi == 'success'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" id="processTransaction"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Proses Transaksi</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
if($row->status_transaksi == 'progress'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" id="sendOrder"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Kirim barang</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
if($row->status_transaksi == 'sent'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalOrderSent"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Barang sudah sampai</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
$html_code .= '
|
||||
</ul>
|
||||
</div>';
|
||||
return $html_code;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
}catch(Throwable $e){
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json(['success' => false, 'message' => 'Terjadi Kesalahan pada sisi server']);
|
||||
}
|
||||
}
|
||||
|
||||
public function acceptTransaction(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'process',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'process',
|
||||
'background' => 'bg-seller',
|
||||
'user' => auth()->user()->email,
|
||||
'judul' => 'fas fa-handshake',
|
||||
'deskripsi' => 'Transaksi telah diterima oleh ' . auth()->user()->nama_depan,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Transaksi telah diterima. Siapkan pesanan untuk dikirim ke penjual.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function denyTransaction(Request $request){
|
||||
|
||||
$transaction = Transaction::where('id', $request->id)->first();
|
||||
$refund = Refund::create([
|
||||
'transaction_id' => $request->id,
|
||||
'total' => $transaction->total_bayar,
|
||||
'due_date' => now(),
|
||||
'status' => 'refund',
|
||||
'complaint' => $request->complaint
|
||||
]);
|
||||
|
||||
// $params = [
|
||||
// 'refund_key' => $request->id . '-ref1',
|
||||
// 'amount' => $refund->total,
|
||||
// 'reason' => $refund->complaint,
|
||||
// ];
|
||||
|
||||
// $auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
// $response = Http::withOptions([
|
||||
// 'verify' => false,
|
||||
// ])
|
||||
// ->withHeaders([
|
||||
// 'Content-Type' => 'application/json',
|
||||
// 'Authorization' => "Basic $auth",
|
||||
// ])
|
||||
// ->post('https://api.sandbox.midtrans.com/v2/'.$request->id.'/refund', $params);
|
||||
|
||||
// $result = json_decode($response->body(), true);
|
||||
// $code = $result['status_code'];
|
||||
$code = '200';
|
||||
|
||||
if($code == '200'){
|
||||
try{
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'refund',
|
||||
'background' => 'bg-seller',
|
||||
'user' => auth()->user()->email,
|
||||
'judul' => 'fas fa-handshake',
|
||||
'deskripsi' => 'Transaksi ditolak '.auth()->user()->nama_depan.', uang akan dikembalikan ke pembeli. ',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Transaksi telah ditolak. Uang akan dikirimkan ke pembeli.',
|
||||
]);
|
||||
}catch(Throwable $e){
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
// Log::error($result['status_message']);
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi gagal',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function sendingOrder(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'sending',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'sending',
|
||||
'background' => 'bg-seller',
|
||||
'user' => auth()->user()->email,
|
||||
'judul' => 'fas fa-truck-moving',
|
||||
'deskripsi' => 'Pesanan telah dikirim oleh ' . auth()->user()->nama_depan . ' dan sedang dalam perjalanan menuju pembeli.',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pesanan sedang dikirim dan menuju pembeli.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function sentOrder(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->transaction_id)->update([
|
||||
'status_transaksi' => 'sent',
|
||||
]);
|
||||
|
||||
$bukti_foto = '';
|
||||
|
||||
if ($request->hasFile('bukti_foto')) {
|
||||
$file = $request->file('bukti_foto');
|
||||
$bukti_foto = time() . '.' . $file->getClientOriginalExtension();
|
||||
$path = 'bukti-foto/' . $bukti_foto;
|
||||
|
||||
Storage::disk('public')->put($path, file_get_contents($file));
|
||||
}
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->transaction_id,
|
||||
'status' => 'sent',
|
||||
'background' => 'bg-seller',
|
||||
'user' => auth()->user()->email,
|
||||
'judul' => 'fas fa-check',
|
||||
'deskripsi' => 'Pesanan telah sampai di tempat pembeli. Keterangan: '.$request->keterangan_bukti,
|
||||
'bukti_foto' => $bukti_foto,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pesanan telah sampai di tempat pembeli.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
|
||||
return response([
|
||||
'status' => true,
|
||||
'message' => 'Sukses kirim data.',
|
||||
'data' => $request
|
||||
]);
|
||||
}
|
||||
}
|
@ -24,23 +24,6 @@ use Stichoza\GoogleTranslate\GoogleTranslate;
|
||||
|
||||
class UserTransactionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
public function indexPembeli()
|
||||
{
|
||||
return view('user.transaction.pembeli.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function indexPenjual()
|
||||
{
|
||||
return view('user.transaction.penjual.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('user.transaction.pembeli.detail-transaction', [
|
||||
@ -51,968 +34,6 @@ class UserTransactionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
$bulan = $now->format('F');
|
||||
$tahun = $now->year;
|
||||
$persentase_keuntungan = Setting::where('status', 'Active')
|
||||
->where('bulan', '=', $bulan)
|
||||
->where('tahun', '=', $tahun)
|
||||
->value('persentase');
|
||||
if (is_null($persentase_keuntungan)) {
|
||||
$persentase_keuntungan = Setting::where('status', 'Active')
|
||||
->latest()
|
||||
->value('persentase');
|
||||
}
|
||||
return view('user.transaction.pembeli.new-transaction', [
|
||||
'persentase_keuntungan' => $persentase_keuntungan,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$pembeli = Auth::user()->email;
|
||||
$penjual = $request->email_penjual;
|
||||
$nama_barang = $request->nama_barang;
|
||||
$satuan_barang = $request->satuan_barang;
|
||||
$deskripsi_transaksi = $request->deskripsi;
|
||||
$harga_barang = $request->harga_barang;
|
||||
$jumlah_barang = $request->jumlah_barang;
|
||||
|
||||
$nama_depan_pembeli = Auth::user()->nama_depan;
|
||||
$nama_belakang_pembeli = Auth::user()->nama_belakang;
|
||||
$nohp_pembeli = Auth::user()->nohp;
|
||||
$nama_penjual = User::where('email', $penjual)->value('nama_depan');
|
||||
$bank_penjual = User::where('email', $penjual)->value('nama_bank');
|
||||
$no_rek_penjual = User::where('email', $penjual)->value('no_rek');
|
||||
|
||||
if ($bank_penjual == '' && $no_rek_penjual == '') {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Penjual belum memiliki/memasukan nomor rek bank',
|
||||
]);
|
||||
}
|
||||
|
||||
$alamat = ucwords(strtolower(Auth::user()->alamat));
|
||||
|
||||
$now = Carbon::now();
|
||||
|
||||
$persentase_keuntungan = $request->persentase_keuntungan;
|
||||
|
||||
$total_harga = $request->total_harga;
|
||||
$total_keuntungan = $request->total_keuntungan;
|
||||
$total_bayar = $request->total_bayar;
|
||||
|
||||
$batas_pembayaran = $now->addDays(1)->toTimeString();
|
||||
$batas_konfirmasi_transaksi = $now->addDays(2)->toDateTimeString();
|
||||
$batas_pengiriman_barang_awal = $now->addDays(3)->toDateTimeString();
|
||||
$batas_pengiriman_barang_akhir = $now->addDays(4)->toDateTimeString();
|
||||
|
||||
$status = 'created';
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$query = Transaction::create([
|
||||
'pembeli' => $pembeli,
|
||||
'penjual' => $penjual,
|
||||
'nama_barang' => $nama_barang,
|
||||
'deskripsi_transaksi' => $deskripsi_transaksi,
|
||||
'satuan_barang' => $satuan_barang,
|
||||
'harga_barang' => $harga_barang,
|
||||
'jumlah_barang' => $jumlah_barang,
|
||||
'persentase_keuntungan' => $persentase_keuntungan,
|
||||
'total_keuntungan' => $total_keuntungan,
|
||||
'total_harga' => $total_harga,
|
||||
'total_bayar' => $total_bayar,
|
||||
'nama_bank_penjual' => $bank_penjual,
|
||||
'no_rek_penjual' => $no_rek_penjual,
|
||||
'status_transaksi' => $status,
|
||||
'batas_pembayaran' => $batas_pembayaran,
|
||||
'batas_konfirmasi_transaksi' => $batas_konfirmasi_transaksi,
|
||||
'batas_pengiriman_barang_awal' => $batas_pengiriman_barang_awal,
|
||||
'batas_pengiriman_barang_akhir' => $batas_pengiriman_barang_akhir,
|
||||
]);
|
||||
|
||||
$params = [
|
||||
'transaction_details' => [
|
||||
'order_id' => $query->id,
|
||||
'gross_amount' => $total_bayar,
|
||||
],
|
||||
'item_details' => [
|
||||
[
|
||||
'id' => $nama_barang . time(),
|
||||
'price' => $harga_barang,
|
||||
'quantity' => $jumlah_barang,
|
||||
'name' => $nama_barang,
|
||||
],
|
||||
[
|
||||
'id' => 'BA01',
|
||||
'price' => $total_keuntungan,
|
||||
'quantity' => 1,
|
||||
'name' => 'Biaya Admin',
|
||||
],
|
||||
],
|
||||
'customer_details' => [
|
||||
'firts_name' => $nama_depan_pembeli,
|
||||
'last_name' => $nama_belakang_pembeli,
|
||||
'email' => $pembeli,
|
||||
'phone' => $nohp_pembeli,
|
||||
'billing' => [
|
||||
'first_name' => $nama_depan_pembeli,
|
||||
'last_name' => $nama_belakang_pembeli,
|
||||
'email' => $pembeli,
|
||||
'phone' => $nohp_pembeli,
|
||||
'address' => $alamat,
|
||||
'city' => Auth::user()->village->district->city->name,
|
||||
'country_code' => 'IDN',
|
||||
],
|
||||
],
|
||||
'callbacks' => [
|
||||
'finish' => route('user-pembeli.index'),
|
||||
],
|
||||
'enabled_payments' => ['credit_card', 'shopeepay', 'gopay', 'other_qris'],
|
||||
];
|
||||
|
||||
$client = new Client([
|
||||
'verify' => false,
|
||||
]);
|
||||
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = $client->request('POST', 'https://app.sandbox.midtrans.com/snap/v1/transactions', [
|
||||
'body' => json_encode($params),
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
'authorization' => 'Basic ' . $auth,
|
||||
'content-type' => 'application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$result = json_decode($response->getBody(), true);
|
||||
|
||||
Transaction::where('id', $query->id)->update([
|
||||
'token' => $result['token'],
|
||||
]);
|
||||
|
||||
$contact = Contact::where('pemilik_kontak', $pembeli)
|
||||
->where('relasi_kontak', $penjual)
|
||||
->count();
|
||||
|
||||
if ($contact == 0) {
|
||||
Contact::create([
|
||||
'pemilik_kontak' => $pembeli,
|
||||
'relasi_kontak' => $penjual,
|
||||
]);
|
||||
}
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $query->id,
|
||||
'status' => $status,
|
||||
'user' => $pembeli,
|
||||
'judul' => 'fa fa-plus',
|
||||
'background' => 'bg-buyer',
|
||||
'deskripsi' => $nama_depan_pembeli . ' telah membuat transaksi baru dengan ' . $nama_penjual,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Berhasil menambahkan transaksi. Silahkan lakukan pembayaran.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal menambahkan transaksi.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function acceptTransaction(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'process',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'process',
|
||||
'background' => 'bg-seller',
|
||||
'user' => Auth::user()->email,
|
||||
'judul' => 'fas fa-handshake',
|
||||
'deskripsi' => 'Transaksi telah diterima oleh ' . Auth::user()->nama_depan,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Transaksi telah diterima. Siapkan pesanan untuk dikirim ke penjual.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function sendingOrder(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'sending',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'sending',
|
||||
'background' => 'bg-seller',
|
||||
'user' => Auth::user()->email,
|
||||
'judul' => 'fas fa-truck-moving',
|
||||
'deskripsi' => 'Pesanan telah dikirim oleh ' . Auth::user()->nama_depan . ' dan sedang dalam perjalanan menuju pembeli.',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pesanan sedang dikirim dan menuju pembeli.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function sentOrder(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->transaction_id)->update([
|
||||
'status_transaksi' => 'sent',
|
||||
]);
|
||||
|
||||
$bukti_foto = '';
|
||||
|
||||
if ($request->hasFile('bukti_foto')) {
|
||||
$file = $request->file('bukti_foto');
|
||||
$bukti_foto = time() . '.' . $file->getClientOriginalExtension();
|
||||
$path = 'bukti-foto/' . $bukti_foto;
|
||||
|
||||
Storage::disk('public')->put($path, file_get_contents($file));
|
||||
}
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->transaction_id,
|
||||
'status' => 'sent',
|
||||
'background' => 'bg-seller',
|
||||
'user' => Auth::user()->email,
|
||||
'judul' => 'fas fa-check',
|
||||
'deskripsi' => 'Pesanan telah sampai di tempat pembeli. Keterangan: '.$request->keterangan_bukti,
|
||||
'bukti_foto' => $bukti_foto,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pesanan telah sampai di tempat pembeli.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
|
||||
return response([
|
||||
'status' => true,
|
||||
'message' => 'Sukses kirim data.',
|
||||
'data' => $request
|
||||
]);
|
||||
}
|
||||
|
||||
public function finishTransaction(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'finished',
|
||||
'status_pembayaran' => 'settlement',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'finished',
|
||||
'background' => 'bg-buyer',
|
||||
'user' => Auth::user()->email,
|
||||
'judul' => 'fas fa-check',
|
||||
'deskripsi' => 'Pesanan telah diselesaikan oleh ' . auth()->user()->nama_depan . '.',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pesanan telah diselesaikan oleh ' . auth()->user()->nama_depan . '.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Gagal update status karena kesalahan server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function payTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
$code = substr($result['status_code'], 0, 1);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
if ($code == '4') {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di server.',
|
||||
'data' => $result,
|
||||
]);
|
||||
} else {
|
||||
if ($result['transaction_status'] == 'settlement') {
|
||||
$transaction = 'success';
|
||||
} elseif ($result['transaction_status'] == 'capture') {
|
||||
if ($result['fraud_status'] == 'accept') {
|
||||
$transaction = 'success';
|
||||
} elseif ($result['fraud_status'] == 'challenge') {
|
||||
$transaction = 'challenge';
|
||||
}
|
||||
} else {
|
||||
$transaction = 'failure';
|
||||
}
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'metode_pembayaran' => $result['payment_type'],
|
||||
'tanggal_transaksi' => $result['transaction_time'],
|
||||
'status_transaksi' => $transaction,
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'fraud_status' => $result['fraud_status'],
|
||||
'signature_key' => $result['signature_key'],
|
||||
]);
|
||||
|
||||
if ($transaction == 'success') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'success',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-money-bill',
|
||||
'deskripsi' => Auth::user()->nama_depan . ' telah sukses melakukan pembayaran. Transaksi diteruskan ke penjual.',
|
||||
'user' => auth()->user()->email,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pembayaran sukses',
|
||||
]);
|
||||
} elseif ($transaction == 'challenge') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'challenge',
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-clock',
|
||||
'deskripsi' => 'Transaksi ' . auth()->user()->email . ' terindikasi masalah, tunggu sesaat hingga admin menyetujui pembayaran.',
|
||||
'user' => 'admin@example.net',
|
||||
'keterangan' => $result['status_message'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Pembayaran ditunda hingga disetujui oleh admin.',
|
||||
]);
|
||||
} else {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'failure',
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Terjadi kegagalan pembayaran.',
|
||||
'user' => 'admin@example.net',
|
||||
'keterangan' => $result['status_message'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi pembayaran gagal',
|
||||
]);
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi pembayaran gagal.',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
|
||||
public function cancelTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->post('https://api.sandbox.midtrans.com/v2/' . $request->id . '/cancel');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
if (in_array($result['status_code'], ['412','401'])) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi gagal.',
|
||||
'data' => $result
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_transaksi' => 'failure',
|
||||
'status_pembayaran' => 'cancel'
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'cancel',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => auth()->user()->nama_depan . ' telah membatalkan transaksi.',
|
||||
'user' => auth()->user()->email,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Transaksi berhasil dibatalkan',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Transaksi gagal dibatalkan',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function pendingTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Pembayaran di-pending, silahkan masuk lagi dan bayar secepat mungkin.',
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di bagian server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function complaintTransaction($id)
|
||||
{
|
||||
return view('user.refund.new-refund', compact('id'));
|
||||
}
|
||||
|
||||
public function onErrorTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
]);
|
||||
|
||||
if ($result['transaction_status'] == 'expire') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'cancel',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Pembayaran sudah expire',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Pembayaran sudah expire, silahkan buat transaksi baru.',
|
||||
]);
|
||||
} elseif ($result['transaction'] == 'failure') {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'failure',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => auth()->user()->nama_depan . ' telah membatalkan transaksi.',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi kesalahan di server saat pembayaran.',
|
||||
'data' => $result,
|
||||
]);
|
||||
} else {
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => $result['transaction_status'],
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Status tidak diketahui',
|
||||
'user' => 'admin@example.net',
|
||||
'keterangan' => $result['status_message'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Terjadi kesalahan di server',
|
||||
'data' => $result,
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di bagian server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function onCloseTransaction(Request $request)
|
||||
{
|
||||
$auth = base64_encode(env('MIDTRANS_SERVER_KEY'));
|
||||
|
||||
$response = Http::withOptions([
|
||||
'verify' => false,
|
||||
])
|
||||
->withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Basic $auth",
|
||||
])
|
||||
->get('https://api.sandbox.midtrans.com/v2/' . $request->id . '/status');
|
||||
|
||||
$result = json_decode($response->body(), true);
|
||||
|
||||
$status = $result['transaction_status'] == null ? '' : $result['transaction_status'];
|
||||
|
||||
if ($status == '') {
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'On Close',
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
if ($result['transaction_status'] == 'expire') {
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'status_transaksi' => 'failure',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'cancel',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Pembayaran sudah expire',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Pembayaran sudah expire, silahkan buat transaksi baru.',
|
||||
]);
|
||||
} elseif ($result['transaction'] == 'failure') {
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'status_transaksi' => 'failure',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => 'failure',
|
||||
'background' => 'bg-buyer',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => auth()->user()->nama_depan . ' telah membatalkan transaksi.',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi kesalahan di server saat pembayaran.',
|
||||
]);
|
||||
} else {
|
||||
Transaction::where('id', $request->id)->update([
|
||||
'status_pembayaran' => $result['transaction_status'],
|
||||
'status_transaksi' => 'failure',
|
||||
]);
|
||||
|
||||
TransactionDescription::create([
|
||||
'transaction_id' => $request->id,
|
||||
'status' => $result['transaction_status'],
|
||||
'background' => 'bg-primary',
|
||||
'judul' => 'fas fa-exclamation',
|
||||
'deskripsi' => 'Status tidak diketahui.',
|
||||
'user' => 'admin@example.net',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Terjadi kesalahan di server',
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Terjadi error di bagian server.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function listPembeli(Request $request)
|
||||
{
|
||||
try{
|
||||
$subQuery = Transaction::join('users','transactions.penjual','=','users.email')
|
||||
->where('transactions.pembeli',auth()->user()->email)
|
||||
->select(
|
||||
'transactions.id',
|
||||
DB::raw("CONCAT(users.nama_depan,' ',users.nama_belakang) as nama_penjual"),
|
||||
'transactions.nama_barang',
|
||||
'transactions.total_harga',
|
||||
'transactions.created_at',
|
||||
'transactions.status_transaksi',
|
||||
'transactions.token'
|
||||
);
|
||||
|
||||
if($request->has('search') && !empty($request->search['value'])){
|
||||
$searchPembeli = $request->search['value'];
|
||||
if(!is_numeric($searchPembeli)){
|
||||
$subQuery->where(function($a) use ($searchPembeli){
|
||||
$a->whereRaw("LOWER(CONCAT(users.nama_depan,' ',users.nama_belakang)) LIKE ?",['%'.strtolower($searchPembeli).'%'])
|
||||
->orWhereRaw('LOWER(transactions.nama_barang) LIKE ?',['%'.strtolower($searchPembeli).'%'])
|
||||
->orWhereRaw('LOWER(transactions.status_transaksi) LIKE ?',['%'.strtolower($searchPembeli).'%']);
|
||||
});
|
||||
}else{
|
||||
$subQuery->where(function($a) use ($searchPembeli){
|
||||
$a->where('transactions.total_harga','=',$searchPembeli);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$queryPembeli = Transaction::from(DB::raw("({$subQuery->toSql()}) as tmp"))
|
||||
->mergeBindings($subQuery->getQuery()) // Menggabungkan binding parameters
|
||||
->select('*')
|
||||
->get();
|
||||
|
||||
if ($request->ajax()) {
|
||||
return DataTables::of($queryPembeli)
|
||||
->addIndexColumn()
|
||||
->addColumn('action', function ($row) {
|
||||
$url = route('user-pembeli.show', ['id' => $row->id]);
|
||||
$invoice = route('invoice.get',['id' => $row->id]);
|
||||
$html_code = '
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
....
|
||||
</button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$url.'">Detail</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$invoice.'">Invoice</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalTracking"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Tracking</a>
|
||||
</li>';
|
||||
|
||||
if($row->status_transaksi == 'created'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" id="bayar"
|
||||
data-id="'.$row->id.'"
|
||||
data-token="'.$row->token.'"
|
||||
href="#">Bayar</a>
|
||||
</li>
|
||||
<li><a href="#" data-id="'.$row->id.'"
|
||||
id="cancel" class="dropdown-item">Batal</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
if($row->status_transaksi == 'sent'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalFinish"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Selesaikan</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
$html_code .= '
|
||||
</ul>
|
||||
</div>';
|
||||
return $html_code;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
}catch(Throwable $e){
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json(['success' => false, 'message' => 'Terjadi Kesalahan pada sisi server']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function listPenjual(Request $request){
|
||||
try{
|
||||
$subQuery = Transaction::join('users','transactions.pembeli','=','users.email')
|
||||
->where('transactions.penjual',auth()->user()->email)
|
||||
->select(
|
||||
'transactions.id',
|
||||
DB::raw("CONCAT(users.nama_depan,' ',users.nama_belakang) as nama_pembeli"),
|
||||
'transactions.nama_barang',
|
||||
'transactions.total_harga',
|
||||
'transactions.created_at',
|
||||
'transactions.status_transaksi',
|
||||
);
|
||||
|
||||
if($request->has('search') && !empty($request->search['value'])){
|
||||
$searchPenjual = $request->search['value'];
|
||||
if(!is_numeric($searchPenjual)){
|
||||
$subQuery->where(function($a) use ($searchPenjual){
|
||||
$a->whereRaw("LOWER(CONCAT(users.nama_depan,' ',users.nama_belakang)) LIKE ?",['%'.strtolower($searchPenjual).'%'])
|
||||
->orWhereRaw('LOWER(transactions.nama_barang) LIKE ?',['%'.strtolower($searchPenjual).'%'])
|
||||
->orWhereRaw('LOWER(transactions.status_transaksi) LIKE ?',['%'.strtolower($searchPenjual).'%']);
|
||||
});
|
||||
}else{
|
||||
$subQuery->where(function($a) use ($searchPenjual){
|
||||
$a->whereDay('transactions.created_at', '=', $searchPenjual)
|
||||
->orWhereMonth('transactions.created_at', '=', $searchPenjual)
|
||||
->orWhereYear('transactions.created_at', '=', $searchPenjual)
|
||||
->orWhere('transactions.total_harga', '=', $searchPenjual);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$queryPenjual = Transaction::from(DB::raw("({$subQuery->toSql()}) as tmp"))
|
||||
->mergeBindings($subQuery->getQuery()) // Menggabungkan binding parameters
|
||||
->select('*')
|
||||
->get();
|
||||
|
||||
if ($request->ajax()) {
|
||||
return DataTables::of($queryPenjual)
|
||||
->addIndexColumn()
|
||||
->addColumn('action', function ($row) {
|
||||
$url = route('user-penjual.show', ['id' => $row->id]);
|
||||
$invoice = route('invoice.get',['id' => $row->id]);
|
||||
$html_code = '
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
....
|
||||
</button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$url.'">Detail</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$invoice.'">Invoice</a>
|
||||
</li>
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalTracking"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Tracking</a>
|
||||
</li>';
|
||||
|
||||
if($row->status_transaksi == 'success'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" id="processTransaction"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Proses Transaksi</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
if($row->status_transaksi == 'progress'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" id="sendOrder"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Kirim barang</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
|
||||
if($row->status_transaksi == 'sent'){
|
||||
$html_code .= '
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalOrderSent"
|
||||
data-id="'.$row->id.'"
|
||||
href="#">Barang sudah sampai</a>
|
||||
</li>
|
||||
';
|
||||
}
|
||||
$html_code .= '
|
||||
</ul>
|
||||
</div>';
|
||||
return $html_code;
|
||||
})
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
}catch(Throwable $e){
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return response()->json(['success' => false, 'message' => 'Terjadi Kesalahan pada sisi server']);
|
||||
}
|
||||
}
|
||||
|
||||
public function transactionTracking(Request $request){
|
||||
$data = TransactionDescription::where('transaction_id', $request->id)->get();
|
||||
|
||||
|
@ -278,6 +278,83 @@
|
||||
});
|
||||
});
|
||||
|
||||
$('#table-penjual').on('click', '#denyTransaction', function() {
|
||||
const id = $(this).data('id');
|
||||
const csrfToken = $('meta[name="csrf-token"]').attr('content');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Tolak Transaksi?',
|
||||
text: 'Apakah anda yakin untuk menolak transaksi ini?',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
cancelButtonText: 'Tunggu, lihat detail dahulu.',
|
||||
confirmButtonText: 'Ya, tolak transaksi.'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
const {
|
||||
value: complaint
|
||||
} = await Swal.fire({
|
||||
title: 'Tolak Transaksi?',
|
||||
inputLabel: 'Berikan alasan untuk menolak transaksi ini',
|
||||
input: 'text',
|
||||
inputPlaceholder: 'Cth: Salah penjual.'
|
||||
});
|
||||
|
||||
if (complaint) {
|
||||
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>',
|
||||
allowEscapeKey: false,
|
||||
allowOutsideClick: false,
|
||||
didOpen: () => {
|
||||
Swal.showLoading();
|
||||
}
|
||||
});
|
||||
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': csrfToken
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: "{{ route('user-penjual.deny') }}",
|
||||
type: 'PUT',
|
||||
data: {
|
||||
id: id,
|
||||
complaint: complaint
|
||||
},
|
||||
success: function(response) {
|
||||
Swal.fire({
|
||||
title: response.status ? 'Berhasil' :
|
||||
'Gagal',
|
||||
text: response.message,
|
||||
icon: response.status ? 'success' :
|
||||
'error',
|
||||
}).then(function() {
|
||||
Swal.close();
|
||||
if (response.status) {
|
||||
listPenjual.ajax.reload();
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(error) {
|
||||
Swal.fire({
|
||||
title: 'Gagal',
|
||||
text: 'Pemrosesan transaksi gagal',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Swal.close();
|
||||
}
|
||||
} else {
|
||||
location.href = "{{ route('user-transaction.show', ':id') }}".replace(':id',
|
||||
id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#table-penjual').on('click', '#sendOrder', function() {
|
||||
const id = $(this).data('id');
|
||||
const csrfToken = $('meta[name="csrf-token"]').attr('content');
|
||||
|
@ -17,12 +17,12 @@
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-10">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-center bg-primary text-white">
|
||||
<img class="mr-3 rounded" width="150"
|
||||
src="{{ asset('assets/images/google-removebg-preview.png') }}">
|
||||
<div class="card-header d-flex justify-content-center bg-primary text-white font-weight-bold"
|
||||
style="font-size: 36px; margin-bottom: -10px;">
|
||||
REKBER
|
||||
</div>
|
||||
<div class="d-flex justify-content-center bg-primary text-white">
|
||||
<h2 class="mb-0">Verifikasi Email</h2>
|
||||
<p class="mb-3">Verifikasi Email</p>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
|
@ -22,6 +22,8 @@ use App\Http\Controllers\Profile\ProfileController;
|
||||
|
||||
//Invoice
|
||||
use App\Http\Controllers\Invoice\InvoiceController;
|
||||
use App\Http\Controllers\User\PembeliController;
|
||||
use App\Http\Controllers\User\PenjualController;
|
||||
|
||||
// use Illuminate\Foundation\Auth\User;
|
||||
|
||||
@ -77,6 +79,8 @@ Route::controller(LoginController::class)->group(function(){
|
||||
Route::get('cari-kelurahan','searchVillage')->name('cari-kelurahan');
|
||||
Route::post('kode-verifikasi','sendVerificationCode')->name('kirim-kode');
|
||||
Route::get('ocr','getOcr');
|
||||
Route::get('email','email');
|
||||
Route::get('test-invoice','invoice');
|
||||
});
|
||||
|
||||
// admin dan user
|
||||
@ -157,7 +161,6 @@ Route::middleware(['auth'])->group(function(){
|
||||
Route::get('user-contact','index')->name('user-contact.index');
|
||||
Route::get('user-contact/list-contact','listContact')->name('user-contact.list-contact');
|
||||
Route::post('user-contact','store')->name('user-contact.store');
|
||||
Route::get('admin-contact/{id}','show')->name('admin-contact.show');
|
||||
Route::delete('user-contact/delete','destroy')->name('user-contact.destroy');
|
||||
Route::get('user-contact/get-user-contact','getContact')->name('user-contact.get');
|
||||
Route::get('user-contact/cek-contact','cekEmail')->name('user-contact.email');
|
||||
@ -166,10 +169,14 @@ Route::middleware(['auth'])->group(function(){
|
||||
|
||||
// Tampilan transaksi, bayar, update status pengiriman dan refund
|
||||
Route::controller(UserTransactionController::class)->group(function(){
|
||||
// Pembeli
|
||||
Route::get('transaction-tracking','transactionTracking')->name('user.transaction-tracking');
|
||||
Route::get('user-transaction/detail-transaksi/{id}','show')->name('user-transaction.show');
|
||||
});
|
||||
|
||||
// Pembeli
|
||||
Route::controller(PenjualController::class)->group(function(){
|
||||
Route::get('user-pembeli','indexPembeli')->name('user-pembeli.index');
|
||||
Route::get('user-pembeli/list-pembeli','listPembeli')->name('user-pembeli.list-pembeli');
|
||||
Route::get('user-pembeli/detail-transaksi/{id}','show')->name('user-pembeli.show');
|
||||
Route::get('user-pembeli/tambah-transaksi','create')->name('user-pembeli.create');
|
||||
Route::post('user-pembeli','store')->name('user-pembeli.store');
|
||||
Route::put('user-pembeli/bayar-transaksi','payTransaction')->name('user-pembeli.pay');
|
||||
@ -179,17 +186,16 @@ Route::middleware(['auth'])->group(function(){
|
||||
Route::put('user-pembeli/transaksi-close','onCloseTransaction')->name('user-pembeli.close');
|
||||
Route::put('user-pembeli/transaksi-selesai','finishTransaction')->name('user-pembeli.finish');
|
||||
Route::put('user-pembeli/transaksi-komplain/{id}','complaintTransaction')->name('user-pembeli.complain');
|
||||
});
|
||||
|
||||
//Penjual
|
||||
// Penjual
|
||||
Route::controller(PembeliController::class)->group(function(){
|
||||
Route::get('user-penjual','indexPenjual')->name('user-penjual.index');
|
||||
Route::get('user-penjual/list-penjual','listPenjual')->name('user-penjual.list-penjual');
|
||||
Route::get('user-penjual/detail-transaksi/{id}','show')->name('user-penjual.show');
|
||||
Route::get('user-penjual/tolak-transaksi','denyTransaction')->name('user-penjual.deny');
|
||||
Route::put('user-penjual/terima-transaksi','acceptTransaction')->name('user-penjual.accept');
|
||||
Route::put('user-penjual/kirim-pesanan','sendingOrder')->name('user-penjual.sending');
|
||||
Route::post('user-penjual/selesai-kirim-pesanan','sentOrder')->name('user-penjual.sent');
|
||||
|
||||
Route::get('transaction-tracking','transactionTracking')->name('user.transaction-tracking');
|
||||
});
|
||||
|
||||
// Tampilan refund
|
||||
|
Loading…
Reference in New Issue
Block a user