Repository navigation
feat(POINT-3697)(dc): poll the transaction after a lost opener - #290
jakub-binczyk-cko wants to merge 11 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
…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.
…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.
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.
…o feat/POINT-3697/dc-opener-loss-polling # Conflicts: # src/dynamic-checkout/utils/opener-loss.ts # test/dynamic-checkout/opener-loss.test.ts
…ener-loss-polling
| * awaiting-confirmation view and polls the transaction; it emits no event until the outcome is known, | ||
| * because the HPP (and likely merchants) treat payment_pending as final. | ||
| */ | ||
| export class DynamicCheckoutOpenerLossFlow { |
There was a problem hiding this comment.
Could we report how this flow ends to telemetry? #289 sends the verdict, but in on mode that's all we'll see. We won't know whether a lost opener ended in success, failure, timeout, Cancel or how long it took.
One info report when the flow finishes would cover it.
There was a problem hiding this comment.
Added an event reported once per flow
| private cancel() { | ||
| if (this.poller.isFinished()) { | ||
| return | ||
| } | ||
| this.poller.stop() | ||
| this.showCancelled() |
There was a problem hiding this comment.
Cancel goes straight to "payment cancelled" without looking at the transaction.
isFinished() only says whether the poller already reported something, so a payment that went through but hasn't been picked up by the next poll yet ends as payment_cancelled.
Could Cancel reuse what confirmClose does? Show the loading view, check the transaction once, then go to success or cancelled.
There was a problem hiding this comment.
It now stops polling and runs the check
…o feat/POINT-3697/dc-opener-loss-polling # Conflicts: # src/dynamic-checkout/payment-methods/apm.ts # src/dynamic-checkout/payment-methods/saved-apm.ts
… outcome and share the tab_closed handling - Cancel on the awaiting view stops polling and checks the transaction once, so a payment that completed since the last poll shows success instead of cancelled. - The flow reports one outcome telemetry event (success, failure, timeout, cancelled or superseded) with its trigger and the time since the action started. - DynamicCheckoutOpenerLossFlow.handleTabClosed holds the tab_closed handling shared by the APM and saved APM handlers.

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.