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

Sync all stripe subscriptions not only the active ones #107

Closed
Closed
Changes from all commits
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
20 changes: 15 additions & 5 deletions tap_stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
'key_properties': ['id', 'invoice']},
'transfers': {'sdk_object': stripe.Transfer, 'key_properties': ['id']},
'coupons': {'sdk_object': stripe.Coupon, 'key_properties': ['id']},
'subscriptions': {'sdk_object': stripe.Subscription, 'key_properties': ['id']},
'subscriptions': {
'sdk_object': stripe.Subscription,
'key_properties': ['id'],
'request_args': {'status': 'all'}
},
'subscription_items': {'sdk_object': stripe.SubscriptionItem, 'key_properties': ['id']},
'balance_transactions': {'sdk_object': stripe.BalanceTransaction,
'key_properties': ['id']},
Expand Down Expand Up @@ -371,14 +375,15 @@ def reduce_foreign_keys(rec, stream_name):
return rec


def paginate(sdk_obj, filter_key, start_date, end_date, limit=100):
def paginate(sdk_obj, filter_key, start_date, end_date, request_args=None, limit=100):
yield from sdk_obj.list(
limit=limit,
stripe_account=Context.config.get('account_id'),
# None passed to starting_after appears to retrieve
# all of them so this should always be safe.
**{filter_key + "[gte]": start_date,
filter_key + "[lt]": end_date}
filter_key + "[lt]": end_date},
**request_args or {}
).auto_paging_iter()


Expand Down Expand Up @@ -451,8 +456,13 @@ def sync_stream(stream_name):
if stop_window > end_time:
stop_window = end_time

for stream_obj in paginate(STREAM_SDK_OBJECTS[stream_name]['sdk_object'],
filter_key, start_window, stop_window):
for stream_obj in paginate(
STREAM_SDK_OBJECTS[stream_name]['sdk_object'],
filter_key,
start_window,
stop_window,
STREAM_SDK_OBJECTS[stream_name].get('request_args')
):

# get the replication key value from the object
rec = unwrap_data_objects(stream_obj.to_dict_recursive())
Expand Down