-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcharge.php
More file actions
70 lines (54 loc) · 1.98 KB
/
Copy pathcharge.php
File metadata and controls
70 lines (54 loc) · 1.98 KB
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
<?php
use function PHPSTORM_META\map;
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');
header('Content-Type: application/json');
\Stripe\Stripe::setApiKey('sk_test_51KczwTHzGIr65Dz3sxChqpmFSRfLUHeTapV7mtTCPT8kAu9hGwyLVEN1ZLPlax0KZCn5Tzy5XFe7vmPO6xQ2Zeek00xBFK9OgK');
// Sanitize POST Array
$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
$nominal = $POST['nominal'];
$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" => $nominal,
"currency" => "usd",
"description" => "Steam Wallet (USD)",
"customer" => $customer->id
));
// CustomerData
$customerData = [
'id_customer' => $charge->customer,
'email' => $email
];
// print_r($charge);
// Instatiate Customer
$customer = new Customer();
// Add Customer to DB
$customer->addCustomer($customerData);
// TransactionsData
$transactionData = [
'id_transaction' => $charge->id,
'customer_id' => $charge->customer,
'product' => $charge->description,
'amount' => $charge->amount,
'currency' => $charge->currency,
'status' => $charge->status,
'country' => $charge->country,
'risk' => $charge->risk,
'card' => $charge->last4
];
// Instatiate Transactions
$transaction = new Transactions();
// Add Transactions to DB
$transaction->addTransactions($transactionData);
// Redirect to Success
header('Location: send_email.php?tid=' . $charge->id . '&product=' . $charge->description . '&email=' . $email . '&amount=' . $charge->amount . '¤cy' . $charge->currency);