Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
require '/home/wwwcilku/public_html/Stripelib/lib/Stripe.php';
if ($_POST) {
$token = $_POST['stripeToken'];
$error = '';
$success = '';
try {
if (!isset($token))
throw new Exception("The Stripe Token was not generated correctly");
$customer = Stripe_Customer::create(array(
"card" => $token,
"email" => $_POST["email"]
// Charge the Customer instead of the card
"amount" => 2500, # amount in cents, again
"currency" => "usd",
"customer" => $customer->id,
saveStripeCustomerId($user, $customer->id);
$success = 'Your payment was successful.';
catch (Exception $e) {
$error = $e->getMessage();
<!doctype html>
<meta charset="utf-8">
<title>Create My Intro</title>
<meta name="description" content="We create custom designed Youtube Channel intros for you channel!">
<link href="/css/normalize.css" rel="stylesheet" type="text/css">
<link href="/css/custom.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src=""></script>
<!-- pubkey !-->
<script type="text/javascript">
// This identifies your website in the createToken call below
// ...
<script type="text/javascript" src=""></script>
<script type="text/javascript">
<!-- Creates the token from the form data. !-->
// Function that creates the token.
jQuery(function($) {
$('#payment-form').submit(function(event) {
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('button').prop('disabled', true);
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
// Function that handles the response from the token.
function stripeResponseHandler(status, response) {
var $form = $('#payment-form');
if (response.error) {
// Show the errors on the form
$form.find('button').prop('disabled', false);
} else {
// response contains id and card, which contains additional card details
var token =;
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// and submit
<div class = "imglogo" style="background: url(/images/logo.png) no-repeat center center transparent;">&nbsp;</div>
<div class="container">
<nav class="top-nav">
<ul class="main-nav">
<li class="but-home"><a href="/index.html">- templates</a></li>
<li><a href="/custom.html">- custom intro</a></li>
<li><a href="/about.html">- about</a></li>
<li><a href="/contact.html">- contact</a></li>
<!-- to display errors returned by createToken -->
<span class="payment-errors"><?= $error ?></span>
<span class="payment-success"><?= $success ?></span>
<form action="" method="POST" id="payment-form">
<span class="payment-errors"></span>
<p class="form-label">Choose Template:</p>
<select data stripe="description">
<option>Poker Template</option>
<option>Poker Template</option>
<option>Poker Template</option>
<option>Poker Template</option>
<p class="form-label">Email:</p>
<input type="text" name="email"></input>
<p class="form-label">Full Name:</p>
<input type="text" size="20" data-stripe="name"></input>
<p class="form-label">Zip Code:</p>
<input type="text" size="5" data-stripe="address_zip"></input>
<p class="form-label">Credit Card Number:</p>
<input type="text" size="20" data-stripe="number"></input>
<p class="form-label">Expiration Date:</p>
<select data-stripe="exp_month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
<select data-stripe="exp_year">
$yearRange = 20;
$thisYear = date('Y');
$startYear = ($thisYear + $yearRange);
foreach (range($thisYear, $startYear) as $year)
if ( $year == $thisYear) {
print '<option value="'.$year.'" selected="selected">' . $year . '</option>';
} else {
print '<option value="'.$year.'">' . $year . '</option>';
<p class="form-label">CVC:</p>
<input type="text" size ="3" data-stripe="cvc" autocomplete="off"></input>
<button type="submit">Submit Payment</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment