-
-
Save briancollins/5942803 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
Stripe.setPublishableKey('pk_test_Wfzrj4uDDPOcv7XxVJKXRERS'); | |
var l = Ladda.create( document.querySelector( '#addservice-submit' ) ); | |
var stripeResponseHandler = function(status, response) { | |
if (response.error) { | |
// show the errors on the form | |
$("#stripe-errors").html(response.error.message); | |
} else { | |
var token = response['id']; | |
var form$ = $("#addservice-form"); | |
form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />"); | |
var data = $("#addservice-form").serialize(); | |
var $form = $('form#addservice-form'); | |
$.post("/addService.php", data, | |
function (html) { | |
l.stop(); | |
//if process.php returned 1/true (send mail success) | |
if (html=="good") { | |
//hide the form | |
$('#serviceNameExists').hide(); | |
$('#notComplete').hide(); | |
$('#serviceAdded').show(); | |
} else if (html=="notComplete") { | |
$('#serviceAdded').hide(); | |
$('#serviceNameExists').hide(); | |
$('#notComplete').show(); | |
} else if (html=="serviceNameExists") { | |
$('#serviceAdded').hide(); | |
$('#notComplete').hide(); | |
$('#serviceNameExists').show(); | |
} else alert(html); | |
} | |
}); | |
} | |
} | |
// do stuff when dom is ready | |
$(document).ready(function(){ | |
// Add new service stuff. | |
$('button#addservice-submit').click(function(event) { | |
l.start(); | |
Stripe.createToken({ | |
number: $('#thecard').val(), | |
cvc: $('#thecvc').val(), | |
exp_month: $('#themonth').val(), | |
exp_year: $('#theyear').val() | |
}, stripeResponseHandler); | |
return false; | |
}); |
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_once("/srv/www/mysite.com/public_html/includes/stripe-php/lib/Stripe.php"); | |
Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxxx"); | |
// This line has got to have something to do with it. But the request from jQuery to this file sends info in POST. | |
$token = ($_GET['stripeToken']) ?$_GET['stripeToken'] : $_POST['stripeToken']; | |
Stripe_Customer::create(array( | |
"card" => $token, | |
"plan" => "standard", | |
"email" => $customerInfo['email'] | |
) | |
); | |
// create a charge for $14.99, or 1,499 cents. | |
Stripe_Charge::create(array( | |
"amount" => 1499, | |
"currency" => "usd", | |
"card" => $token, // obtained with Stripe.js | |
"description" => "New Mysite.com Service") | |
); | |
?> |
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
<!-- Here's our form with id value of addservice-form, as the js expects --> | |
<form action="" method="POST" id="addservice-form"> | |
<label>Service Name</label> | |
<input type="text" name="servicename" class="span3"> | |
<label>API URL</label> | |
<input type="text" name="apiurl" class="span3"> | |
<label>API Key</label> | |
<input type="text" name="apikey" class="span3"> | |
<label>API Hash</label> | |
<input type="text" name="apihash" class="span3"> | |
<label>Allowed IP's (comma separated list)</label> | |
<input type="text" name="allowedip" class="span3"> | |
<label>Desired Status URL</label> | |
<div class="input-append"> | |
<input type="text" name="domain" class="span2" id="appendedInput"> | |
<span class="add-on">.myservice.com</span> | |
</div> | |
<label>Credit Card #</label> | |
<input type="text" data-stripe="number" id="thecard" placeholder="Card Number (eg: 1111222233334444)"> | |
<label>Security Code</label> | |
<input type="text" data-stripe="cvc" id="thecvc" placeholder="CVC Code/Security Code (eg: 112)"> | |
<label>Expiration Month</label> | |
<input type="text" data-stripe="exp-month" id="themonth" placeholder="Expiration Month (eg: 05)"> | |
<label>Expiration Year</label> | |
<input type="text" data-stripe="exp-year" id="theyear" placeholder="Expiration Year (eg: 2013)"> | |
<center><button type="submit" class="ladda-button btn btn-primary" data-style="expand-right" id="addservice-submit"><span class="ladda-label"><i class="icon-white icon-plus-sign"></i> Add Service</span><span class="ladda-spinner"></span></button></center> | |
<div class="clearfix"></div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment