Wallet payment flows
A wallet consumes an offer as a payment intent, verifies it, validates the payer's intended request, resolves it into one new invoice, then sends that invoice through Fiber only after the user confirms.
Resolve a Fiber Address
A Fiber Address is wallet input, not a clickable browser URL. Parse its domain, retrieve the signed offer from the well-known endpoint, and then use the offer ID with the resolver that returned it. Browser users should receive the offer's payment link or link QR instead.
import { FiberOffersClient } from "@fiber-offers/sdk";
const resolver = new FiberOffersClient({
resolverUrl: "https://fiber-offers.leothatguy.me"
});
const offer = await resolver.resolveFiberAddress(
"coffee@fiber-offers.leothatguy.me"
);
const invoice = await resolver.requestInvoice(offer.offer_id, {
amount: "100000000",
asset: { asset_type: "ckb", symbol: "CKB" }
});
await payer.sendPayment(invoice.invoice);
The merchant shares the address repeatedly, but every call to requestInvoice produces a payment-attempt-specific fibt... invoice. The payer never needs the merchant API key or Fiber RPC credentials.
Wallet responsibilities
Discover
Accept a payment link, an encoded offer, a QR payload, or a Fiber Address. Fetch current resolver metadata when the user chooses to continue.
Verify
Decode the offer and verify its Ed25519 signature. Do not treat resolver transport alone as proof of merchant intent.
Check
Call resolver readiness with the exact amount and asset. Render offer or merchant-node failures before requesting an invoice.
Execute explicitly
Request an invoice with an idempotency key, show the final amount, and call Fiber payment only after explicit user approval.
Recommended payment sequence
- Resolve the payment link, address, or encoded offer into a signed offer.
- Verify the offer signature and show the merchant, asset, and price semantics.
- Collect an amount only for customer-chosen or range pricing.
- Call
POST /offers/:offer_id/checkwith the selected amount and asset. - Use the same checkout attempt ID as the idempotency key for
invoice. - Show the returned invoice summary and ask for confirmation.
- Dry-run the invoice through the payer's Fiber node, then send only when the route is payable.
- Retain the resolution ID for status and receipt lookup.
SDK payment preparation
FiberPaymentFlowClient composes resolver readiness, invoice resolution, and payer-side route confidence. Its preparePayment method does not execute payment.
import {
FiberOffersClient,
FiberPaymentClient,
FiberPaymentFlowClient
} from "@fiber-offers/sdk";
const resolver = new FiberOffersClient({
resolverUrl: "https://resolver.example"
});
const payer = new FiberPaymentClient({
url: "http://127.0.0.1:8229"
});
const flow = new FiberPaymentFlowClient({
resolverClient: resolver,
paymentClient: payer
});
const request = {
amount: "1000",
asset: { asset_type: "ckb", symbol: "CKB" }
};
const prepared = await flow.preparePayment(offerId, request, {
idempotencyKey: "checkout-order-42"
});
if (!prepared.ok) {
showPaymentProblem(prepared.failure, prepared.readiness?.next_actions);
return;
}
showConfirmation(prepared.invoice.invoice);
An offer may list fallback resolvers in extensions.fallback_resolvers. When the resolver in use cannot be reached, times out or answers with a 5xx, the flow sends the same request, with the same idempotency key, to the offer's next resolver. It never moves on after a 4xx. The result names the resolver that answered (resolver_url) and any it skipped (resolver_failures). Every invoice is verified the same way whichever resolver issued it.
After confirmation, opt into actual payment. This explicit flag protects application code from accidentally sending funds while it is only testing readiness.
const result = await flow.payOffer(offerId, request, {
idempotencyKey: "checkout-order-42",
execute: true
});
if (result.status === "payment_sent") {
showSuccess(result.payment_hash, result.fee);
}
Pricing cases to render clearly
Fixed amount
Do not show an amount editor. The wallet requests the one fixed amount from the offer and rejects any attempt to substitute a different amount.
Customer chooses amount
Show an amount input with the offer minimum. Call readiness again whenever the selected value changes before enabling the confirmation path.
Amount range
Show both the minimum and maximum. Keep the selected amount visible through invoice confirmation, because that is the value the resolver validates and records.
Failure and retry handling
Readiness results carry a structured code, summary, blockers, warnings, and next_actions. Prefer these to raw RPC error messages in the wallet UI.
| Situation | Wallet behavior |
|---|---|
| Offer signature invalid | Stop. Do not request an invoice and show that the payment intent could not be verified. |
Offer revoked (OFFER_REVOKED) | Stop. The merchant revoked the offer with its own key, and that is permanent. |
Offer switched off (OFFER_DISABLED) | Show that the merchant has switched the offer off. Do not retry automatically. The merchant can switch it back on, so let the user try again later. |
| Amount or asset rejected | Return to amount or asset selection. The offer remains usable if the new request is valid. |
| Route or liquidity blocker | Show the normalized summary and next actions. Do not imply a payment will succeed. |
| Invoice request timeout | Retry with the same idempotency key and payment request. |
| Fiber send failure | Keep the raw node error for diagnostics, but present the normalized failure and suggest the next action. |
An offer that cannot be paid answers an invoice request with 410 and one of two codes. OFFER_REVOKED means a signed revocation. OFFER_DISABLED means the merchant switched the offer off on its resolver, which can be undone. Readiness reports the same code on its failing offer_state check, and GET /offers/:offer_id shows disabled: true, with revoked_at only for a revocation. An invoice issued before the switch stays payable until it expires.
A single-use offer is also safe under concurrent use. While another payer's invoice is unpaid, the resolver answers OFFER_INVOICE_OUTSTANDING with the time it lapses, and the offer becomes available again if it is not paid. Once the offer has been paid it answers OFFER_ALREADY_USED.