Skip to content

Commit

Permalink
Merge pull request #189 from EdgeApp/paul/fixPaybis
Browse files Browse the repository at this point in the history
Fix Paybis error when querying for transactions for the current day
  • Loading branch information
paullinator authored Apr 11, 2024
2 parents 10c2b5b + 7734efe commit 2ad07f8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/partners/paybis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ export async function queryPaybis(
): Promise<PluginResult> {
const { settings, apiKeys } = asStandardPluginParams(pluginParams)
const { apiKey } = apiKeys
const nowDate = new Date()
const now = nowDate.getTime()
const nowMidnightDate = new Date(nowDate)
nowMidnightDate.setUTCHours(0, 0, 0, 0)
const nowMidnight = nowMidnightDate.getTime()

let { latestIsoDate } = settings

if (latestIsoDate === EDGE_APP_START_DATE) {
Expand All @@ -169,19 +175,22 @@ export async function queryPaybis(

while (true) {
const endTime = startTime + QUERY_TIME_BLOCK_MS
const now = Date.now()

try {
let cursor: string | undefined

while (true) {
const urlObj = new URL(URLS.prod, true)

// From value cannot exceed midnight of the current day
const fromTime = startTime > nowMidnight ? nowMidnight : startTime

const queryParams: any = {
from: new Date(startTime).toISOString(),
from: new Date(fromTime).toISOString(),
to: new Date(endTime).toISOString(),
limit: QUERY_LIMIT_TXS
}
datelog(`Querying from:${queryParams.from} to:${queryParams.to}`)
if (cursor != null) queryParams.cursor = cursor

urlObj.set('query', queryParams)
Expand Down

0 comments on commit 2ad07f8

Please sign in to comment.