Tuesday, 15 July 2014

ruby on rails - Automatically Setting a Devise User as a Stripe Customer -



ruby on rails - Automatically Setting a Devise User as a Stripe Customer -

my strategy this:

have user sign up automatically associate user stripe id

how i've tried implement this:

i created users controller , have inherit registrationcontroller:

devise_for :users, :controllers => { :registrations => 'users'}

i created callback after user saved:

after_save :set_stripe_customer_id private def set_stripe_customer_id end

now, think needs here like:

current_user.update_attribute(:stripe_id => ....

the docs show code like

stripe::customer.create( :description => "customer test@example.com", :card => "tok_1046el4bfu4hlntvxyciz4re" )

thing is, don't want client set card in immediately. although, isn't big deal, i'm fine waiting require registration until actual point of purchase. question simplest, bare minimum code need create callback automatically create stripe customer?

all of parameters stripe::customer.create optional, can bare-bones as:

def set_stripe_customer_id client = stripe::customer.create current_user.update_attributes :stripe_id => customer.id end

and later on create subscription customer, or update various details need.

although isn't necessary. there's no real downside waiting until need client create (eg, because subscribing).

ruby-on-rails devise stripe-payments

No comments:

Post a Comment