I’m working with Stripe, and I want to make sure that when a user deletes his or her account on my site that the user’s information and subscription is deleted from Stripe automatically. Right now, in my user controller I have the following code for the destroy action:
def destroy
User.find(params[:id]).destroy
flash[:success] = "Your account has been deleted."
redirect_to root_path
end
On Stripe’s website, they have the following code for deleting a customer that was subscribed to a subscription:
cu = Stripe::Customer.retrieve("cus_IzJx2FQ7r13IOk")
cu.delete
What I would like to do is place that code in my destroy action in my rails app. I’m not sure how to properly retrieve the customer’s id from Stripe that is related to the id of the customer that is about to be deleted. My customer’s Stripe id is set equal to stripe_customer_token, and the value for stripe_customer_token is stored in my database. Any help you can give me in setting up this functionality would be awesome!
Instead of directly destroying the user instance, you can delete Stripe association first like shown below.