Skip to content

feat(POINT-3697)(dc): poll the transaction after a lost opener - #290

Open
jakub-binczyk-cko wants to merge 7 commits into
feat/dc-opener-loss-verdictfrom
feat/POINT-3697/dc-opener-loss-polling
Open

jakub-binczyk-cko wants to merge 7 commits into
feat/dc-opener-loss-verdictfrom
feat/POINT-3697/dc-opener-loss-polling

Conversation

@jakub-binczyk-cko

@jakub-binczyk-cko jakub-binczyk-cko commented Nov 17, 2026 •

Copy link
Copy Markdown

Description

Follow-up to #289 (this PR is stacked on it). With opener_loss_handling: on, #289 shows a plain pending view when the PSP tab lost its link to the checkout (e.g. after a COOP page). This PR makes that path complete: DC waits for the real outcome by polling our invoice API, so the shopper sees success or failure without the merchant doing anything.

Design: RFC: Mercado Pago COOP-isolated return flow, section 4.3 and Q2.

Solution

  • DynamicCheckoutTransactionPoller (utils/transaction-poller.ts): polls GET invoices/{id}?expand=transaction with the client secret (the read DC already does on load). It never calls the PSP; the backend keeps the transaction in sync (webhook, reconcile).
    • Checks right away and on focus / visibilitychange. While the page is visible, the interval starts at 3 s and grows by 1.5x up to 30 s (about 35 requests in 15 minutes instead of about 300). Coming back to the page checks at once and starts again at 3 s. No requests while hidden; the last wait never runs past the timeout.
    • authorized, pending-capture, completed → success; failed, voided, blocked → failure; anything else keeps polling. Request errors keep polling.
    • Times out after 15 min (APM v2 default), also while hidden. apiRequest has no XHR timeout, so a request without an answer counts as an error after 30 s; a late answer is ignored. A final status that arrives after the widget was removed is ignored too.
    • Stops silently when the widget is removed from the page, or when stop() is called.
  • DynamicCheckoutOpenerLossFlow (utils/opener-loss-flow.ts), used by apm.ts and saved-apm.ts:
    • Shows the new DynamicCheckoutPaymentAwaitingConfirmationView: "Complete the payment in the other tab. This page will update automatically." with a Cancel button.
    • Success → payment_success with the same views as other APMs (success view, or info view without a return_url).
    • Failure → error view and payment_error (gateway.declined, with transaction_status).
    • Timeout → pending view and processout_dynamic_checkout_payment_pending {reason: "opener_isolated", timeout: true}, the first and only pending event.
    • Cancel → cancelled view and payment_cancelled {tab_closed: true}. Ignored once polling has reported an outcome (the view stays mounted for the merchant redirect when status messages are off).
    • A late postMessage result (token or error) after the lost opener: the first outcome wins, so DC never reports two outcomes.
    • No event while polling: the HPP treats payment_pending as final and unmounts DC.
  • Real close in on mode (DC page focused when the tab closes): DC checks the transaction once before showing "payment cancelled". A shopper whose PSP tab lost only its own opener sees the checkout "close this tab" landing, closes it, and DC sees a real close although the payment may be captured. Success → success view and payment_success; any other status, a request error or no answer within 10 s → "payment cancelled" as before. off and shadow are unchanged.
  • First result wins: if a postMessage token arrives after all, polling stops and the normal flow continues; if polling already reported an outcome, the late token is ignored. A new payment attempt resets the flow.
  • Two new translation keys in all 33 locales (payment-awaiting-confirmation-message, payment-awaiting-confirmation-cancel-button).

Demo

Staging, Mercado Pago MX sandbox, processout.js 1.9.23 (this branch) with opener_loss_handling: on from processout/api#6348:

  • Lost opener, simulated in the test tool (the popup handle reports closed after 3 s, window.opener = null in the popup): DC treated it as a lost opener (no payment_cancelled), polled GET invoices/{id}?expand=transaction once the shopper came back to the tab, and sent payment_success. No requests while the tab was hidden.
  • Opener kept: unchanged, payment_success with authorized: true, captured: true.
  • Not tested with a real COOP header from Mercado Pago.
  • Real close after a paid payment (only the PSP tab lost its opener, shopper closed the landing tab): DC checked the transaction once right after the close and showed success instead of "payment cancelled" (92838de on staging).

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

  • The translations other than English and Polish are machine-quality and should be reviewed by someone who knows the language.
  • The awaiting view reuses the pending icon and the pay button style.
  • Merge after feat(dc): tell a lost opener from a real tab close on tab_closed #289; the base branch will then switch to master.
  • The payment_success sent after polling has no authorized / captured fields (seen on staging); the normal flow has them.

Jira Issue

https://checkout.atlassian.net/browse/POINT-3697

Testing

  • test/dynamic-checkout/transaction-poller.test.ts: backoff from 3 s to 30 s, reset on return to the page, last wait clamped to the timeout, success and failure statuses, request errors, hidden page, focus, 15 min timeout (visible and hidden, and with requests that never answer), 30 s request timeout with a late answer, unmount (also with a response in flight), stop(), late response; both translation keys in every locale.
  • test/dynamic-checkout/opener-loss-flow.test.ts: views and events for waiting, success (with and without status messages), failure, timeout, Cancel (also after success with status messages off), and takeOver(); confirmClose() for success, waiting, failed, request error, no answer within 10 s, take-over (also at the 10 s deadline) and unmount before the response.
  • test/dynamic-checkout/opener-loss.test.ts: getTabClosedHandling for every mode × page state.
  • vitest (370 tests), tsc -p src/processout and eslint pass.

When opener_loss_handling is on and DC decides the PSP tab lost its link to the
checkout, DC now shows an awaiting-confirmation view with a Cancel button and
polls GET invoices/{id}?expand=transaction:

- right away, on focus / visibilitychange, then every 3 s while visible;
- authorized / pending-capture / completed -> payment_success;
- failed / voided / blocked -> payment_error;
- after 15 min -> payment_pending {reason: opener_isolated, timeout: true};
- Cancel -> payment_cancelled {tab_closed: true}.

No event is emitted while polling. A late postMessage token and the poller can't
both report an outcome: the first one wins.
…after a real tab close

In on mode, a real close (DC page focused) now checks the transaction once.
A shopper whose PSP tab lost only its own opener sees the close-this-tab
landing, closes it, and DC used to show payment cancelled although the
payment was captured. Success shows the success view and event; any other
status or a request error keeps payment cancelled. off and shadow are unchanged.
@jakub-binczyk-cko
jakub-binczyk-cko marked this pull request as ready for review November 24, 2026 14:17
@jakub-binczyk-cko jakub-binczyk-cko self-assigned this Nov 24, 2026
@jakub-binczyk-cko
jakub-binczyk-cko requested review from a team and mateusz-walesiak-cko and removed request for a team November 24, 2026 14:36
…3 s to 30 s

The interval grows by 1.5x after each check, up to 30 s, so a shopper who keeps
the DC tab open makes about 35 requests in 15 minutes instead of about 300.
Coming back to the tab still checks at once and starts again at 3 s, and the
last wait never runs past the timeout.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unbounded invoice requests can stall recovery indefinitely, while missing lifecycle and callback guards allow events after widget removal or contradictory terminal events, and save-for-future recovery drops the new customer token ID.

6 open issues
What changed in this PR

Extends #289’s lost-opener handling so Dynamic Checkout can recover payment outcomes by polling invoice status instead of leaving shoppers on a pending screen.

Changes:

  • Adds visibility-aware polling, an awaiting-confirmation view, and outcome handling for regular and saved alternative payment methods.
  • Checks transaction status once before treating a real tab close as cancellation.
  • Adds regression tests and messages in 33 locales, and bumps the version to 1.9.23.
File Description
test/​support/​loadNamespace.ts Adds loaders and browser shims for recovery tests.
test/​dynamic-checkout/​transaction-poller.test.ts Tests polling timing, outcomes, lifecycle, and translation keys.
test/​dynamic-checkout/​opener-loss.test.ts Tests tab-close handling across rollout modes.
test/​dynamic-checkout/​opener-loss-flow.test.ts Tests recovery views, events, cancellation, and takeover.
src/​dynamic-checkout/​views/​payment-awaiting-confirmation.ts Adds the waiting message and Cancel button.
src/​dynamic-checkout/​utils/​transaction-poller.ts Adds invoice polling with backoff and timeout handling.
src/​dynamic-checkout/​utils/​opener-loss.ts Distinguishes polling, close confirmation, and cancellation.
src/​dynamic-checkout/​utils/​opener-loss-flow.ts Coordinates recovery views, status checks, and events.
src/​dynamic-checkout/​utils/​events.ts Adds pending-event reason and timeout fields.
src/​dynamic-checkout/​references.ts Includes the new recovery utilities and view.
src/​dynamic-checkout/​payment-methods/​saved-apm.ts Integrates recovery into saved APM payments.
src/​dynamic-checkout/​payment-methods/​apm.ts Integrates recovery into regular and save-for-future payments.
src/​dynamic-checkout/​locales/​zh-tw.ts Adds Traditional Chinese waiting and cancel text.
src/​dynamic-checkout/​locales/​zh-cn.ts Adds Simplified Chinese waiting and cancel text.
src/​dynamic-checkout/​locales/​vi.ts Adds Vietnamese waiting and cancel text.
src/​dynamic-checkout/​locales/​uk.ts Adds Ukrainian waiting and cancel text.
src/​dynamic-checkout/​locales/​tr.ts Adds Turkish waiting and cancel text.
src/​dynamic-checkout/​locales/​th.ts Adds Thai waiting and cancel text.
src/​dynamic-checkout/​locales/​te.ts Adds Telugu waiting and cancel text.
src/​dynamic-checkout/​locales/​ta.ts Adds Tamil waiting and cancel text.
src/​dynamic-checkout/​locales/​sv.ts Adds Swedish waiting and cancel text.
src/​dynamic-checkout/​locales/​ru.ts Adds Russian waiting and cancel text.
src/​dynamic-checkout/​locales/​ro.ts Adds Romanian waiting and cancel text.
src/​dynamic-checkout/​locales/​pt.ts Adds Portuguese waiting and cancel text.
src/​dynamic-checkout/​locales/​pl.ts Adds Polish waiting and cancel text.
src/​dynamic-checkout/​locales/​nl.ts Adds Dutch waiting and cancel text.
src/​dynamic-checkout/​locales/​nb.ts Adds Norwegian Bokmål waiting and cancel text.
src/​dynamic-checkout/​locales/​ko.ts Adds Korean waiting and cancel text.
src/​dynamic-checkout/​locales/​kn.ts Adds Kannada waiting and cancel text.
src/​dynamic-checkout/​locales/​ja.ts Adds Japanese waiting and cancel text.
src/​dynamic-checkout/​locales/​it.ts Adds Italian waiting and cancel text.
src/​dynamic-checkout/​locales/​id.ts Adds Indonesian waiting and cancel text.
src/​dynamic-checkout/​locales/​hi.ts Adds Hindi waiting and cancel text.
src/​dynamic-checkout/​locales/​he.ts Adds Hebrew waiting and cancel text.
src/​dynamic-checkout/​locales/​fr.ts Adds French waiting and cancel text.
src/​dynamic-checkout/​locales/​fi.ts Adds Finnish waiting and cancel text.
src/​dynamic-checkout/​locales/​es.ts Adds Spanish waiting and cancel text.
src/​dynamic-checkout/​locales/​en.ts Adds English waiting and cancel text.
src/​dynamic-checkout/​locales/​el.ts Adds Greek waiting and cancel text.
src/​dynamic-checkout/​locales/​de.ts Adds German waiting and cancel text.
src/​dynamic-checkout/​locales/​da.ts Adds Danish waiting and cancel text.
src/​dynamic-checkout/​locales/​cs.ts Adds Czech waiting and cancel text.
src/​dynamic-checkout/​locales/​bn.ts Adds Bengali waiting and cancel text.
src/​dynamic-checkout/​locales/​bg.ts Adds Bulgarian waiting and cancel text.
src/​dynamic-checkout/​locales/​ar.ts Adds Arabic waiting and cancel text.
package.json Bumps the package version to 1.9.23.

Review effort: Balanced

…requests

- A late postMessage error after a lost opener goes through the same first-outcome-wins
  check as a late token, so it can't report a second outcome or leave polling running.
- The save-for-future path passes the new customer_token_id to the opener loss flow.
- Cancel on the awaiting view does nothing once polling has reported an outcome (the view
  stays mounted for the merchant redirect when status messages are off).
- apiRequest has no XHR timeout: a polling request counts as an error after 30 s, so the
  15 min timeout still fires, and the real-close check falls back to payment cancelled after 10 s.
- A final status that arrives after the widget was removed is ignored.
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.

2 participants