forked from elementary/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.php
31 lines (28 loc) · 990 Bytes
/
payment.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
<?php
require_once __DIR__.'/lib/Stripe.php';
require_once __DIR__.'/config.loader.php';
Stripe::setApiKey($config['stripe_sk']);
if (isset($_POST['token'])) {
$token = $_POST['token'];
$amount = $_POST['amount'];
$description = $_POST['description'];
$email = $_POST['email'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array(
'amount' => $amount,
'currency' => 'usd',
'card' => $token,
'description' => $description,
'receipt_email' => $email,
));
// Set an insecure, HTTP only cookie for 10 years in the future.
$encoded = urlencode(str_replace(' ', '_', 'has_paid_'.$description));
setcookie($encoded, $amount, time() + 315360000, '/', '', 0, 1);
echo 'OK';
} catch(Stripe_CardError $e) {
echo 'error';
}
} else {
echo $config['stripe_pk'];
}