Skip to content

feat(apm)(POCP-1408): poll the payment while the redirect tab is open - #300

Draft
lukasz-k-bieszczad-cko wants to merge 1 commit into
feat/apm-sessions-web-redirectfrom
feat/apm-sessions-redirect-polling
Draft

lukasz-k-bieszczad-cko wants to merge 1 commit into
feat/apm-sessions-web-redirectfrom
feat/apm-sessions-redirect-polling

Conversation

@lukasz-k-bieszczad-cko

@lukasz-k-bieszczad-cko lukasz-k-bieszczad-cko commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

A deep link, or a Universal Link that opens the provider app, never posts back from the redirect tab. A return through checkout can also land in a new tab the widget doesn't know about. In both cases the redirect step ended with customer.canceled (tab_closed) or waited forever. #298 now opens deep links when there is no web link, so this PR is what makes them complete.

Agreed on the APM sync (2026-12-03): processout.js polls the payment during the redirect step and stops when the backend returns a different action_id.

Stacked on #298.

Solution

  • Shared backoff (src/apm/API.ts): the mobile SDK values, 150 ms × 1.45ⁿ clamped to 3–90 s, with no jitter. The wait is capped by confirmation.timeout (900 s by default).
    • The existing pending polling uses it too, instead of a fixed 1 s, which cuts a 15-minute poll from about 900 requests to about 25.
    • When the page becomes visible again (visibilitychange), the scheduled poll runs at once and the backoff restarts. initialise and sendFormData restart it too.
  • Redirect-step polling (APIImpl.pollRedirect, started by views/Redirect.ts when the tab opens): each poll is POST apm-payment.
    • Stop rule: the payment has left the step when action_id differs from the step's. Without an action_id, it has left when the answer is no longer a REDIRECT to the same origin and path. Query and hash are ignored, and custom schemes need an exact match.
    • Retries: status 0, 409 (api lock busy) and >500 retry at the next backoff step. Validation and api errors count as left, so the reload shows them.
    • On left: the tab closes through the new ActionHandler.cancel({ silent: true }), with no error and no telemetry. The view emits redirect-completed once and reloads the step, and that reload emits success. The poll itself never emits success.
    • At confirmation.timeout the chain ends silently. The tab's postMessage path keeps working.
  • Tab closed (APIImpl.checkRedirectOnce): one last poll before failing. If the payment left the step, the page reloads as above. If nothing changed, or the poll failed on the network, the old customer.canceled failure path runs.
  • Bug fix: network retries no longer loop forever. A retry used to spread the original options back over the decremented serviceRetries.

Demo

Not tested against the api yet, because the api doesn't send action_id yet. Covered by unit tests: 482 in 12 files, including the new test/apm/redirect-view.test.ts and silent-cancel tests for ActionHandler. They cover the backoff timing, the stop rule, retries, timeouts, the visibility reset, the last poll, and races with reloads, unmounts and second clicks.

Checklist

  • I bumped the version of the project using yarn bump-version
  • I have checked the code for any potential issues
  • I tested my changes in the browser

Notes

  • Behaviour changes:
    • Pending polls are sparser: up to 90 s apart late in the window.
    • A closed redirect tab now costs one extra POST before customer.canceled.
  • Open questions:
    • Should a plain 500 be retried? Today it counts as left, the same threshold as the existing network retry.
    • Does the api keep the redirect URL the same within a step? That matters only while action_id is missing.
  • The api must add action_id as a top-level field on apm-payment answers.

Jira Issue

POCP-1408

🤖 Generated with Claude Code

@lukasz-k-bieszczad-cko lukasz-k-bieszczad-cko changed the title feat(apm): poll the payment while the redirect tab is open feat(apm)(POCP-1408): poll the payment while the redirect tab is open Dec 3, 2026
@lukasz-k-bieszczad-cko
lukasz-k-bieszczad-cko force-pushed the feat/apm-sessions-redirect-polling branch from 1c8c34f to 8e85d6e Compare December 3, 2026 14:51
A deep link, or a Universal Link that opens the provider app, never posts
back from the redirect tab, and a return through checkout can land in a
new tab the widget does not know. The redirect step then ended with
`customer.canceled` (`tab_closed`) or waited forever.

Polling now uses the mobile SDK backoff, 150 ms * 1.45^n clamped to
3-90 s with no jitter, capped by `confirmation.timeout`. The pending
polling uses it too, instead of a fixed 1 s. A poll runs at once when the
page becomes visible again, and `initialise` and `sendFormData` restart
the backoff.

`APIImpl.pollRedirect` starts when the redirect tab opens and POSTs
apm-payment. The payment has left the step when `action_id` changes, or,
without one, when the answer is no longer a REDIRECT to the same origin
and path. Status 0, 409 (api lock busy) and >500 retry at the next step;
validation and api errors count as left. On left, the tab closes through
the new silent `ActionHandler.cancel({ silent: true })`, the view emits
`redirect-completed` once and reloads the step, which emits `success`.
At `confirmation.timeout` the chain ends silently.

When the tab is closed, `checkRedirectOnce` polls once before failing,
and the old `customer.canceled` path runs only if nothing changed.

Also fixes network retries without limit: a retry spread the original
options back over the decremented `serviceRetries`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukasz-k-bieszczad-cko
lukasz-k-bieszczad-cko force-pushed the feat/apm-sessions-redirect-polling branch from 8e85d6e to 2081933 Compare December 3, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant