Created
July 20, 2014 23:04
-
-
Save anonymous/4133f99c2791385059f4 to your computer and use it in GitHub Desktop.
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 | |
require '/home/wwwcilku/public_html/Stripelib/lib/Stripe.php'; | |
if ($_POST) { | |
Stripe::setApiKey("sk_test_DwpmvsqgIkLNt3Tt0lvFW3mz"); | |
$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, | |
// "description" => htmlspecialchars($_POST['description']), | |
)); | |
// Charge the Customer instead of the card | |
Stripe_Charge::create(array( | |
"amount" => 2500, # amount in cents, again | |
"currency" => "usd", | |
"customer" => $customer->id, | |
)); | |
saveStripeCustomerId($user, $customer->id); | |
header("Location: http://www.createmyintro.com/index.html"); | |
$success = 'Your payment was successful.'; | |
} | |
catch (Exception $e) { | |
$error = $e->getMessage(); | |
} | |
} | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
<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"> | |
<!-- STRIPE JS REFERENCE !--> | |
<script type="text/javascript" src="https://js.stripe.com/v2/"></script> | |
<!-- pubkey !--> | |
<script type="text/javascript"> | |
// This identifies your website in the createToken call below | |
Stripe.setPublishableKey('pk_test_3mbgjo4AhmkOBfsSIyZ1N7Bo'); | |
// ... | |
</script> | |
<!--JQUERY!--> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></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('.payment-errors').text(response.error.message); | |
$form.find('button').prop('disabled', false); | |
} else { | |
// response contains id and card, which contains additional card details | |
var token = response.id; | |
// Insert the token into the form so it gets submitted to the server | |
$form.append($('<input type="hidden" name="stripeToken" />').val(token)); | |
// and submit | |
$form.get(0).submit(); | |
} | |
}; | |
</script> | |
</head> | |
<body> | |
<div class = "imglogo" style="background: url(/images/logo.png) no-repeat center center transparent;"> </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> | |
</ul> | |
</nav> | |
<h2>PAYMENT FORM</h2> | |
<!-- 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> | |
</select> | |
<p class="form-label">Email:</p> | |
<input type="text" data-stripe="receipt-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> | |
<select data-stripe="exp_year"> | |
<?php | |
$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>'; | |
} | |
} | |
?> | |
</select> | |
<p class="form-label">CVC:</p> | |
<input type="text" size ="3" data-stripe="cvc" autocomplete="off"></input> | |
<button type="submit">Submit Payment</button> | |
</form> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment