Appearance
useCashAppOrder
Create an onramp order, read checkout fields, and track status.
When to use
Amount form submit → checkout screen → pending payment. Session must be active. Pair with expiry & countdown on the checkout step.
Must be used under CashAppProvider. Order state is shared for the whole provider tree — deposit and checkout screens see the same order.
createOrder() builds the request from the current selection. Pass { amountFiat, destinationAsset, destinationChain } to create from explicit params instead.
There is no closeOrder. Creating a new order replaces any previous active order.
Example — create
tsx
import {
useCashAppAmount,
useCashAppOrder,
useCashAppSelection,
} from '@swapped/connect-sdk/react'
function DepositForm() {
const { canSubmit } = useCashAppSelection()
const { error: amountError, setTouched } = useCashAppAmount()
const { createOrder, isCreating, error, order } = useCashAppOrder()
async function onSubmit() {
setTouched(true)
if (!canSubmit) return
await createOrder()
}
return (
<div>
{(amountError || error) && (
<p>{(amountError?.message ?? error?.message)}</p>
)}
<button
type="button"
disabled={isCreating || !canSubmit}
onClick={() => void onSubmit()}
>
{isCreating ? 'Creating…' : 'Continue'}
</button>
{order && <p>Order {order.id} created</p>}
</div>
)
}Example — create with explicit params
tsx
import { Network, TokenSymbol } from '@swapped/connect-sdk'
import { useCashAppOrder } from '@swapped/connect-sdk/react'
function CustomDeposit() {
const { createOrder, isCreating, error } = useCashAppOrder()
return (
<button
type="button"
disabled={isCreating}
onClick={() =>
void createOrder({
amountFiat: '25.00',
destinationAsset: TokenSymbol.USDC,
destinationChain: Network.Solana,
})
}
>
{error ? error.message : isCreating ? 'Creating…' : 'Create order'}
</button>
)
}Passing a request does not read or write provider selection. Both call paths update the same shared order state.
Example — checkout
tsx
import {
useCashAppOrder,
useOnCashAppOrderExpired,
useOnCashAppOrderFailed,
} from '@swapped/connect-sdk/react'
function Checkout({
onExpired,
onFailed,
}: {
onExpired: () => void
onFailed: () => void
}) {
const { order, status, isCompleted, isFailed } = useCashAppOrder()
useOnCashAppOrderExpired(() => {
onExpired() // navigate back to deposit
})
useOnCashAppOrderFailed(() => {
onFailed() // navigate back to deposit
})
if (!order) return null
if (isCompleted) return <p>Payment received</p>
if (isFailed) return <p>Payment failed</p>
return (
<div>
<p>Status: {status}</p>
{/* 'pending' | 'success' | 'failure' | null */}
<a href={order.cashAppUrl} target="_blank" rel="noreferrer">
Open Cash App
</a>
{order.shortUrl && (
<a href={order.shortUrl} target="_blank" rel="noreferrer">
Open link
</a>
)}
{/* Encode order.invoice as a Lightning QR */}
</div>
)
}On expiry, order is cleared. Handle toast / navigate with useOnCashAppOrderExpired. expiredOrder is available if you still need the last order payload.
Checkout fields
| Field | Use for |
|---|---|
order.cashAppUrl | Open Cash App / encode as a Cash App QR |
order.shortUrl | Compact share / open link |
order.invoice | BTC Lightning invoice — encode as a Lightning QR |
order.fiatAmount / order.fiatCurrency | Deposit value (excluding fees) |
order.amount | Total fiat the user pays (includes fees) |
order.estimatedOut | Expected destination amount |
order.expiresAt | Countdown — see Expiry |
Returns
| Field | Purpose |
|---|---|
order | Active CashAppOrder or null (cleared on expiry) |
expiredOrder | Last expired order, or null (cleared on create / reset) |
status | 'pending' | 'success' | 'failure' or null |
isCompleted / isFailed / isExpired | Convenience flags |
createOrder() | Create from current selection |
createOrder(request) | Create from { amountFiat, destinationAsset, destinationChain } |
isCreating | In-flight flag |
error | Last action failure |
Errors
| Code | When | What to do |
|---|---|---|
REACT_CASH_APP_PROVIDER_REQUIRED | Used outside CashAppProvider | Wrap with the provider |
CASH_APP_SELECTION_INCOMPLETE | createOrder() missing asset / amount | Complete selection first, or pass a request |
SESSION_NOT_ACTIVE | Session cannot pay again | restartSession() |
SESSION_REQUIRED | Session not loaded | loadSession() |
API_ERROR | Create failure | Retry |
See Errors.