Hi Tweakers,
Ik ben eigenlijk een webshop aan het opzetten in Laravel in combinatie met vueJS.
Maar helaas krijg ik een foutmelding op het moment dat ik mijn aankoop wil finaliseren
Foutmelding die te lezen is vanout de console:
Hier de vue.JS component:
Hier de PHP componenten:
Ik denk eerder dat het probleem heeft te maken met de url link. Maar helaas heb ik meer dan 10 al de url link gecontroleerd in de php router root, maar daar is ook geen spelfouten te vinden.
zo ziet mijn php router eruit:
Ik ben eigenlijk een webshop aan het opzetten in Laravel in combinatie met vueJS.
Maar helaas krijg ik een foutmelding op het moment dat ik mijn aankoop wil finaliseren
Foutmelding die te lezen is vanout de console:
code:
1
| [Vue warn]: Error in v-on handler (Promise/async): "Error: Request failed with status code 500" |
Hier de vue.JS component:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
| <script> export default { data() { return { items: [], firstName: '', lastName: '', address: '', city: '', zipCode:'', email:'', phone:'', country:'', cardType:'', expirationMonth: '', expirationYear: '', cvv:'', cardNumber:'', } }, methods: { async getCartItems() { let response = await axios.get("/checkout/get/items"); this.items = response.data; console.log(this.items); }, async getUserAddress(){ if(this.firstName != '' && this.address != '' && this.cardNumber && this.cvv) { // Process payment. let response = await axios.post('/process/user/payment', { 'firstName':this.firstName, 'lastName':this.lastName, 'address':this.address, 'city':this.city, 'zipCode':this.zipCode, 'email':this.email, 'phone':this.phone, 'country':this.country, 'cardType':this.cardType, 'expirationMonth':this.expirationMonth, 'expirationYear':this.expirationYear, 'cvv':this.cvv, 'cardNumber':this.cardNumber, 'amount': this.items.totalAmount, 'order': this.items, }); if(response.data.message == 'success') { this.$toastr.s(response.data.success) } else{ this.$toastr.e(response.data.error); } setTimeout(()=> { window.location.href='/'; }, 1500); console.log(response.data); } else{ this.$toastr.e('User info incomplete'); } console.log(response); } }, created() { this.getCartItems(); } }; </script> |
Hier de PHP componenten:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
| public function processPayment(Request $request) { dd($request->all()); $firstName = $request->get('firstName'); $lastName = $request->get('lastName'); $address = $request->get('address'); $city = $request->get('city'); $zipCode = $request->get('zipCode'); $email = $request->get('email'); $phone = $request->get('phone'); $country = $request->get('country'); $cardType = $request->get('cardType'); $expirationMonth = $request->get('expirationMonth'); $expirationYear = $request->get('expirationYear'); $cvv = $request->get('cvv'); $cardNumber = $request->get('cardNumber'); $amount = $request->get('amount'); $orders = $request->get('order'); $ordersArray = []; // getting orders details foreach($orders as $order) { if($order['id']) { $ordersArray[$order['id']]['order_id'] = $order['id']; $ordersArray[$order['id']]['quantity'] = $order['quantity']; } } dd($order); // process payment $stripe = Stripe::make(env('STRIPE_KEY')); $token = $stripe->tokens()->create([ 'card' => [ 'number' => $cardNumber, 'exp_month' => $expirationMonth, 'exp_year' => $expirationYear, 'cvv' => $cvv, ], ]); if (!$token['id']) { session()->flush('error', 'Stripe Token generation failed'); return; } // Create a customer Stripe $customer = $stripe->customers()->create([ 'name' => $firstName. ''.$lastName, 'email' => $email, 'phone' => $phone, 'address' => [ 'line1' => $address, 'postal_code' => $zipCode, 'city' => $city, 'country' => $country, ], 'shipping' => [ 'name' => $firstName.' '.$lastName, 'address' => [ 'line1' => $address, 'postal_code' => $zipCode, 'city' => $city, 'country' => $country, ], ], 'source' => $token['id'], ]); dd($customer); // code for charging the client in Stripe $charge = $stripe->charges()->create([ 'customer' => $customer['id'], 'currency' => 'eur', 'amount' => $amount, 'description' => 'Betaling van de bestelling', // 'total' => items.totalAmount, ]); if($charge['status'] =='succeeded') { // capture the datails from Stripe $customerIdStripe = $charge['id']; $amountRec = $charge['amount']; $client_id = auth()->user()->id; $processingDetails = Processing::create([ 'client_id' => $client_id, 'client_address' => json_encode([ 'line1' => $address, 'postal_code' => $zipCode, 'city' => $city, 'country' => $country, ]), 'order_details' => json_encode($ordersArray), 'amount' => $amount, 'currency' => $charge['currency'], ]); if($processingDetails) { // clear the cart after payment success Cart::where('user_id', $client_id)->delete(); return ['success' => 'Order Completed successfully']; } } else { return ['error' => 'Order Failed contact support']; } } |
Ik denk eerder dat het probleem heeft te maken met de url link. Maar helaas heb ik meer dan 10 al de url link gecontroleerd in de php router root, maar daar is ook geen spelfouten te vinden.
zo ziet mijn php router eruit:
code:
1
2
3
4
| Route::get('/checkout', [CartsController::class, 'index'])->name('checkout'); Route::get('/checkout/get/items',[CartsController::class, 'getCartItemsForCheckout']); Route::post('/process/user/payment',[CartsController::class, 'processPayment']); |