From 339efa8a96b5329165c8b27f5efc73c0540d4610 Mon Sep 17 00:00:00 2001 From: GR Date: Fri, 22 Jun 2018 12:18:24 +0100 Subject: [PATCH 1/2] Remove bank account action --- pinax/stripe/actions/externalaccounts.py | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pinax/stripe/actions/externalaccounts.py b/pinax/stripe/actions/externalaccounts.py index a1d92cf4e..082432e20 100644 --- a/pinax/stripe/actions/externalaccounts.py +++ b/pinax/stripe/actions/externalaccounts.py @@ -1,4 +1,5 @@ from .. import models +import stripe def create_bank_account(account, account_number, country, currency, **kwargs): @@ -62,3 +63,42 @@ def sync_bank_account_from_stripe_data(data): setattr(obj, a, data.get(a)) obj.save() return obj + + + +def delete_bank_account(account, bank_account): + """ + Create or update using the account object from a Stripe API query. + + Important: The user must have another bank account with default_for_currency set to True + + Args: + account: stripe.models.Account object to delete the bank_account from + bank_account: stripe.models.BankAccount object + + Returns: + True if Bank Account was deleted + """ + + # Get Stripe Account + account = stripe.Account.retrieve(account.stripe_id) + + # Retrieve the associated Bank Account and Delete it + try: + r = account.external_accounts.retrieve(bank_account.stripe_id).delete() + + if r['deleted']: # if Stripe returns that deleted is True + # delete the account + bank_account.delete() + return True + + except stripe.error.InvalidRequestError as E: + print(E) + + return False + + + + + + From 753c52cfee825ce83c597bfe7a1a4b75b264cce1 Mon Sep 17 00:00:00 2001 From: GR Date: Fri, 22 Jun 2018 12:33:24 +0100 Subject: [PATCH 2/2] Remove bank account action --- pinax/stripe/actions/externalaccounts.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pinax/stripe/actions/externalaccounts.py b/pinax/stripe/actions/externalaccounts.py index 082432e20..e993bae3a 100644 --- a/pinax/stripe/actions/externalaccounts.py +++ b/pinax/stripe/actions/externalaccounts.py @@ -1,6 +1,7 @@ -from .. import models import stripe +from .. import models + def create_bank_account(account, account_number, country, currency, **kwargs): """ @@ -65,10 +66,9 @@ def sync_bank_account_from_stripe_data(data): return obj - def delete_bank_account(account, bank_account): """ - Create or update using the account object from a Stripe API query. + Deletes an external bank account from Stripe and Updates DB Important: The user must have another bank account with default_for_currency set to True @@ -95,10 +95,4 @@ def delete_bank_account(account, bank_account): except stripe.error.InvalidRequestError as E: print(E) - return False - - - - - - + return False \ No newline at end of file