Skip to content

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

FieldUse for
order.cashAppUrlOpen Cash App / encode as a Cash App QR
order.shortUrlCompact share / open link
order.invoiceBTC Lightning invoice — encode as a Lightning QR
order.fiatAmount / order.fiatCurrencyDeposit value (excluding fees)
order.amountTotal fiat the user pays (includes fees)
order.estimatedOutExpected destination amount
order.expiresAtCountdown — see Expiry

Returns

FieldPurpose
orderActive CashAppOrder or null (cleared on expiry)
expiredOrderLast expired order, or null (cleared on create / reset)
status'pending' | 'success' | 'failure' or null
isCompleted / isFailed / isExpiredConvenience flags
createOrder()Create from current selection
createOrder(request)Create from { amountFiat, destinationAsset, destinationChain }
isCreatingIn-flight flag
errorLast action failure

Errors

CodeWhenWhat to do
REACT_CASH_APP_PROVIDER_REQUIREDUsed outside CashAppProviderWrap with the provider
CASH_APP_SELECTION_INCOMPLETEcreateOrder() missing asset / amountComplete selection first, or pass a request
SESSION_NOT_ACTIVESession cannot pay againrestartSession()
SESSION_REQUIREDSession not loadedloadSession()
API_ERRORCreate failureRetry

See Errors.