Skip to content

Instantly share code, notes, and snippets.

@Migweld
Created April 28, 2015 14:08
Show Gist options
  • Save Migweld/7e1e69a07d53d7d44740 to your computer and use it in GitHub Desktop.
Save Migweld/7e1e69a07d53d7d44740 to your computer and use it in GitHub Desktop.
Quaderno.js create sub
jQuery(function($) {
$('.form-payment-yearly').submit(function(event) {
event.preventDefault();
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('.btn').prop('disabled', true);
// Get the card token from Stripe
Stripe.setPublishableKey($form.data('gateway-key'));
Stripe.card.createToken($form, stripeResponseHandlerYearly);
// Prevent the form from submitting with the default action
return false;
});
$('.form-payment-monthly').submit(function(event) {
event.preventDefault();
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('.btn').prop('disabled', true);
// Get the card token from Stripe
Stripe.setPublishableKey($form.data('gateway-key'));
Stripe.card.createToken($form, stripeResponseHandlerMonthly);
// Prevent the form from submitting with the default action
return false;
});
});
function stripeResponseHandlerYearly(status, response) {
var $form = $('.form-payment-yearly');
if (response.error) {
// Show the errors on the form
$form.children('.payment-errors').text(response.error.message);
$form.children('.btn').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" data-stripe="stripeToken" />').val(token));
Quaderno.createSubscription({
success: function(status, response){
$form = $('.form-payment-yearly');
$form.append($('<input type="hidden" name="transactionDetails" />').val(response.details));
},
error: function(status, response){
$form = $('.form-payment-yearly');
$form.find('btn').prop('disabled', false);
$form.find('.payment-errors').text(response.message);
},
//complete: quadernoResponseHandler(status, response)
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment