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

Enhancement to fetch payments data for all location_ids #119

Open
wants to merge 2 commits into
base: TDL-25358-bugfix
Choose a base branch
from
Open
Show file tree
Hide file tree
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
39 changes: 25 additions & 14 deletions tap_square/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,34 @@ def get_refunds(self, start_time, bookmarked_cursor):
body,
'refunds')

def get_payments(self, start_time, bookmarked_cursor):
start_time = utils.strptime_to_utc(start_time)
start_time = start_time - timedelta(milliseconds=1)
start_time = utils.strftime(start_time)
def get_payments(self, location_id, start_time, bookmarked_cursor):
if bookmarked_cursor:
cursor = bookmarked_cursor
else:
cursor = '__initial__' # initial value so while loop is always entered one time

body = {
}
body['begin_time'] = start_time
end_time = utils.strftime(utils.now(), utils.DATETIME_PARSE)
while cursor:
if cursor == '__initial__':
# initial text was needed to go into the while loop, but api needs
# it to be a valid bookmarked cursor or None
cursor = bookmarked_cursor

if bookmarked_cursor:
body['cursor'] = bookmarked_cursor
with singer.http_request_timer('GET payments'):
result = self._retryable_v2_method(
lambda bdy: self._client.payments.list_payments(
location_id=location_id,
begin_time=start_time,
end_time=end_time,
cursor=cursor,
limit=1000,
),
None,
)

yield from self._get_v2_objects(
'payments',
lambda bdy: self._client.payments.list_payments(**bdy),
body,
'payments')
yield (result.body.get('payments', []), result.body.get('cursor'))

cursor = result.body.get('cursor')

def get_cash_drawer_shifts(self, location_id, start_time, bookmarked_cursor):
if bookmarked_cursor:
Expand Down
6 changes: 3 additions & 3 deletions tap_square/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def sync(self, state, stream_schema, stream_metadata, config, transformer):
self.tap_stream_id,
transformed_record,
)
singer.write_bookmark(state, self.tap_stream_id, 'cursor', cursor)
singer.write_state(state)

state = singer.clear_bookmark(state, self.tap_stream_id, 'cursor')
singer.write_state(state)
Expand Down Expand Up @@ -189,7 +187,9 @@ class Payments(FullTableStream):
object_type = 'PAYMENT'

def get_pages(self, bookmarked_cursor, start_time):
yield from self.client.get_payments(start_time, bookmarked_cursor)
for location_id in Locations.get_all_location_ids(self.client):
# Payments requests can only take up to 1 location_id at a time
yield from self.client.get_payments(location_id, start_time, bookmarked_cursor)


class Orders(Stream):
Expand Down