Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:16
What would you like to do?
Example 2 for a post on one-time charge
// This charge script is getting JWT and send it to stripe as one-time chage
// Author: @greenido
// Date: 28.2.2015
// Get the latest version from:
// 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
// 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" => "")
error_log("Charge obj: $charge");
$htmlCharge = "<h4>{$charge}</h4>";
echo $htmlCharge;
} catch (Stripe_CardError $e) {
error_log("Err: We could not charge. The card has been declined.\n Error Details: " . $e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment