Python stripe can't delete connect account | 'str' object has no attribute 'refresh_from'

Question:

I am using stripe connect and a custom interface to create/manage stripe users.

I want now to delete a stripe connect account, the balance is 0 ofc., eventhough it should not matter with test keys. According to the docu for stripe connect it is super simple to delete an account:

With Connect, you may delete Custom accounts you manage.
Custom accounts created using test-mode keys can be deleted at any time. Custom accounts created using live-mode keys may only be deleted once all balances are zero.

That is my code:

user = User.query.filter_by(id=data_received["user_id"]).first()

stripe_acc_id = user.stripe_connect_acc_id

db_session.delete(user)

if stripe_acc_id != None:
    print ("User has stripe connect account", stripe_acc_id)
    try:
        stripe.Account.delete(stripe_acc_id)
    except Exception as e:
        return json.dumps({'status': 'failed', 'reason': str(e)})

db_session.commit()

But it does not work, I am getting this error:

{"status": "failed", "reason": "'str' object has no attribute 'refresh_from'"}
Asked By: Roman

||

Answers:

Support for static methods like stripe.Account.delete as documented was actually only added to the library very recently.

Unless you’re using the latest version of the library, you need to instead slightly counter-intuitively fetch the account first, and then delete it:

account = stripe.Account.retrieve('acct_1DyHD2HPqAmBZVG2') 
account.delete()
Answered By: karllekko

This error is caused because your python-stripe version does not support this delete method with the id argument. I faced the same issue while deleting the coupon with the old stripe version 2.6.0.

Answered By: Nitin
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.