From ceb5cf414efff9c3813b798ac98e22c760f2ee71 Mon Sep 17 00:00:00 2001 From: Raihan Surya Date: Mon, 6 Nov 2023 14:52:21 +0700 Subject: [PATCH] Perbaiki dashboard admin --- .../Admin/AdminDashboardController.php | 14 ++++++------ .../User/UserTransactionController.php | 22 +++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Admin/AdminDashboardController.php b/app/Http/Controllers/Admin/AdminDashboardController.php index eec0688..183c74a 100644 --- a/app/Http/Controllers/Admin/AdminDashboardController.php +++ b/app/Http/Controllers/Admin/AdminDashboardController.php @@ -19,22 +19,22 @@ class AdminDashboardController extends Controller $currentMonth = Carbon::now()->month; $currentYear = Carbon::now()->year; - $countSuccess = Transaction::where('status', 'settlement') + $countSuccess = Transaction::where('status_pembayaran', 'settlement') ->whereMonth('updated_at', $currentMonth) ->whereYear('updated_at', $currentYear) ->count(); - $countPending = Transaction::where('status', 'pending') + $countPending = Transaction::where('status_pembayaran', 'pending') ->whereMonth('updated_at', $currentMonth) ->whereYear('updated_at', $currentYear) ->count(); - $countCancelled = Transaction::where('status', 'cancel') + $countCancelled = Transaction::where('status_pembayaran', 'cancel') ->whereMonth('updated_at', $currentMonth) ->whereYear('updated_at', $currentYear) ->count(); - $countRefund = Transaction::where('status', 'refund') + $countRefund = Transaction::where('status_pembayaran', 'refund') ->whereMonth('updated_at', $currentMonth) ->whereYear('updated_at', $currentYear) ->count(); @@ -46,7 +46,7 @@ class AdminDashboardController extends Controller $dataChartTransaction = []; $dataChartRefund = []; - $totalRefund = Transaction::where('status', 'refund')->count(); + $totalRefund = Transaction::where('status_pembayaran', 'refund')->count(); $dataChartTotalRefund = []; $totalUser = User::where('status', 'Finished')->count(); @@ -55,12 +55,12 @@ class AdminDashboardController extends Controller for ($bulan = 1; $bulan <= 12; $bulan++) { $transaction = Transaction::whereMonth('updated_at', $bulan) ->whereYear('updated_at', $currentYear) - ->where('status', 'settlement') + ->where('status_pembayaran', 'settlement') ->sum('total_bayar'); $refund = Transaction::whereMonth('updated_at', $bulan) ->whereYear('updated_at', $currentYear) - ->where('status', 'partial refund') + ->where('status_pembayaran', 'refund') ->sum('total_harga'); $dataChartTransaction[] = intval($transaction); diff --git a/app/Http/Controllers/User/UserTransactionController.php b/app/Http/Controllers/User/UserTransactionController.php index 25671f2..ae86f7a 100644 --- a/app/Http/Controllers/User/UserTransactionController.php +++ b/app/Http/Controllers/User/UserTransactionController.php @@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Ramsey\Uuid\Uuid; +use GuzzleHttp\Client; use Stichoza\GoogleTranslate\GoogleTranslate; use Throwable; @@ -194,15 +195,23 @@ class UserTransactionController extends Controller 'enabled_payments' => ['credit_card', 'gopay', 'qris'], ]; + $client = new Client(); + $auth = base64_encode(env('MIDTRANS_SERVER_KEY')); - $response = Http::withHeaders([ - 'Content-Type' => 'application/json', - 'Authorization' => "Basic $auth", - ])->post('https://app.sandbox.midtrans.com/snap/v1/transactions', $params); + $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 = $response->getBody(); Transaction::where('id', $query->id)->update([ - 'token' => $response['token'], + 'token' => $result['token'], ]); $contact = Contact::where('pemilik_kontak', $pembeli) @@ -561,11 +570,10 @@ class UserTransactionController extends Controller $result = json_decode($response->body(), true); try { - DB::beginTransaction(); Transaction::where('id', $request->id)->update([ - 'status_pembayaran' => $result['transaction_status'] + 'status_pembayaran' => $result['transaction_status'], ]); DB::commit();