So the Stripe docs say:
Once you've created a customer, you should store its id in your own database so you can refer to it later when communicating with stripe.
Okay, easy enough. My question is: how do I find a customer by their ID? UPDATE like this:
customer = Stripe::Customer.retrieve(id)
When I sign up a new customer for one of my services I create a new Stripe Customer
, but if they are an existing customer I'd like to use their existing account and simply add a plan. How do I find them and add a new plan? I looked through the docs and the ruby gem but couldn't figure it out. Help please? Here's the method in question.
def social_signup
token = params[:stripe_token]
if current_vendor.stripe_id == nil
customer = Stripe::Customer.create(
:card => token,
:plan => 'social',
:email => current_vendor.email
)
current_vendor.update_attributes(stripe_id: customer.id)
else
customer = Stripe::Customer.retrieve(current_vendor.stripe_id)
# bill the customer's existing account for the added subscription
end
redirect_to :somewhere
end
Find a customer:
customer = Stripe::Customer.retrieve(current_vendor.stripe_id) # pass in the persisted ID
Create a new subscription to a plan:
customer.subscriptions.create(plan: "social")
The docs are pretty thorough, just had to dig through and find the specifics. Incidentally, adding multiple subscriptions for a single customer was a feature that Stripe added in February of this year.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With