1212class Stripe :
1313 """API for Stripe"""
1414
15- def __init__ (self , api_key ):
15+ def __init__ (self , api_key , provider_account_id ):
1616 # Due to fact that we can set up only one Stripe per 3scale and we use same api_key everytime this
1717 # is not disruptive even if it looks like it is.
1818 stripe .api_key = api_key
19+ self .provider_account_id = provider_account_id
1920
2021 @staticmethod
2122 @backoff .on_predicate (backoff .fibo , lambda x : x == [], max_tries = 10 , jitter = None )
2223 def read_charge (customer ):
2324 """Retrieves the details of the charge"""
2425 return stripe .Charge .search (query = f"customer:'{ customer ['id' ]} '" ).data
2526
26- @staticmethod
2727 @backoff .on_exception (backoff .expo , IndexError , max_tries = 4 , jitter = None )
28- def read_customer_by_account (account ):
28+ def read_customer_by_account (self , account ):
2929 """
3030 Read Stripe customer.
3131 Different 3scale deployments can have customers with the same id, which is reflected to the
3232 `3scale_account_reference` Stripe Customer variable. This method reads just the last one.
3333 """
3434 return stripe .Customer .search (
35- query = f"metadata['3scale_account_reference']:'3scale-2 -{ str (account .entity_id )} '"
35+ query = f"metadata['3scale_account_reference']:'3scale-{ self . provider_account_id } -{ str (account .entity_id )} '"
3636 ).data [0 ]
3737
3838 def assert_payment (self , invoice , account ):
@@ -51,7 +51,7 @@ def assert_payment(self, invoice, account):
5151class Braintree :
5252 """API for braintree"""
5353
54- def __init__ (self , merchant_id , public_key , private_key ):
54+ def __init__ (self , merchant_id , public_key , private_key , provider_account_id ):
5555 self .gateway = braintree .BraintreeGateway (
5656 braintree .Configuration (
5757 environment = braintree .Environment .Sandbox ,
@@ -60,6 +60,7 @@ def __init__(self, merchant_id, public_key, private_key):
6060 private_key = private_key ,
6161 )
6262 )
63+ self .provider_account_id = provider_account_id
6364
6465 @backoff .on_exception (backoff .fibo , (ServiceUnavailableError , RequestTimeoutError ), max_tries = 8 , jitter = None )
6566 def get_customer_transactions (self , account ):
@@ -76,10 +77,9 @@ def merchant_currency(self):
7677 merchant_accounts = list (self .gateway .merchant_account .all ().merchant_accounts .items )
7778 return [x for x in merchant_accounts if x .default is True ][0 ].currency_iso_code
7879
79- @staticmethod
80- def customer_id (account ):
81- """Returns Braintree customer id. It is in a form `3scale-2-{account_id}-1`"""
82- return f"3scale-2-{ account .entity_id } -1"
80+ def customer_id (self , account ):
81+ """Returns Braintree customer id. It is in a form `3scale-{provider_id}-{account_id}-1`"""
82+ return f"3scale-{ self .provider_account_id } -{ account .entity_id } -1"
8383
8484 @staticmethod
8585 def _assert_transaction (invoice , transaction ):
0 commit comments