forked from phptechlife/laravel_10_ecomm_templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part37.txt
81 lines (67 loc) · 1.92 KB
/
part37.txt
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
<script src="https://js.stripe.com/v3/"></script>
var stripe = Stripe('{{ env('STRIPE_PUBLIC_KEY') }}');
var elements = stripe.elements();
var style = {
base: {
color: '#32325d',
lineHeight: '18px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
var card = elements.create('card',{hidePostalCode: true, style: style});
card.mount('#card-element');
card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
/////////
stripe.createToken(card).then(function(result) {
if (result.error) {
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// var dataForm = $("#checkOutForm").serializeArray();
// dataForm.push({name: 'token', value: result.token.id});
// Put your ajax here
}
});
///////
$stripe = Stripe::make(env('STRIPE_SECRET_KEY'),'2019-02-19');
// Create Customer
$customer = $stripe->customers()->create([
'source' => $request->token,
'email' => $request->email,
'address' => [
'city' => $request->city,
]
]);
// Charge Customer
$charge = $stripe->charges()->create([
'customer' => $customer['id'],
'currency' => 'USD',
'amount' => $grandTotal,
]);
if ($charge['status'] == 'succeeded') {
Cart::destroy();
// Update Order status
return response()->json([
'status' => true,
'order_id' => $order->id,
'message' => 'Thanks for your order'
]);
} else {
// Payment error
}