I was looking for quite a long time for a good example on how to de-authorize / disconnect a Stripe Connect account in my Rails app. Perhaps for those that are well versed in making external POST requests, this is trivial, but I'm new and this seemed so hard for someone new to manually crafting POST requests. :)
I'm using the omniauth-stripe-connect gem, which is excellent for connecting an account with Stripe connect. It doesn't appear to have built-in functionality for disconnecting accounts.
Stripe's own documentation says to simply do a POST to their deauthorize URL. But their example is a cURL command, which you can't use natively in Rails. Or rather, it's not advised.
curl https://connect.stripe.com/oauth/deauthorize \
-u {YOUR_SECRET_KEY}: \
-d client_id=ca_5ry8QONyVRqZAJcezVxwUWlGcJAR7cW1 \
-d stripe_user_id=acct_llriadrqho6HXC
What's the best way to perform that POST in Rails?
I found this other question's comments and accepted answer extremely helpful: Stripe Connect - retrieving access token
Here is what I ended up doing:
Install the HTTParty gem and then use the following code:
HTTParty.post("https://connect.stripe.com/oauth/deauthorize",
:basic_auth => { :username => ENV['STRIPE_SECRET_KEY'] },
:query => {
client_id: ENV['STRIPE_CONNECT_CLIENT_ID'],
stripe_user_id: @user.stripe_user_id })
I've got my Stripe keys loaded into the environment with the Figaro gem.
I hope that saves someone else hours of search and tinkering!