-
Notifications
You must be signed in to change notification settings - Fork 0
/
charge.php
64 lines (51 loc) · 1.47 KB
/
charge.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once('vendor/autoload.php');
require_once('config/db.php');
require_once('lib/pdo_db.php');
require_once('models/Customer.php');
require_once('models/Transaction.php');
\Stripe\Stripe::setApiKey('sk_YOURSERVERKEY');
// Sanitize POST Array
$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
$first_name = $POST['first_name'];
$last_name = $POST['last_name'];
$email = $POST['email'];
$token = $POST['stripeToken'];
// Create Customer In Stripe
$customer = \Stripe\Customer::create(array(
"email" => $email,
"source" => $token
));
// Charge Customer
$charge = \Stripe\Charge::create(array(
"amount" => 5000,
"currency" => "usd",
"description" => "Intro To React Course",
"customer" => $customer->id
));
// Customer Data
$customerData = [
'id' => $charge->customer,
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email
];
// Instantiate Customer
$customer = new Customer();
// Add Customer To DB
$customer->addCustomer($customerData);
// Transaction Data
$transactionData = [
'id' => $charge->id,
'customer_id' => $charge->customer,
'product' => $charge->description,
'amount' => $charge->amount,
'currency' => $charge->currency,
'status' => $charge->status,
];
// Instantiate Transaction
$transaction = new Transaction();
// Add Transaction To DB
$transaction->addTransaction($transactionData);
// Redirect to success
header('Location: success.php?tid='.$charge->id.'&product='.$charge->description);