Last active
August 29, 2015 14:16
-
-
Save greenido/dde47b408c0f89fc7d11 to your computer and use it in GitHub Desktop.
Example 2 for a post on one-time charge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 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: | |
// 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" => "OurPayingUser@example.com") | |
); | |
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