Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Source Stripe: add checkout_sessions stream, checkout_sessions_line_item stream and promotion_codes stream #7345

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": ["null", "object"],
"properties": {
"id": {"type": ["null", "string"]},
"object": {"type": ["null", "string"]},
"after_expiration": {
"type": ["null", "object"],
"properties": {
"recovery": {
"type": ["null", "object"],
"properties": {
"allow_promotion_codes": {"type": ["null", "boolean"]},
"enabled": {"type": ["null", "boolean"]},
"expires_at": {"type": ["null", "integer"]},
"url": {"type": ["null", "string"]}
}
}
}
},
"allow_promotion_codes": {"type": ["null", "boolean"]},
"amount_subtotal": {"type": ["null", "integer"]},
"amount_total": {"type": ["null", "integer"]},
"automatic_tax": {
"enabled": {"type": ["null", "boolean"]},
"status": {"type": ["null", "string"]}
},
vladimir-remar marked this conversation as resolved.
Show resolved Hide resolved
"billing_address_collection": {"type": ["null", "string"]},
"cancel_url": {"type": ["null", "string"]},
"client_reference_id": {"type": ["null", "string"]},
"consent": {
"type": ["null", "object"],
"properties": {
"promotions": {"type": ["null", "string"]}
}
},
"consent_collection": {
"type": ["null", "object"],
"properties": {
"promotions": {"type": ["null", "string"]}
}
},
"currency": {"type": ["null", "string"]},
"customer": {"type": ["null", "string"]},
"customer_details": {
"type": ["null", "object"],
"properties": {
"email": {"type": ["null", "string"]},
"phone": {"type": ["null", "string"]},
"tax_exempt": {"type": ["null", "string"]},
"tax_ids": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"type": {"type": ["null", "string"]},
"value": {"type": ["null", "string"]}
}
}
}
}
},
"customer_email": {"type": ["null", "string"]},
"expires_at": {"type": ["null", "integer"]},
"livemode": {"type": ["null", "boolean"]},
"locale": {"type": ["null", "string"]},
"metadata": {
"type": ["null", "object"],
"properties": {}
},
"mode": {"type": ["null", "string"]},
"payment_intent": {"type": ["null", "string"]},
"payment_method_options": {
"type": ["null", "object"],
"properties": {
"acss_debit":{
"type": ["null", "object"],
"properties": {
"currency": {"type": ["null", "string"]},
"mandate_options": {
"type": ["null", "object"],
"properties": {
"custom_mandate_url": {"type": ["null", "string"]},
"default_for": {
"type": ["null", "array"],
"items": {
"type": ["null", "string"]
}
},
"interval_description": {"type": ["null", "string"]},
"payment_schedule": {"type": ["null", "string"]},
"transaction_type": {"type": ["null", "string"]}
}
},
"verification_method": {"type": ["null", "string"]}
}
},
"boleto":{
"type": ["null", "object"],
"properties": {
"expires_after_days": {"type": ["null", "integer"]}
}
},
"oxxo":{
"type": ["null", "object"],
"properties": {
"expires_after_days": {"type": ["null", "integer"]}
}
}
}
},
"payment_method_types": {
"type": ["null", "array"],
"items": {
"card": {"type": ["null", "string"]}
}
},
"payment_status": {"type": ["null", "string"]},
"phone_number_collection": {
"enabled": {"type": ["null", "boolean"]}
},
vladimir-remar marked this conversation as resolved.
Show resolved Hide resolved
"recovered_from": {"type": ["null", "string"]},
"setup_intent": {"type": ["null", "string"]},
"shipping": {
"type": ["null", "object"],
"properties": {
"address": {
"type": ["null", "object"],
"properties": {
"city": {"type": ["null", "string"]},
"country": {"type": ["null", "string"]},
"line1": {"type": ["null", "string"]},
"line2": {"type": ["null", "string"]},
"postal_code": {"type": ["null", "string"]},
"state": {"type": ["null", "string"]}
}
},
"name": {"type": ["null", "string"]}
}
},
"shipping_address_collection": {
"type": ["null", "object"],
"properties": {
"allowed_countries": {
"type": ["null", "array"],
"items": {
"type": ["null", "string"]
}
}
}
},
"submit_type": {"type": ["null", "string"]},
"subscription": {"type": ["null", "string"]},
"success_url": {"type": ["null", "string"]},
"tax_id_collection": {
"type": ["null", "object"],
"properties": {
"enabled": {"type": ["null", "boolean"]}
}
},
"total_details": {
"type": ["null", "object"],
"properties": {
"amount_discount": {"type": ["null", "integer"]},
"amount_shipping": {"type": ["null", "integer"]},
"amount_tax": {"type": ["null", "integer"]},
"breakdown": {
"type": ["null", "object"],
"properties": {
"discounts": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"amount": {"type": ["null", "integer"]},
"discount": {
"type": ["null", "object"],
"properties": {}
}
}
}
},
"taxes": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"integer": {"type": ["null", "string"]},
vladimir-remar marked this conversation as resolved.
Show resolved Hide resolved
"rate": {
"type": ["null", "object"],
"properties": {
"id": {"type": ["null", "string"]},
"object": {"type": ["null", "string"]},
"active": {"type": ["null", "boolean"]},
"country": {"type": ["null", "string"]},
"created": {"type": ["null", "integer"]},
"description": {"type": ["null", "string"]},
"display_name": {"type": ["null", "string"]},
"inclusive": {"type": ["null", "boolean"]},
"jurisdiction": {"type": ["null", "string"]},
"livemode": {"type": ["null", "boolean"]},
"metadata": {
"type": ["null", "object"],
"properties": {}
},
"percentage": {"type": ["null", "number"]},
"state": {"type": ["null", "string"]},
"tax_type": {"type": ["null", "string"]}
}
}
}
}
}
}
}
}
},
"url": {"type": ["null", "string"]}
}
}
vladimir-remar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": ["null", "object"],
"properties": {
"id": {"type": ["null", "string"]},
"checkout_session_id": {"type": ["null", "string"]},
"object": {"type": ["null", "string"]},
"amount_subtotal": {"type": ["null", "integer"]},
"amount_total": {"type": ["null", "integer"]},
"currency": {"type": ["null", "string"]},
"description": {"type": ["null", "string"]},
"discounts": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"amount": {"type": ["null", "integer"]},
"discount": {
"type": ["null", "object"],
"properties": {}
}
}
}
},
"price": {
"type": ["null", "object"],
"properties": {
"id": {"type": ["null", "string"]},
"object": {"type": ["null", "string"]},
"active": {"type": ["null", "boolean"]},
"billing_scheme": {"type": ["null", "string"]},
"created": {"type": ["null", "integer"]},
"currency": {"type": ["null", "string"]},
"livemode": {"type": ["null", "boolean"]},
"lookup_key": {"type": ["null", "string"]},
"metadata": {
"type": ["null", "object"],
"properties": {}
},
"nickname": {"type": ["null", "string"]},
"product": {"type": ["null", "string"]},
"recurring": {
"type": ["null", "object"],
"properties": {
"aggregate_usage": {"type": ["null", "string"]},
"interval": {"type": ["null", "string"]},
"interval_count": {"type": ["null", "integer"]},
"usage_type": {"type": ["null", "string"]}
}
},
"tax_behavior": {"type": ["null", "string"]},
"tiers": {
"type": ["null", "object"],
"properties": {
"flat_amount": {"type": ["null", "integer"]},
"flat_amount_decimal": {"type": ["null", "string"]},
"unit_amount": {"type": ["null", "integer"]},
"unit_amount_decimal": {"type": ["null", "string"]},
"up_to": {"type": ["null", "integer"]}
}
},
"tiers_mode": {"type": ["null", "string"]},
"transform_quantity": {
"type": ["null", "object"],
"properties": {
"divide_by": {"type": ["null", "integer"]},
"round": {"type": ["null", "string"]}
}
},
"type": {"type": ["null", "string"]},
"unit_amount": {"type": ["null", "integer"]},
"unit_amount_decimal": {"type": ["null", "string"]}
}
},
"quantity": {"type": ["null", "integer"]},
"taxes": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"amount": {"types": ["null", "integer"]},
"rate": {
"type": ["null", "object"],
"properties": {
"id": {"type": ["null", "string"]},
"object": {"type": ["null", "string"]},
"active": {"type": ["null", "boolean"]},
"country": {"type": ["null", "string"]},
"created": {"type": ["null", "integer"]},
"description": {"type": ["null", "string"]},
"display_name": {"type": ["null", "string"]},
"inclusive": {"type": ["null", "boolean"]},
"jurisdiction": {"type": ["null", "string"]},
"livemode": {"type": ["null", "boolean"]},
"metadata": {
"type": ["null", "object"],
"properties": {}
},
"percentage": {"type": ["null", "number"]},
"state": {"type": ["null", "string"]},
"tax_type": {"type": ["null", "string"]}
}
}
}
}
}
}
}
vladimir-remar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
BalanceTransactions,
BankAccounts,
Charges,
CheckoutSessions,
CheckoutSessionsLineItems,
Coupons,
CustomerBalanceTransactions,
Customers,
Expand Down Expand Up @@ -52,6 +54,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
BalanceTransactions(**incremental_args),
BankAccounts(**args),
Charges(**incremental_args),
CheckoutSessions(**args),
CheckoutSessionsLineItems(**args),
Coupons(**incremental_args),
CustomerBalanceTransactions(**args),
Customers(**incremental_args),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#


import re
import math
from abc import ABC, abstractmethod
from typing import Any, Iterable, Mapping, MutableMapping, Optional
Expand Down Expand Up @@ -348,3 +348,40 @@ def read_records(self, stream_slice: Optional[Mapping[str, Any]] = None, **kwarg
customers_stream = Customers(authenticator=self.authenticator, account_id=self.account_id, start_date=self.start_date)
for customer in customers_stream.read_records(sync_mode=SyncMode.full_refresh):
yield from super().read_records(stream_slice={"customer_id": customer["id"]}, **kwargs)


class CheckoutSessions(StripeStream):
"""
API docs: https://stripe.com/docs/api/checkout/sessions/list
"""

name = "checkout_sessions"

def path(self, **kwargs):
return "checkout/sessions"


class CheckoutSessionsLineItems(StripeStream):
"""
API docs: https://stripe.com/docs/api/checkout/sessions/line_items
"""

name = "checkout_sessions_line_items"

def path(self, stream_slice: Mapping[str, Any] = None, **kwargs):
return f"checkout/sessions/{stream_slice['checkout_session_id']}/line_items"

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

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:

response_json = response.json()
data = response_json.get("data", [])
if data:
for e in data:
checkout_session_id = re.search(r'/sessions/(cs_[^/].+)/line_items', response.url)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the checkout_session_id is saved into the line_items response, since it is not included line_items response.

e['checkout_session_id'] = checkout_session_id.group(1) if checkout_session_id else None
yield from data