Repository navigation
feat(POINT-3697)(dc): poll the transaction after a lost opener - #290
Open
jakub-binczyk-cko wants to merge 7 commits into
Open
jakub-binczyk-cko wants to merge 7 commits into
jakub-binczyk-cko wants to merge 7 commits into
Conversation
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.
…ener-loss-polling
…ener-loss-polling
3 tasks done
…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
marked this pull request as ready for review
November 24, 2026 14:17
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.
Contributor
There was a problem hiding this comment.
🟡 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
Guard error callbacks against duplicate terminal events · New Forward the captured customer token ID to recovery events · New Bound the confirmClose request with a timeout · New Disable cancellation after polling reports success · New Keep the polling deadline active while requests are in flight · New Ignore terminal responses after the widget is detached · New
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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): pollsGET invoices/{id}?expand=transactionwith the client secret (the read DC already does on load). It never calls the PSP; the backend keeps the transaction in sync (webhook, reconcile).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.apiRequesthas 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.stop()is called.DynamicCheckoutOpenerLossFlow(utils/opener-loss-flow.ts), used byapm.tsandsaved-apm.ts:DynamicCheckoutPaymentAwaitingConfirmationView: "Complete the payment in the other tab. This page will update automatically." with a Cancel button.payment_successwith the same views as other APMs (success view, or info view without areturn_url).payment_error(gateway.declined, withtransaction_status).processout_dynamic_checkout_payment_pending {reason: "opener_isolated", timeout: true}, the first and only pending event.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).payment_pendingas final and unmounts DC.onmode (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 andpayment_success; any other status, a request error or no answer within 10 s → "payment cancelled" as before.offandshadoware unchanged.postMessagetoken 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.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: onfrom processout/api#6348:closedafter 3 s,window.opener = nullin the popup): DC treated it as a lost opener (nopayment_cancelled), polledGET invoices/{id}?expand=transactiononce the shopper came back to the tab, and sentpayment_success. No requests while the tab was hidden.payment_successwithauthorized: true, captured: true.92838deon staging).Checklist
yarn bump-versionNotes
master.payment_successsent after polling has noauthorized/capturedfields (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), andtakeOver();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:getTabClosedHandlingfor every mode × page state.vitest(370 tests),tsc -p src/processoutandeslintpass.