-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.php
41 lines (34 loc) · 1.12 KB
/
submit.php
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
<?php
require_once('./includes/init.inc.php');
require_once('./config/stripeConfig.php');
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
// Sanitize The Post Array.
$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
$token = $POST['stripeToken'];
$firstName = $POST['first_name'];
$emailAddress = $POST['email'];
$countryName = $POST['country'];
$cityName = $POST['city'];
// Retrieve Amount & Convert Into Integer.
$totalAmount = number_format(( $_SESSION['total'] * 100 ) , 0, '', '');
// Create customer in stripe.
$customer = \Stripe\Customer::create([
'email' => $emailAddress,
'source' => $token,
'description' => 'A new customer purchase '.$cart->total().' items from shopping cart',
]);
// Charge the amount from customer.
$charge = \Stripe\Charge::create([
'amount' => $totalAmount,
'currency' => 'usd',
'description' => 'Charged from E-StuffCart',
'customer' => $customer->id
]);
// Redirect To Success Page.
header('location: http://localhost/estuffcart/success/'.$charge->id.'', TRUE, 302);
}
else {
// Redirect To Home Page.
header('location: index');
exit;
}