1

I'm using Rails-Stripe-Membership-SaaS which makes use of Payola. Payola assumes you want to create an immediately charging subscription. This means free plans and plans with free trials require a credit card at sign up. I'd like to get around this. I've made a fork here: https://github.com/archonic/payola

Where I'm confused is the specifics of how to complete the first step here: Stripe - How to handle subscription with a free plan and no credit card required at sign up time

Stripe doesn't require a card for free plans or plans with a trial, but I'm not sure how to create a token without a card. How can I get a token with just an email before I call create_customer?

Community
  • 1
  • 1
Archonic
  • 5,207
  • 5
  • 39
  • 55

1 Answers1

2

You don't need a token to create a customer. Just go ahead and call the create customer API like this:

customer = Stripe::Customer.create(
  email: "test@example.com",
  description: "...something..."
)
# do something with customer, save id in db/etc

You can subscribe that customer to a plan that has a free trial without it needing a card attached. You could even pass plan: 'someplan' in that create customer call if you wanted so long as the plan has a free trial.

rfunduk
  • 30,053
  • 5
  • 59
  • 54
  • Well that's ridiculously simple. Trying to get Payola to not require a card on form submit, I'll need to change the submit handler. Do you know what I can use instead of `Stripe.card.createToken`? – Archonic Jun 06 '15 at 22:34
  • You won't need Stripe at all for that part. Just submit the form directly (vaguely, I'd take a look at what happens in the response handler of the createToken call and do that directly instead). If you point me at the actual front-end code in payola that does this I might be able to help more. – rfunduk Jun 06 '15 at 22:44
  • Here's the response handler: https://github.com/peterkeen/payola/blob/master/app/assets/javascripts/payola/subscription_form_twostep.js#L17 – Archonic Jun 06 '15 at 22:45
  • This answered my question, but I'm still looking for a Payola specific solution. `Stripe.card.createToken` is providing some very handy form validation and is hitting `/users` first to create the user which triggers creating the subscription and properly populating it's owner (the recently created user). If I go directly for `/payola/subscribe/plan/1/`, the owner object is nil. Is there a Stripe call like createToken which doesn't require a card? – Archonic Jun 07 '15 at 21:03
  • So right here: https://github.com/peterkeen/payola/blob/master/app/assets/javascripts/payola/subscription_form_twostep.js#L11-L13 -- just call it like this: `PayolaSubscriptionForm.stripeResponseHandler(form, status, { error: false, id: null } );` -- unfortunately the chain from there gets a bit convoluted. I feel like that might just work, or you might have more digging into the various subscription classes in use. Might just be easier to roll your own and not use Payola if it doesn't support this. – rfunduk Jun 07 '15 at 23:28
  • Looks like the Payola gem author created a work around for this: https://github.com/peterkeen/payola/commit/0b0282fb256eba7247999fbf2b33f2ded567c311 – Ryan Arneson Jun 11 '16 at 13:20