Skip to content

Commit

Permalink
Made StripeModel._find_owner_account work for all object types
Browse files Browse the repository at this point in the history
_find_owner_account will now work for not only WebhookEventTrigger or event objects but also other Stripe Objects as well as Stripe Objects on Conencted Accounts.
  • Loading branch information
arnav13081994 authored and jleclanche committed Dec 8, 2021
1 parent aea87ef commit 8969322
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions djstripe/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,21 @@ def _find_owner_account(cls, data, api_key=djstripe_settings.STRIPE_SECRET_KEY):
"""
from .account import Account

if data and data.get("account"):
# try to fetch by stripe_account. Also takes care of Stripe Connected Accounts
stripe_account = cls._id_from_data(data.get("account"))
if stripe_account:
return Account._get_or_retrieve(id=stripe_account)
# try to fetch by stripe_account. Also takes care of Stripe Connected Accounts
if data:
# case of Webhook Event Trigger
if data.get("object") == "event":
# if account key exists and has a not null value
if data.get("account"):
stripe_account = cls._id_from_data(data.get("account"))
if stripe_account:
return Account._get_or_retrieve(id=stripe_account)

else:
if getattr(data, "stripe_account", ""):
stripe_account = cls._id_from_data(data.stripe_account)
if stripe_account:
return Account._get_or_retrieve(id=stripe_account)

# try to fetch by the given api_key.
return Account.get_or_retrieve_for_api_key(api_key)
Expand Down

0 comments on commit 8969322

Please sign in to comment.