public
Last active

For those who aren't using coffeescript, here is the compiled Subscriptions javascript file from RailsCast #288 Billing with Stripe

  • Download Gist
subscriptions.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
(function() {
var subscription;
jQuery(function() {
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
return subscription.setupForm();
});
subscription = {
setupForm: function() {
return $('#new_subscription').submit(function() {
$('input[type=submit]').attr('disabled', true);
if ($('#card_number').length) {
subscription.processCard();
return false;
} else {
return true;
}
});
},
processCard: function() {
var card;
card = {
number: $('#card_number').val(),
cvc: $('#card_code').val(),
expMonth: $('#card_month').val(),
expYear: $('#card_year').val()
};
return Stripe.createToken(card, subscription.handleStripeResponse);
},
handleStripeResponse: function(status, response) {
if (status === 200) {
$('#subscription_stripe_card_token').val(response.id);
return $('#new_subscription')[0].submit();
} else {
$('#stripe_error').text(response.error.message);
return $('input[type=submit]').attr('disabled', false);
}
}
};
}).call(this);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.