Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Recurly.js. For when you want the "transparent redirect" but none of the form generation.
# Ripped from recurly.js
createObject = (o) ->
F = ->
F.prototype = o
return new F()
$ ->
$(".recurly-form").submit (e) ->
e.preventDefault()
$form = $(this)
Recurly.config({
subdomain: $form.data("recurly-subdomain")
currency: "USD"
})
plan = createObject(Recurly.Plan)
plan.code = $form.find("#plan_code").val()
plan.quantity = 1
user_name = $form.find("input[data-billing=billing_name]").val()
[first_name, last_name...] = user_name.split(" ")
last_name = last_name.join(" ")
account = createObject(Recurly.Account)
account.firstName = first_name
account.lastName = last_name
account.companyName = $form.find("input[data-billing=company_name]").val()
account.email = $form.find("input[data-billing=email]").val()
card_name = $form.find("input[data-billing=card_name]").val()
[card_first_name, card_last_name...] = card_name.split(" ")
card_last_name = card_last_name.join(" ")
billing = createObject(Recurly.BillingInfo)
billing.firstName = card_first_name
billing.lastName = card_last_name
billing.address1 = $form.find("input[data-billing=address_line1]").val()
billing.address2 = $form.find("input[data-billing=address_line2]").val()
billing.city = $form.find("input[data-billing=address_city]").val()
billing.state = $form.find("select[data-billing=address_state]").val()
billing.zip = $form.find("input[data-billing=address_zip]").val()
billing.country = $form.find("select[data-billing=address_country]").val()
billing.number = $form.find("input[data-billing=card_number]").val()
billing.month = $form.find("select[data-billing=exp_month]").val()
billing.year = $form.find("select[data-billing=exp_year]").val()
billing.cvv = $form.find("input[data-billing=card_ccv]").val()
subscription = createObject(Recurly.Subscription)
subscription.plan = plan
subscription.account = account
subscription.billingInfo = billing
subscription.save({
signature: $form.data("recurly-signature")
success: (data) ->
console.log("Save was successful %o", data)
error: (data) ->
console.log("Save failed %o", data)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.