From a2da77b814168f3f3c1975da580f425951304075 Mon Sep 17 00:00:00 2001 From: Somtom Date: Wed, 22 Dec 2021 15:06:31 +0100 Subject: [PATCH] Sync all stripe subscriptions not only the active ones --- tap_stripe/__init__.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tap_stripe/__init__.py b/tap_stripe/__init__.py index 2c06ec36..5736f297 100755 --- a/tap_stripe/__init__.py +++ b/tap_stripe/__init__.py @@ -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']}, @@ -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() @@ -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())