forked from greenido/Product-Site-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
charge.php
33 lines (28 loc) · 1.1 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
<?php
// Get the latest version of stripe from: https://github.com/stripe/stripe-php/releases
require_once("stripe-php-1.18.0/lib/Stripe.php");
//
// Set your secret key: remember to change this to your live secret key in production
// We are using the test seceret key here just for our demo
//
Stripe::setApiKey("sk_test_Hta3le08tAzxbMq4NvgQVnqe");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array(
"amount" => 999999, // amount in cents - so it's 9,999.99$ (cheap!)
"currency" => "usd",
"card" => $token,
"description" => "[email protected]")
);
error_log("Charge obj: $charge");
$charge = str_replace("{", "<br>{", $charge);
$charge = str_replace("}", "}<br>", $charge);
$charge = str_replace(",", "<br>", $charge);
$htmlCharge = "<h4> {$charge} </h4>";
echo $htmlCharge;
} catch(Stripe_CardError $e) {
// The card has been declined
error_log("Err: We could not charge. The card has been declined.\n Error Details: " . $e);
}