Skip to content

Commit

Permalink
fix order id
Browse files Browse the repository at this point in the history
  • Loading branch information
AndikaHilmiHamdani committed Apr 30, 2022
1 parent 9d0ed2e commit 0b79930
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 8 additions & 6 deletions app/Http/Controllers/MidtransController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ public function paymentgateway(Request $request)
$this->initMidtrans();

$snapToken = '';
$order = Order::create();
$order->save();
$orderId = rand();

$params = array(
'transaction_details' => array(
'order_id' => $order->id,
'order_id' => $orderId,
'gross_amount' => $totalPrice,
),

Expand Down Expand Up @@ -79,8 +78,11 @@ public function paymentgateway(Request $request)

$snapToken = \Midtrans\Snap::getSnapToken($params);

$order->menu = $input;
$order->total_price = $totalPrice;
$order = Order::create([
"menu" => json_encode($input),
"total_price" => $totalPrice,
"order_id" => $orderId,
]);
$order->save();

return view('users.kasir.checkout', ['snapToken' => $snapToken]);
Expand All @@ -96,7 +98,7 @@ public function store(Request $request)
$transaction_time = $request->get('transaction_time');
// $signature_key = $request->get('signature_key');

$order = Order::find($order_id)->firstOrFail();
$order = Order::where('order_id', $order_id)->firstOrFail();
$order->va_numbers = $va_numbers;
$order->transaction_id = $transaction_id;
$order->transaction_status = $transaction_status;
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class Order extends Model
public $timestamps = false;
protected $primaryKey = 'id'; // Memanggil isi DB Dengan primarykey
protected $fillable = [
'transaction_id',
'order_id',
'menu',
'total_price',
'transaction_id',
'payment_type',
'transaction_time',
'transaction_status',
Expand Down
5 changes: 3 additions & 2 deletions database/migrations/2022_04_22_211254_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public function up()
Schema::create('order', function (Blueprint $table) {
$table->id();
//item detail
$table->unsignedBigInteger('order_id');
$table->json('menu');
$table->unsignedInteger('total_price');
$table->string('transaction_id')->nullable();
$table->json('menu')->nullable();
$table->unsignedInteger('total_price')->nullable();
$table->string('payment_type')->nullable();
$table->timestamp('transaction_time')->nullable();
$table->string('transaction_status')->nullable();
Expand Down

0 comments on commit 0b79930

Please sign in to comment.