Recover an interrupted payment or refund
Inspect the saved operation after a failure, cancellation or restart. Recover that operation before allowing a new payment or refund.
1. Restore the original context
Use the same API URL and storage ID. Attach an allowed merchant session and select the original merchant, branch, POS and serial.
val pending = withContext(Dispatchers.IO) { sdk.pendingOperation() }The snippets use the coroutine imports from the quickstart.
The snapshot contains kind, order ID, idempotency ID, phase and any known request ID/status. It excludes the saved payer and signature.
If no operation is retained, still check your host's order/flow records before initiating again. An empty SDK journal is not proof that the order has never been paid.
2. Choose the next action
| Saved state | Next action |
|---|---|
READING_NFC, PREPARED or CANCELLED_BEFORE_SUBMISSION | No financial POST was dispatched by this recorded attempt. After the active call finishes/cancels, acknowledge the abandoned attempt before an explicit new try |
| Definitive result: authorised, declined, blocked or failed | Recover the cached result, record it in host state, then acknowledge when safe |
| Known request ID with pending, timed-out or unknown result | Recover by GET using that request ID |
| Submitted with no request ID | Explicitly replay the saved POST, within the recovery window |
| Expired replay window, unreadable journal or context mismatch | Retain available records and use the agreed support/reconciliation process |
READING_NFC is the stored phase name for both NFC and Bluetooth acquisition. It does not identify which transport was selected.
3. Recover a known result or request
val result = withContext(Dispatchers.IO) { sdk.recoverOperation() }A definitive result is returned from storage. A known request ID is queried with GET. Neither path starts a new payment or asks the customer to tap again.
Record and handle the returned status using the payment result rules. A pending or timed-out result remains outstanding.
4. Explicitly replay an unknown submission
Use this only after deciding to recover a submitted operation whose response supplied no request ID:
val result = withContext(Dispatchers.IO) {
sdk.recoverOperation(replayInitiation = true)
}The SDK reuses the exact saved payer, amount, currency, location, reference, signature and idempotency ID. It uses the current merchant token. It does not rescan, re-sign or reconstruct a similar request.
Replay may return a definitive result directly, which the SDK caches. A later recovery uses GET only when a known request remains non-definitive. Replay is not always followed by another GET. Use the local recovery tests to inspect these paths with fake transports.
If the replay returns a definitive result, the SDK caches that result directly. If it returns a known request that remains unresolved, a later recovery uses GET for that same request. A replay does not require an unconditional follow-up GET.
Replay is allowed for at most 29 days from operation creation. A future creation timestamp or older journal returns RECOVERY_WINDOW_EXPIRED. The record remains stored. Known request IDs can still be queried after this replay window.
5. Acknowledge only when allowed
For an abandoned, never-submitted attempt, or a definitive result already saved in host state:
withContext(Dispatchers.IO) {
sdk.acknowledgeOperation(pending.idempotencyId)
}These snippets assume you have unwrapped a non-null pending snapshot and selected an acknowledgeable state from the table. Pending, timed-out and unknown submitted operations cannot be acknowledged.
Acknowledgement clears the local record. It does not complete or cancel anything at the server. Keep your durable order/refund receipt so the same completed host flow cannot initiate again.
Cancellation and logout
Cancel the owning coroutine or use cancelOperation() to stop local work. After submission, cancellation says nothing about the server outcome.
clear() removes the merchant session, selected terminal and terminal key, while retaining the financial journal. selectTerminal retains the merchant session, cancels in-flight payment work and clears the stored key only when its binding differs. A late server result can be saved even when the original caller receives a context or cancellation error. Recover using the original context; recovery uses the saved signature or GET and does not need the old private key.
Do not log, export or manually edit the encrypted journal. An error's outcomeUnknown flag is useful, but false on an unrelated error does not replace inspection of retained state.
Verify recovery before offering Retry
| Test | Check |
|---|---|
| Stop before submission | After the active call ends, inspect the never-submitted phase and explicitly abandon it |
| Lose the response after submission | Recover the existing request or explicitly replay the exact saved submission; never generate a replacement ID |
| Relaunch while pending | Restore the same API/storage and terminal context; the operation is still visible |
| Save a definitive result, fail acknowledgement | Recover the cached result and finish safe host handling |
| Acknowledge, then reopen the same checkout | Host receipt still prevents duplicate initiation |
| Lose journal or host flow / exceed replay window | Use the agreed external reconciliation process; keep new initiation blocked |
Use the native starters for the host flow/receipt structure. The application and backend teams must supply failure-injection and transaction-count evidence for these scenarios. See recoverOperation and acknowledgeOperation.
External reconciliation handoff
Before release, name the operations owner and agree how the host securely supplies the environment, original order/flow, terminal context, known request/idempotency IDs, time and last public phase/status. Define how the owner checks the authoritative server/order state and tells the app whether any new initiation is allowed.
The SDK provides no confirmed lookup-by-idempotency or server abort/reconcile endpoint in this contract. A missing journal or expired unknown submission remains blocked until the approved external process resolves it. Keep the developer requirements with the integration handoff.
Count attempts and financial creations
An exact replay of an unknown submission may make another HTTP POST using the original body, signature and idempotency ID. A passing recovery test demonstrates one financial request creation, not necessarily one HTTP attempt.
Use the approved response-drop control and backend count tooling from repeatable tests. Record the original request/host flow, journal phase, observed outcome and counts. A local fake transport or compilation result is separate from backend or physical-device acceptance.