Stripe with PHP
<?php
https://stripe.com/docs/testing#cards
https://stripe.com/docs/checkout/php
https://gist.github.com/bkrausz/a76f9d7a9b446337d470
1) Download Stripe, rename stripe download name to just stripe
unpack put it inside a vendor folder
/vendor/stripe
2) Create a config file: config_stripe.php
// require_once('vendor/autoload.php');
// load the init.php instead of the vendor autoload, requires composer (SSH access to install via composer)
require_once('vendor/stripe/init.php') ;
$stripe = array(
"secret_key" => "sk_test_VndnI5YP5EmfnEQQRkWWTySY",
"publishable_key" => "pk_test_qvWZoegjCE0PleWlb3lwZq3p"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
3) in your web page where you want the form to show:
<?php
// reference the publishable key for data-key
require_once('config_stripe.php');
?>
<form action="charge_stripe.php" method="post">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-name="Regigo"
data-description="Event"
data-label="Complete Registration"
data-amount="5000"
data-locale="auto"></script>
</form>
4) Create charge_stripe.php
<?php
require_once('config_stripe.php');
$token = $_POST['stripeToken'];
// juan@popcreativegroup.com is hardcoded, use $_POST['stripeEmail'] to grab the email used with the credit card
$customer = \Stripe\Customer::create(array(
'email' => 'juan@popcreativegroup.com',
'source' => $token
));
// this is where the customer gets charged, and it is logged into stripe
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 5000,
'currency' => 'usd'
));
echo '<pre>';
// var_dump($customer) ; // dump the whole customer object
// var_dump( get_class_methods($customer) ) ; // you can see the class methods for the customer object
var_dump( $customer->keys() ) ; // we are interested in the keys() method
echo '</pre>';
echo '<h1>Successfully charged $50.00!</h1>';