Skip to content
Get started
Menu
Get started

Wallet handoff and return

Let the buyer open a supported wallet app on the phone where they started checkout. Back in your app, Check status asks about the original payment attempt. Opening the wallet, returning to checkout and canceling the wallet step are not payment results.

Open Wallet handoff in the example Gallery, or run the standalone demo from example/:

Terminal window
flutter run -d <device-id> -t lib/wallet_handoff_demo.dart

The demo doesn’t open another app. With Aplikasi tersedia selected, open the wallet and choose Simulasi kembali or Simulasi batal. The first status check returns pending. A second check returns a separate, synthetic provider confirmation. The standalone demo’s Skenario demo menu also covers these cases:

Scenario What the buyer can do
Aplikasi tidak tersedia The wallet couldn’t open. Check status on the same payment.
Tidak kembali dari dompet Simulate restoring checkout without a wallet return. The demo doesn’t persist anything. The first check keeps the pending status when the provider is unreachable. The next check receives a provider-reported expiry.
  1. Pass the existing PaymentAttempt and exact Money amount from its approved quote. Only pass WalletHandoffPhase.ready when your provider has authorized the handoff for that attempt. Include PaymentAction.checkStatus in the accepted snapshot while the buyer can recover the payment. The block won’t offer launch without that action. Put it in a bounded screen body to keep Check status pinned.
  2. Use openWalletHandoff in onOpenWallet(attemptId) with callbacks that capture the current attempt and wallet authorization. The recipe claims ready as opening before persisting. If saving throws, it never launches: it restores ready only if the same handoff is still opening and the authorization is valid, or clears that handoff to keep status recovery available. Catch the error in your host and tell the buyer the wallet didn’t open because checkout couldn’t be saved. After saving, the recipe requires the same attempt to still be opening and checks the captured authorization again immediately before launch. Your app owns the SDK or URL, return route, and launch error reporting. Return false for an expected launch failure so the recipe can show appUnavailable if the handoff still owns opening.
  3. Apply a correlated return or cancellation once, from opening or awaitingReturn, even if both the return route and app resume fire. An uncorrelated resume can take the buyer back to checkout but cannot establish wallet success or cancellation. If checkout is restored without a return, recover the persisted attempt and use noReturn. Validate the restored snapshot against that attempt before rendering it. Ignore signals from earlier attempts.
  4. In onCheckStatus(attemptId), query that same attempt, never submit again. Set Observation.refreshing and prevent repeated checks while it runs. Use PaymentAttempt.reconcile on a matching authoritative reply. An unchanged revision can be a valid answer: retain the last trusted snapshot and clear refreshing even when reconciliation doesn’t apply it. If status couldn’t be checked, retain the snapshot and set Observation.unavailable. Don’t update a replacement attempt. If submission is unknown, pass the original attempt and use the existing unknown-status recovery. Only a provider snapshot can confirm success or expiry.

The block offers one handoff and status recovery, with no retry payment or method change. If the host later offers a new payment, follow the Status and receipt pattern to decide when the original attempt can be replaced.

Source: compositions/wallet_handoff_block.dart

Open this file on GitHub. Copy and adapt it in your host app.

import 'package:flutter/material.dart';
import 'package:rakit_ui/rakit_ui.dart';
/// Host-reported handoff progress, separate from the payment's business status.
enum WalletHandoffPhase {
ready,
opening,
awaitingReturn,
returned,
appUnavailable,
canceled,
noReturn,
}
typedef WalletHandoff = ({String attemptId, WalletHandoffPhase phase});
/// Host-side recipe for [WalletHandoffBlock.onOpenWallet]. The caller captures
/// the attempt and wallet authorization in its callbacks. [isAuthorized] must
/// only read state and must reject a replaced attempt or authorization.
/// Don't re-arm the same attempt while its earlier handoff is still in flight.
/// If [persistAttempt] throws, no launch occurs. Catch the error in the host
/// to explain that the attempt could not be saved. [launchWallet] reports
/// expected launch failures as `false`, independent of payment status.
Future<void> openWalletHandoff({
required String attemptId,
required WalletHandoff? Function() readHandoff,
required void Function(WalletHandoff?) writeHandoff,
required bool Function() isAuthorized,
required Future<void> Function() persistAttempt,
required Future<bool> Function() launchWallet,
}) async {
final ready = (attemptId: attemptId, phase: WalletHandoffPhase.ready);
if (readHandoff() != ready || !isAuthorized()) return;
final opening = (attemptId: attemptId, phase: WalletHandoffPhase.opening);
writeHandoff(opening);
try {
await persistAttempt();
} catch (_) {
if (readHandoff() == opening) {
writeHandoff(isAuthorized() ? ready : null);
}
rethrow;
}
if (readHandoff() != opening) return;
if (!isAuthorized()) {
writeHandoff(null);
return;
}
final opened = await launchWallet();
if (readHandoff() == opening) {
writeHandoff((
attemptId: attemptId,
phase: opened
? WalletHandoffPhase.awaitingReturn
: WalletHandoffPhase.appUnavailable,
));
}
}
/// Copyable host block for one wallet and one existing payment attempt.
/// Wallet callbacks and lifecycle events cannot update the payment status here.
class WalletHandoffBlock extends StatelessWidget {
const WalletHandoffBlock({
super.key,
required this.attempt,
required this.amount,
required this.onOpenWallet,
required this.onCheckStatus,
this.handoff,
});
final PaymentAttempt attempt;
final Money amount;
final WalletHandoff? handoff;
final Future<void> Function(String attemptId) onOpenWallet;
final Future<void> Function(String attemptId) onCheckStatus;
@override
Widget build(BuildContext context) {
final id = attempt.attemptId;
final snapshot = attempt.snapshot;
final handoff = this.handoff;
final phase =
handoff != null &&
handoff.attemptId == id &&
(handoff.phase != WalletHandoffPhase.ready ||
(attempt.observation == Observation.fresh &&
attempt.availableActions.contains(
PaymentAction.checkStatus,
))) &&
attempt.submission == SubmissionState.accepted &&
(attempt.status == PaymentStatus.pending ||
attempt.status == PaymentStatus.requiresAction)
? handoff.phase
: null;
final showAmountBeforeLaunch =
phase == WalletHandoffPhase.ready ||
phase == WalletHandoffPhase.opening;
// This block can only open the existing authorization or check its status.
// Other host actions belong outside it, even after a terminal result.
final statusAttempt =
snapshot != null &&
snapshot.allowedActions.any((a) => a != PaymentAction.checkStatus)
? attempt.copyWith(
snapshot: PaymentStatusSnapshot(
attemptId: snapshot.attemptId,
serverReference: snapshot.serverReference,
status: snapshot.status,
revision: snapshot.revision,
updatedAt: snapshot.updatedAt,
safeReason: snapshot.safeReason,
refund: snapshot.refund,
instructions: snapshot.instructions,
isCorrection: snapshot.isCorrection,
allowedActions: {
if (snapshot.allowedActions.contains(PaymentAction.checkStatus))
PaymentAction.checkStatus,
},
),
)
: attempt;
return PaymentStatusView(
key: ValueKey(id),
attempt: statusAttempt,
amount: showAmountBeforeLaunch ? null : amount,
header: phase == null
? null
: _instructions(context, phase, () => onOpenWallet(id)),
onAction: (action) async {
if (action == PaymentAction.checkStatus) await onCheckStatus(id);
},
);
}
Widget _instructions(
BuildContext context,
WalletHandoffPhase phase,
Future<void> Function() open,
) {
final id = Localizations.localeOf(context).languageCode == 'id';
final canOpen = phase == WalletHandoffPhase.ready;
final opening = phase == WalletHandoffPhase.opening;
final (title, message, tone) = switch (phase) {
WalletHandoffPhase.ready || WalletHandoffPhase.opening => (
id ? 'Bayar di dompet digital' : 'Pay in your wallet',
id
? 'Buka aplikasi dompet di perangkat ini, lalu kembali untuk cek status.'
: 'Open the wallet app on this device, then come back to check status.',
StatusTone.info,
),
WalletHandoffPhase.awaitingReturn => (
id ? 'Menunggu kembali dari dompet' : 'Waiting for wallet return',
id
? 'Jika sudah selesai di aplikasi dompet, cek status di sini.'
: 'If you finished in the wallet app, check status here.',
StatusTone.info,
),
WalletHandoffPhase.returned => (
id ? 'Kembali dari dompet' : 'Back from wallet',
id
? 'Cek status untuk memastikan pembayaran ini.'
: 'Check status to confirm this payment.',
StatusTone.info,
),
WalletHandoffPhase.appUnavailable => (
id ? 'Aplikasi dompet tidak tersedia' : 'Wallet app unavailable',
id
? 'Aplikasi tidak dapat dibuka. Cek status sebelum membayar lagi.'
: 'The app could not open. Check status before paying again.',
StatusTone.warning,
),
WalletHandoffPhase.canceled => (
id ? 'Batal di aplikasi dompet' : 'Wallet step canceled',
id
? 'Cek status untuk mengetahui apakah pembayaran tercatat.'
: 'Check status to see whether this payment went through.',
StatusTone.warning,
),
WalletHandoffPhase.noReturn => (
id ? 'Belum ada respons dari dompet' : 'No return from wallet',
id
? 'Cek status pembayaran ini sebelum mencoba lagi.'
: 'Check this payment’s status before trying again.',
StatusTone.warning,
),
};
final theme = PaymentTheme.of(context);
return Padding(
padding: EdgeInsets.only(bottom: theme.space(PaymentSpace.group)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (canOpen || opening) ...[
Align(
alignment: AlignmentDirectional.centerStart,
child: AmountText(amount, variant: AmountTextVariant.display),
),
SizedBox(height: theme.space(PaymentSpace.related)),
],
PaymentBanner(
tone: tone,
title: title,
message: message,
announce: !canOpen && !opening,
),
if (canOpen || opening) ...[
SizedBox(height: theme.space(PaymentSpace.related)),
PaymentButton(
label: id ? 'Buka dompet' : 'Open wallet',
variant: PaymentButtonVariant.secondary,
busyLabel: id ? 'Membuka dompet' : 'Opening wallet',
busy: opening,
onPressed: canOpen ? open : null,
),
],
],
),
);
}
}

The demo exercises a simulated host boundary. Before claiming provider support, wire a supported wallet to an Android sandbox host and run checkout on one phone. Open the wallet, return both through its callback and by switching apps, and confirm that neither path produces a receipt before a matching server status. Repeat without the wallet installed, with a wallet cancellation, and after leaving the checkout without a return and reopening it. In each case, verify that the lookup uses the original attempt reference and makes no second payment submission.