Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
complete rent process
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina committed May 16, 2022
1 parent 9bbc90f commit 0fe8498
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 21 deletions.
116 changes: 116 additions & 0 deletions app/Http/Controllers/RentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Illuminate\Support\Facades\DB;

use Illuminate\Support\Facades\Http;

use App\Models\Vehicle;

use App\Models\Order;
Expand Down Expand Up @@ -134,6 +136,120 @@ public function getPaymentDetails($id)
$method = request()->input('method') ? request()->input('method') : 'BCA Transfer';
$order = Order::find($id);

if($order->transaction_id) {
return redirect()->route('confirm-payment', [$order->id])->with('order', $order);
}

return view('payment-details', ['order' => $order, 'selected_method' => $method]);
}

public function getVirtualAccount($id)
{
$method = request()->input('method');
$order = Order::find($id);

$AUTH_STRING = "Basic " . base64_encode(env('MIDTRANS_SERVER_KEY') . ":");

$payment_type = array(
"BCA Transfer" => "bank_transfer",
"BNI Transfer" => "bank_transfer",
"BRI Transfer" => "bank_transfer",
"Mandiri Transfer" => "echannel",
"Permata Transfer" => "permata",
"Shopee Pay" => "gopay",
"Dana" => "gopay",
"OVO" => "gopay",
"GoPay" => "gopay"
);

$req_body = [
"payment_type" => $payment_type[$method],
"transaction_details" => [
"order_id" => $order->id,
"gross_amount" => $order->total_price,
]
];

if($payment_type[$method] == 'bank_transfer') {
$req_body['bank_transfer']['bank'] = explode(' ', strtolower($method))[0];
}

if($payment_type[$method] == 'echannel') {
$req_body['echannel']['bill_info1'] = $order->id;
$req_body['echannel']['bill_info2'] = $order->total_price;
}

$response = Http::withHeaders([
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => $AUTH_STRING
])
->withBody(json_encode($req_body), 'application/json')
->post('https://api.sandbox.midtrans.com/v2/charge');

$response = $response->json();

if($response['status_code'] == '201') {
if($payment_type[$method] == 'bank_transfer') {
$order->virtual_account = $response['va_numbers'][0]['va_number'];
} else if ($payment_type[$method] == 'echannel') {
$order->virtual_account = $response['bill_key'] . ' ' . $response['bill_code'];
} else if ($payment_type[$method] == 'gopay') {
$order->qr_link = $response['actions'][0]['url'];
$order->deep_link = $response['actions'][1]['url'];
} else {
$order->virtual_account = $response->json()['permata_va_number'];
}

$order->transaction_id = $response['transaction_id'];
$payment_expiry_time = new DateTime();
$payment_expiry_time->modify('+1 day');
$order->payment_expiry_time = $payment_expiry_time->format('Y-m-d H:i:s');
$order->payment_method = $method;
}

$order->save();

if($order->transaction_id) {
return redirect()->route('confirm-payment', ['id' => $order->id]);
} else {
return redirect()->route('payment-details', ['id' => $order->id])->with('error', 'Something went wrong. Please try again later.');
}
}

public function getConfirmPayment($id)
{
$order = Order::find($id);

if($order->transaction_id) {
return view('confirm-payment', ['order' => $order]);
} else {
return redirect()->route('payment-details', ['id' => $order->id]);
}
}

public function checkPayment($id) {
$order = Order::find($id);

$AUTH_STRING = "Basic " . base64_encode(env('MIDTRANS_SERVER_KEY') . ":");

$response = Http::withHeaders([
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => $AUTH_STRING
])
->get('https://api.sandbox.midtrans.com/v2/' . $order->transaction_id . '/status');

$response = $response->json();

if($response['status_code'] == '200') {
if($response['transaction_status'] == 'settlement') {
$order->order_status = 'PAYMENT_DONE';
}
}

$order->save();

return redirect()->route('user-orders');
}
}
32 changes: 32 additions & 0 deletions database/migrations/2022_05_16_174019_update_orders_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('orders', function (Blueprint $table) {
$table->timestamp('payment_expiry_time')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn('payment_expiry_time');
});
}
};
4 changes: 4 additions & 0 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,10 @@ select {
margin-top: 5rem;
margin-bottom: 5rem;
}
.my-24 {
margin-top: 6rem;
margin-bottom: 6rem;
}
.ml-3 {
margin-left: 0.75rem;
}
Expand Down
Binary file added public/images/logo-permata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions public/js/navbar_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var showButton = document.getElementById('rent-button');
var showMenu = document.getElementById('rent-menu');
var toggleMenu = document.getElementById('menu-toggle');
var menuList = document.getElementById('menu-list');
var menuOption = document.getElementsByClassName('rent-menu-option');
var menuOption = document.getElementsByClassName('menu-option');

toggleMenu.onclick = function (event) {
event.preventDefault();
Expand All @@ -17,7 +17,7 @@ toggleMenu.onclick = function (event) {
menuOption[0].onclick = function (event) {
event.preventDefault();

if (menuOption[0].innerHTML == 'Rent Car') {
if (menuOption[0].innerHTML.trim() == 'Rent Car') {
window.location.href = window.location.origin + '/find/car';
} else {
window.location.href = window.location.origin + '/dashboard/vehicles/car';
Expand All @@ -27,7 +27,7 @@ menuOption[0].onclick = function (event) {
menuOption[1].onclick = function (event) {
event.preventDefault();

if (menuOption[0].innerHTML == 'Rent Car') {
if (menuOption[1].innerHTML.trim() == 'Rent Motorcycle') {
window.location.href = window.location.origin + '/find/motor';
} else {
window.location.href = window.location.origin + '/dashboard/vehicles/motor';
Expand Down
6 changes: 3 additions & 3 deletions resources/js/navbar_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const showButton = document.getElementById('rent-button');
const showMenu = document.getElementById('rent-menu');
const toggleMenu = document.getElementById('menu-toggle');
const menuList = document.getElementById('menu-list');
const menuOption = document.getElementsByClassName('rent-menu-option');
const menuOption = document.getElementsByClassName('menu-option');

toggleMenu.onclick = (event) => {
event.preventDefault();
Expand All @@ -11,7 +11,7 @@ toggleMenu.onclick = (event) => {

menuOption[0].onclick = (event) => {
event.preventDefault();
if(menuOption[0].innerHTML == 'Rent Car') {
if(menuOption[0].innerHTML.trim() == 'Rent Car') {
window.location.href = window.location.origin + '/find/car';
} else {
window.location.href = window.location.origin + '/dashboard/vehicles/car';
Expand All @@ -20,7 +20,7 @@ menuOption[0].onclick = (event) => {

menuOption[1].onclick = (event) => {
event.preventDefault();
if(menuOption[0].innerHTML == 'Rent Car') {
if(menuOption[1].innerHTML.trim() == 'Rent Motorcycle') {
window.location.href = window.location.origin + '/find/motor';
} else {
window.location.href = window.location.origin + '/dashboard/vehicles/motor';
Expand Down
6 changes: 3 additions & 3 deletions resources/views/components/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
@if($isRent($key) || $isProduct($key))
<img src="{{ asset('images/down-arrow.svg') }}" class="inline-block w-5 ml-3 pl-1">
<div id="rent-menu" class="rent-menu z-10 hidden absolute w-40 font-normal bg-white">
<div class="rent-menu-option px-2 py-1 bg-gray hover:bg-lilac-100 hover:text-white">
{{ $isRent($key) ? 'Rent Car' : 'Car' }}
<div class="menu-option px-2 py-1 bg-gray hover:bg-lilac-100 hover:text-white">
{{$isRent($key) ? 'Rent Car' : 'Car'}}
</div>
<div class="rent-menu-option px-2 py-1 bg-gray hover:bg-lilac-100 hover:text-white">
<div class="menu-option px-2 py-1 bg-gray hover:bg-lilac-100 hover:text-white">
{{ $isRent($key) ? 'Rent Motorcycle' : 'Motorcycle' }}
</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions resources/views/confirm-payment.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<x-base-layout>
<x-base-body selected="My order">
<div class="mt-24 mx-20">
<h2 class="font-bold text-3xl text-lilac-100">Konfirmasi Pembayaran</h2>
</div>
<div class="flex justify-center">
<div class="w-full max-w-7xl shadow rounded-lg p-10 my-6">
<p>Order ID : {{ $order->id }}</p>
<p>Name : {{ auth()->user()->name }}</p>
<p>Email : {{ auth()->user()->email }}</p>
<p>Total Price : {{ $order->total_price }}</p>
<p>Payment Status : {{ $order->payment_status }}</p>
<p>Payment Method : {{ $order->payment_method }}</p>
<p>Pay Before : {{ $order->payment_expiry_time }}</p>
<p>Virtual Account : {{ $order->virtual_account }}</p>
<a href="{{ route('check-payment', [$order->id]) }}">
<x-button filled="true">Konfirmasi Pembayaran</x-button>
</a>
</div>
</div>
</x-base-body>
</x-base-layout>
25 changes: 13 additions & 12 deletions resources/views/payment-details.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<x-base-layout>
<x-base-body selected="Rent">
<div class="mt-24 mx-20">
<div class="mt-24 mx-10">
<h2 class="font-bold text-3xl text-lilac-100">Select Payment</h2>
<p class="text-lilac-100">Order ID: {{ $order->id }}</p>
<p class="text-lilac-100">Customer: {{ auth()->user()->name }}</p>
<p class="text-lilac-100">Order ID : {{ $order->id }}</p>
<p class="text-lilac-100">Customer : {{ auth()->user()->name }}</p>
</div>
<div class="mx-10 mt-20 mb-24 flex">
<div class="mx-10 my-10 flex">
<div class="w-60 text-sm font-medium text-gray-900 bg-white rounded-lg">
<p aria-current="true" class="block w-full px-4 py-2 text-white font-bold bg-lilac-300">
BANK TRANSFER
</p>
<?php $method = array('BCA Transfer' => 'bca', 'Mandiri Tranfer' => 'mandiri', 'BNI Transfer' => 'bni', 'BRI Transfer' => 'bri') ?>
@foreach($method as $key => $value)
<?php $bank_method = array('BCA Transfer' => 'bca', 'Mandiri Transfer' => 'mandiri', 'BNI Transfer' => 'bni', 'BRI Transfer' => 'bri', 'Permata Transfer' => 'permata') ?>
@foreach($bank_method as $key => $value)
<a href="{{ route('payment-details', [ $order->id, 'method' => $key]) }}" class="block w-full px-4 py-2 cursor-pointer {{ $selected_method == $key ? 'bg-white text-lilac-100' : 'bg-lilac-200 text-white' }} hover:bg-lilac-300 focus:outline-none focus:ring-2 focus:ring-blue-700">
<img src="{{ asset('images/logo-'. $value . '.png') }}" class="inline h-8 mr-2">
{{ $key }}
Expand All @@ -20,8 +20,8 @@
<p aria-current="true" class="block w-full px-4 py-2 text-white font-bold bg-lilac-300 ">
TRANSFER E-WALLET
</p>
<?php $method = array('ShopeePay' => 'shopeepay', 'DANA' => 'dana', 'Gopay' => 'gopay', 'OVO' => 'ovo') ?>
@foreach($method as $key => $value)
<?php $ewallet_method = array('ShopeePay' => 'shopeepay', 'DANA' => 'dana', 'Gopay' => 'gopay', 'OVO' => 'ovo') ?>
@foreach($ewallet_method as $key => $value)
<a href="{{ route('payment-details', [ $order->id, 'method' => $key]) }}" class="block w-full px-4 py-2 cursor-pointer {{ $selected_method == $key ? 'bg-white text-lilac-100' : 'bg-lilac-200 text-white' }} hover:bg-lilac-300 focus:outline-none focus:ring-2 focus:ring-blue-700">
<img src="{{ asset('images/logo-'. $value . '.png') }}" class="inline h-8 mr-2">
{{ $key }}
Expand All @@ -30,34 +30,35 @@
</div>
<div class="w-full max-w-5xl shadow p-10">
<h2 class="font-bold text-3xl text-lilac-100 mb-2">{{ $selected_method }} Payment</h2>
@if(in_array($selected_method, array_keys($bank_method)))
<div class="bg-lilac-400 text-lilac-100 text-sm p-2 rounded-md border border-lilac-100">
<svg class="inline mx-1" width="18" height="18" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M15 1.875C7.75195 1.875 1.875 7.75195 1.875 15C1.875 22.248 7.75195 28.125 15 28.125C22.248 28.125 28.125 22.248 28.125 15C28.125 7.75195 22.248 1.875 15 1.875ZM15.9375 21.3281C15.9375 21.457 15.832 21.5625 15.7031 21.5625H14.2969C14.168 21.5625 14.0625 21.457 14.0625 21.3281V13.3594C14.0625 13.2305 14.168 13.125 14.2969 13.125H15.7031C15.832 13.125 15.9375 13.2305 15.9375 13.3594V21.3281ZM15 11.25C14.632 11.2425 14.2816 11.091 14.024 10.8281C13.7664 10.5652 13.6222 10.2118 13.6222 9.84375C13.6222 9.47568 13.7664 9.12228 14.024 8.85938C14.2816 8.59647 14.632 8.44501 15 8.4375C15.368 8.44501 15.7184 8.59647 15.976 8.85938C16.2336 9.12228 16.3778 9.47568 16.3778 9.84375C16.3778 10.2118 16.2336 10.5652 15.976 10.8281C15.7184 11.091 15.368 11.2425 15 11.25Z" fill="#9395DE"/>
</svg>
You can transfer from any banking service (m-banking, SMS banking or ATM)
</div>
@endif
<div class="m-10">
<p class="font-bold">PRICING DETAILS</p>
<div class="grid lg:grid-rows-2 lg:grid-cols-2 my-2 gap-y-2">
<p>Honda Scoopy Smart Key x1</p>
<p>IDR 100000</p>
<p>IDR {{ $order->total_price - 4500 }}</p>
<p>Service Fee</p>
<p>IDR 4500</p>
</div>
<hr>
<div class="grid lg:grid-rows-1 lg:grid-cols-2 my-2">
<p>Total Price</p>
<p>IDR 100000</p>
<p>IDR {{ $order->total_price }}</p>
</div>
<hr>
</div>
<div class="m-10 flex justify-end">
<a href="">
<a href="{{ route('get-virtual-account', [$order->id, 'method' => $selected_method ]) }}">
<x-button filled="true"> Pay with {{ $selected_method }} </x-button>
</a>
</div>
</div>

</div>
</x-base-body>
</x-base-layout>
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
Route::get('/rent/motor/{id}', [RentController::class, 'getRentForm']);
Route::post('/rent/{type}/{id}', [RentController::class, 'rentVehicle'])->where('type', '\b(motor|car)\b');
Route::get('/me/order/{id}/pay', [RentController::class, 'getPaymentDetails'])->name('payment-details');
Route::get('/me/order/{id}/va', [RentController::class, 'getVirtualAccount'])->name('get-virtual-account');
Route::get('/me/order/{id}/confirm', [RentController::class, 'getConfirmPayment'])->name('confirm-payment');
Route::get('/me/order/{id}/check', [RentController::class, 'checkPayment'])->name('check-payment');
});

Route::middleware(['auth', 'admin.authenticated'])-> group(function () {
Expand Down

0 comments on commit 0fe8498

Please sign in to comment.