-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e57a306
commit b7581ec
Showing
9 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
use Exception; | ||
|
||
use Midtrans\Snap; | ||
use Midtrans\Config; | ||
|
||
use App\Cart; | ||
use App\Transaction; | ||
use App\TransactionDetail; | ||
use App\User; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class CheckoutController extends Controller | ||
{ | ||
public function process(Request $request){ | ||
$user = Auth::user(); | ||
$user->update($request->except('total_price')); | ||
|
||
//proses checkout | ||
$code = 'STORE-' . mt_rand(00000,99999); | ||
$carts = Cart::with(['product','user'])->where('users_id',Auth::user()->id)->get(); | ||
|
||
$transaction = Transaction::create([ | ||
'users_id' => Auth::user()->id, | ||
'insurance_price' => 0, | ||
'shipping_price' => 0, | ||
'total_price' => $request->total_price, | ||
'transaction_status' => 'PENDING', | ||
'code' => $code | ||
]); | ||
|
||
foreach ($carts as $cart) { | ||
$trx = 'TRX-' . mt_rand(00000,99999); | ||
|
||
TransactionDetail::create([ | ||
'transactions_id' => $transaction->id, | ||
'products_id' => $cart->product->id, | ||
'price' => $cart->product->price, | ||
'shipping_status' => 'PENDING', | ||
'resi' => '', | ||
'code' => $trx | ||
]); | ||
} | ||
//konfig midtrans | ||
|
||
Config::$serverKey = config('services.midtrans.serverKey'); | ||
Config::$isProduction = config('services.midtrans.isProduction'); | ||
Config::$isSanitized = config('services.midtrans.isSanitized'); | ||
Config::$is3ds = config('services.midtrans.is3ds'); | ||
|
||
//buat array to send midtrans | ||
$midtrans = [ | ||
'transaction_detail' => [ | ||
'order_id' => $code, | ||
'gross_amount' => (int) $request->total_price, | ||
], | ||
'customer_detail' => [ | ||
'first_name' => Auth::user()->name, | ||
'email' => Auth::user()->email, | ||
], | ||
'enabled_payments' => [ | ||
'gopay', 'bni_va','bank_transfer' | ||
], | ||
'vtweb' => [] | ||
]; | ||
try { | ||
// Get Snap Payment Page URL | ||
$paymentUrl = Snap::createTransaction($midtrans)->redirect_url; | ||
|
||
// Redirect to Snap Payment Page | ||
return redirect($paymentUrl); | ||
} | ||
catch (Exception $e) { | ||
echo $e->getMessage(); | ||
} | ||
} | ||
|
||
public function callback(Request $request){ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class TransactionDetail extends Model | ||
{ | ||
protected $fillable = [ | ||
'transactions_id', 'products_id', 'price', 'shipping_status', 'resi', 'code' | ||
]; | ||
|
||
protected $hidden = [ | ||
|
||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters