Skip to main content
Add a checkout option that lets the sender pay a recipient by their ten-digit TIN. The sender approves the payment details and then approves the wallet deposit. Use the two resulting Solana signatures to confirm the deposit and the recipient’s credit before you mark the order paid.

Before you begin

  • Install the TSN SDK. Connect a wallet with signMessage and signTransaction support.
  • Get the Receiver URL, Solana RPC URL, and an accepted token mint for your TSN deployment. Fund the sender wallet with that token and enough SOL for the deposit transaction fee. Check your endpoints.
  • Have a registered recipient TIN. If you need one for your test, create a TIN first.
  • Resolve the recipient TIN in your trusted backend. Show the sender the TIN and display name from the lookup. Pass the resolved ownerPubkeyHash to the example. Configure recipient lookup.
Copy tsn-docs/sdk/examples/payment-flow.ts and tsn-docs/sdk/examples/credit-deposit.ts from the protocol checkout into your application. Save the three TypeScript blocks below as one module named wallet-payment.ts beside those files. Call the functions from your app with its wallet adapter, endpoints, and protected storage. This example uses Node.js ESM. For a browser integration, see the XP wallet flow and browser SDK entry point.

1. Submit the payment intent

Call startWalletPayment from your Approve payment action after the sender reviews the recipient, token, amount, and fee. Pass a decimal string such as "0.01". The SDK uses the token’s registered decimals. Generate one paymentId per payment and reuse it if the response is lost. The example sets the TSN sender fee to zero. The wallet still pays the Solana deposit fee.
Save session.workId from the POST /node/intents response. Implement retainIntent using protected application state. Keep the private funding note opening out of logs, analytics, public receipts, and persistent browser storage.

2. Approve and submit funding

Call waitForPaymentReadiness(session, signal) to wait for FUNDING_READY and load the deposit details. Use an AbortSignal to stop waiting when the sender leaves the screen. When the call resolves, enable Approve funding and pass the returned readiness to approveWalletFunding when the sender clicks it.
The helper fetches a fresh blockhash just before the wallet prompt. Implement retainCompletion to save the exact signed bytes and blockhash context together before the call to POST /node/network/funding/complete. Keep the completion with the same workId so you can recover a lost response.

3. Confirm the credit

Poll GET /api/work-status/{workId} with readWalletPayment. Display funding and credit separately. After both report CONFIRMED, the helper checks that both transactions finalized without errors on your Solana RPC.
Mark the order paid when finalized is true. If funding is confirmed and credit is still processing, show Deposit confirmed · Credit pending. Keep both signatures with the order. The recipient can then read their updated TIN balance.

Recover an interrupted payment

If the intent response is lost, submit the saved message, signature, and funding note with the same payment ID. If the funding response is lost, check the original workId and any recorded signature. Use the exact saved completion for a retry. For a stale approval or a rejected credit, follow payment troubleshooting to recover the original payment. Status fields · Service endpoints