How to update a customer belonging to a connected account in Stripe?

Viewed 119

I am building a Rails 5.2 app. In this app I have integrated Stripe Connect. I am currently building a feature where my customers can enroll their customers in subscriptions. The front end is Angular 11.

After the user have entered their payment data I need to attach this payment method to the created customer but I am not able too.

When I use this code it says that the customer is not found (even though I am using the correct ID). I guess it's because I created the Customer to a connected account.

The problem is I have no way of setting the stripe_account ID to the code.

customer = Stripe::Customer.update(
  params[:customer],
  invoice_settings: { 
    default_payment_method: params[:payment_method_id] 
   }

)

If I try this it says the stripe_account parameter is not valid.

"(Status 400) (Request req_sByQlJONJi0oHt) Received unknown parameter: stripe_account"

customer = Stripe::Customer.update(
      params[:customer],
      invoice_settings: { 
        default_payment_method: params[:payment_method_id] 
       }, stripe_account: params[:account]
   )

So basically, how can I update a customer belonging to a Connected Account?

1 Answers

The update definition looks like this:

def update(id, params = {}, opts = {})

So in your case, the stripe_account is being passed in the params argument instead of the opts argument. Wrap the params in brackets ({}).

customer = Stripe::Customer.update(params[:customer], 
                                     {invoice_settings: {default_payment_method: params[:payment_method_id]}}, 
                                     {stripe_account: params[:account]})
Related