Stripe Ruby - find an existing customer by ID and add a plan

So Stripe members say:

Once you have created a customer, you must store their ID in your own database to later refer to when communicating with the strip.

Okay, easy enough. My question is: how can I find a client by ID? UPDATE :

customer = Stripe::Customer.retrieve(id)

      

When I register a new customer for one of my services, I create a new Stripe Customer

, but if they are an existing customer, I would like to use their existing account and just add the plan. How do I find them and add a new plan? I looked through the docs and ruby ​​stone but couldn't figure it out. Please help me? This is the method.

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 existing account for the added subscription
    end

    redirect_to :somewhere
end

      

+3


source to share


2 answers


Find a client:

customer = Stripe::Customer.retrieve(current_vendor.stripe_id) # pass in the persisted ID

      

Create a new plan subscription:



customer.subscriptions.create(plan: "social")

      

The documents are quite thorough, I just had to break through and find specifics. By the way, adding multiple subscribers for one client was a feature that Stripe added in February this year .

+2


source


I believe this is how you create a plan when you have your client.



Stripe::Customer.create({
    :card => customer.id,
    :plan => your_plan,
    }, access_token
  )

      

0


source







All Articles