forked from elementary/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.php
59 lines (49 loc) · 1.64 KB
/
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
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
<?php
/**
* api/payment.php
* Accepts payment for current release
*/
require_once __DIR__ . '/../_backend/bootstrap.php';
require_once __DIR__ . '/../_backend/email/os-payment.php';
require_once __DIR__ . '/../_backend/log-echo.php';
require_once __DIR__ . '/../_backend/os-payment.php';
\Stripe\Stripe::setApiKey($config['stripe_sk']);
if (isset($_POST['token'])) {
$token = $_POST['token'];
$amount = intval($_POST['amount']);
$description = $_POST['description'];
$email = $_POST['email'];
$os = $_POST['os'];
// 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,
'metadata' => array(
'receipt' => 'false',
'products' => json_encode(array('ISO-' . $config['release_version']))
)
));
} catch(\Stripe\Error\Card $e) {
// Don't use log_echo because we don't want finance stuff echoing.
error_log($e);
$sentry->captureMessage($e);
http_response_code(500);
echo 'An error occurred.';
die();
}
os_payment_setcookie($config['release_version'], $amount);
try {
email_os_payment($charge);
} catch (Exception $e) {
error_log($e);
$sentry->captureMessage($e);
echo 'Unable to send receipt email';
}
require_once __DIR__.'/../_backend/average-payments.php';
} else {
echo $config['stripe_pk'];
}