Skip to content

Commit

Permalink
馃帀 Source Stripe: support reading data from connected accounts (#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherifnada committed Apr 28, 2021
1 parent 88b77aa commit 95140cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-stripe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY $CODE_PATH ./$CODE_PATH
COPY setup.py ./
RUN pip install .

LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.version=0.1.2
LABEL io.airbyte.name=airbyte/source-stripe
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
class StripeStream(HttpStream, ABC):
url_base = "https://api.stripe.com/v1/"

def __init__(self, account_id: str, **kwargs):
super().__init__(**kwargs)
self.account_id = account_id

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
decoded_response = response.json()
if bool(decoded_response.get("has_more", "False")) and decoded_response.get("data", []):
Expand All @@ -56,6 +60,9 @@ def request_params(

return params

def request_headers(self, **kwargs) -> Mapping[str, Any]:
return {"Stripe-Account": self.account_id}

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
response_json = response.json()
yield from response_json.get("data", []) # Stripe puts records in a container array "data"
Expand Down Expand Up @@ -158,7 +165,7 @@ def path(self, stream_slice: Mapping[str, any] = None, **kwargs):
return f"invoices/{stream_slice['invoice_id']}/lines"

def read_records(self, stream_slice: Optional[Mapping[str, Any]] = None, **kwargs) -> Iterable[Mapping[str, Any]]:
invoices_stream = Invoices(authenticator=self.authenticator)
invoices_stream = Invoices(authenticator=self.authenticator, account_id=self.account_id)
for invoice in invoices_stream.read_records(sync_mode=SyncMode.full_refresh):
yield from super().read_records(stream_slice={"invoice_id": invoice["id"]}, **kwargs)

Expand Down Expand Up @@ -211,7 +218,7 @@ def request_params(self, stream_slice: Mapping[str, any] = None, **kwargs):
return params

def read_records(self, stream_slice: Optional[Mapping[str, Any]] = None, **kwargs) -> Iterable[Mapping[str, Any]]:
subscriptions_stream = Subscriptions(authenticator=self.authenticator)
subscriptions_stream = Subscriptions(authenticator=self.authenticator, account_id=self.account_id)
for subscriptions in subscriptions_stream.read_records(sync_mode=SyncMode.full_refresh):
yield from super().read_records(stream_slice={"subscription_id": subscriptions["id"]}, **kwargs)

Expand Down Expand Up @@ -243,7 +250,7 @@ def request_params(self, **kwargs) -> MutableMapping[str, Any]:
return params

def read_records(self, stream_slice: Optional[Mapping[str, Any]] = None, **kwargs) -> Iterable[Mapping[str, Any]]:
customers_stream = Customers(authenticator=self.authenticator)
customers_stream = Customers(authenticator=self.authenticator, account_id=self.account_id)
for customer in customers_stream.read_records(sync_mode=SyncMode.full_refresh):
yield from super().read_records(stream_slice={"customer_id": customer["id"]}, **kwargs)

Expand All @@ -259,24 +266,24 @@ def check_connection(self, logger, config) -> Tuple[bool, any]:

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = TokenAuthenticator(config["client_secret"])

args = {"authenticator": authenticator, "account_id": config["account_id"]}
return [
BalanceTransactions(authenticator=authenticator),
Charges(authenticator=authenticator),
Coupons(authenticator=authenticator),
Customers(authenticator=authenticator),
CustomerBalanceTransactions(authenticator=authenticator),
Disputes(authenticator=authenticator),
Events(authenticator=authenticator),
InvoiceItems(authenticator=authenticator),
InvoiceLineItems(authenticator=authenticator),
Invoices(authenticator=authenticator),
Plans(authenticator=authenticator),
Payouts(authenticator=authenticator),
Products(authenticator=authenticator),
Subscriptions(authenticator=authenticator),
SubscriptionItems(authenticator=authenticator),
Transfers(authenticator=authenticator),
Refunds(authenticator=authenticator),
BankAccounts(authenticator=authenticator),
BalanceTransactions(**args),
Charges(**args),
Coupons(**args),
Customers(**args),
CustomerBalanceTransactions(**args),
Disputes(**args),
Events(**args),
InvoiceItems(**args),
InvoiceLineItems(**args),
Invoices(**args),
Plans(**args),
Payouts(**args),
Products(**args),
Subscriptions(**args),
SubscriptionItems(**args),
Transfers(**args),
Refunds(**args),
BankAccounts(**args),
]

0 comments on commit 95140cb

Please sign in to comment.