cimplify
TypeScript SDK

FX

Spot rates and locked quotes for cross-currency purchase intents. Lock the displayed rate, then pass its ID into Cart intent preparation so the accepted FX evidence is frozen in immutable terms.

Get a spot rate

const r = await client.fx.getRate('GHS', 'USD')
if (!r.ok) {
  console.error(r.error.code, r.error.message)
  return
}

console.log(r.value.rate, r.value.inverse_rate)
console.log(r.value.quoted_at, r.value.valid_until)

Lock a quote

A locked quote freezes the rate for a short window. Pass fx_quote_id into Cart purchase-intent preparation to bind the displayed rate to immutable terms.

import { money } from '@cimplify/sdk'

const r = await client.fx.lockQuote({
  from: 'GHS',
  to: 'USD',
  amount: money('249.99'),       // Money is a branded string
}, {
  idempotencyKey: 'fx-lock-checkout-flow-once', // optional
})

if (!r.ok) {
  console.error(r.error.code, r.error.message)
  return
}

const quote = r.value
console.log(quote.id)
console.log(quote.base_amount, '→', quote.converted_amount)
console.log(quote.rate, 'valid until', quote.valid_until)

Use it at checkout

import {
  ORDER_TYPE,
  PURCHASE_INTENT_PAYMENT_METHOD,
  PURCHASE_INTENT_SOURCE_KIND,
} from '@cimplify/sdk'

const lock = await client.fx.lockQuote({ from: 'GHS', to: 'USD', amount: cart.pricing.total_price })
if (!lock.ok) return

const r = await client.purchaseIntents.mint({
  client_intent_key: stableKey,
  source: { kind: PURCHASE_INTENT_SOURCE_KIND.CART, cart_id: cart.id },
  checkout: {
    customer: { /* ... */ },
    order_type: ORDER_TYPE.PICKUP,
    address_info: {},
    pay_currency: 'USD',
    fx_quote_id: lock.value.id,
    tender_preference: { method_kind: PURCHASE_INTENT_PAYMENT_METHOD.CARD },
  },
})

if (r.ok) renderTerms(r.value.current_terms)

FxQuote shape

FieldTypeNotes
idstringPass to Cart purchase-intent preparation as fx_quote_id.
base_currencyCurrencyCodee.g. 'GHS'
pay_currencyCurrencyCodee.g. 'USD'
ratenumberbase → pay multiplier
inverse_ratenumberpay → base multiplier
base_amountMoneyBranded string
converted_amountMoneyBranded string
quoted_atstringISO timestamp
valid_untilstringISO timestamp; refresh after

Method reference

MethodReturns
getRate(from, to)Result<FxRateResponse>
lockQuote(input, opts?)Result<FxQuote>
  • Checkout Where the locked quote is consumed

  • Money type Branded strings, parsePrice, formatPrice

  • Cart Source of the base amount you lock

  • Error handling FX_QUOTE_FAILED is retryable

On this page