Skip to content

Commit 21bf8bc

Browse files
committed
Update payment success
1 parent 873298b commit 21bf8bc

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

app/Http/Controllers/User/CheckoutController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function store(Store $request, Camp $camp)
6969
$user->email = $data['email'];
7070
$user->name = $data['name'];
7171
$user->occupation = $data['occupation'];
72+
$user->phone = $data['phone'];
7273
$user->save();
7374

7475
// create checkout
@@ -143,7 +144,7 @@ public function success(Checkout $checkout)
143144
public function getSnapRedirect(Checkout $checkout)
144145
{
145146
$orderId = $checkout->id.'-'.Str::random(5);
146-
$price = $checkout->Camp->price = 1000;
147+
$price = $checkout->Camp->price * 1000;
147148
$checkout->midtrans_booking_code = $orderId;
148149

149150
$transaction_details = [
@@ -155,7 +156,7 @@ public function getSnapRedirect(Checkout $checkout)
155156
'id' => $orderId,
156157
'price' => $price,
157158
'quantity' => 1,
158-
'name' => 'Payment for {$checkout->Camp->title}'
159+
'name' => "Payment for {$checkout->Camp->title}"
159160
];
160161

161162
$userData = [
@@ -164,7 +165,7 @@ public function getSnapRedirect(Checkout $checkout)
164165
'address' => '',
165166
'city' => '',
166167
'postal_code' => '',
167-
'phone' => '$checkout->User->phone',
168+
'phone' => $checkout->User->phone,
168169
'country_code' => "IDN"
169170
];
170171

@@ -185,7 +186,7 @@ public function getSnapRedirect(Checkout $checkout)
185186

186187
try {
187188
//Get Snap Payment Page URL
188-
$paymentUrl = \Midtrans\Snap::createTransaction($params)->redirect_url;
189+
$paymentUrl = \Midtrans\Snap::createTransaction($midtrans_params)->redirect_url;
189190
$checkout->midtrans_url = $paymentUrl;
190191
$checkout->save();
191192

@@ -197,7 +198,7 @@ public function getSnapRedirect(Checkout $checkout)
197198

198199
public function midtransCallback(Request $request)
199200
{
200-
$notif = new Midtrans\Notification();
201+
$notif = $request->method() == 'POST' ? new Midtrans\Notification() : Midtrans\Transaction::status($request->order_id);
201202

202203
$transaction_status = $notif->transaction_status;
203204
$fraud = $notif->fraud_status;

app/Http/Middleware/VerifyCsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
1212
* @var array<int, string>
1313
*/
1414
protected $except = [
15-
//
15+
'payment/success'
1616
];
1717
}

database/migrations/2023_02_03_141102_add_phone_number.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AddPhoneNumber extends Migration
1414
public function up()
1515
{
1616
Schema::table('users', function (Blueprint $table) {
17-
$table->string('phone', 1)->nullable()->after('occupation');
17+
$table->string('phone', 15)->nullable()->after('occupation');
1818
});
1919
}
2020

resources/views/layouts/app.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626

2727
<!-- -->
2828
<!-- -->
29-
<script src="{{asset('frontend/js/bootstrap.bundle.min.js')}}"></script>
29+
<script src="{{asset('frontend/js/bootstrap.bundle.min.js')}}" defer></script>
3030
</body>
3131
</html>

routes/web.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
Route::get('auth/google/callback', [UserController::class, 'handleProviderCallback'])->name('user.google.callback');
3434

3535
// midtrans routes
36-
Route::get('payment/success', [UserController::class, 'midtransCallback']);
37-
Route::post('payment/success', [UserController::class, 'midtransCallback']);
36+
Route::get('payment/success', [CheckoutController::class, 'midtransCallback']);
37+
Route::post('payment/success', [CheckoutController::class, 'midtransCallback']);
3838

3939
Route::middleware('auth')->group(function(){
4040
// Checkout routes

0 commit comments

Comments
 (0)