@juicypie/checkout-api
v0.0.23
Published
Client for interacting with the checkout API.
Readme
@juicypie/checkout-api
Typed client for interacting with the Checkout REST API from browsers or server runtimes.
Installation
pnpm add @juicypie/checkout-apiQuick start
import { createClient } from '@juicypie/checkout-api'
const client = createClient({ baseUrl: '/api' })
const newSession = await client.createCheckoutSession({
amount: 2599,
currency: 'usd',
customer_email: '[email protected]',
})
const sessions = await client.listSessions()
const session = await client.getSession('sess_123')
const completion = await client.complete('sess_123', { pm_token: 'pm_123' })
const status = await client.status('sess_123')API
createClient(options)
| Option | Type | Description |
| ----------- | --------------------------- | ------------------------------------------------------------------------- |
| baseUrl | string | Base URL for the Checkout API (e.g. https://api.example.com or /api). |
| fetchImpl | typeof fetch (optional) | Custom fetch implementation. Defaults to the global fetch. |
The returned client exposes:
createCheckoutSession(payload: CreateCheckoutSessionPayload)– creates a new checkout session.listSessions()– lists available checkout sessions.getSession(id: string)– fetches a checkout session.updateSession(id: string, payload: UpdateCheckoutSessionPayload)– updates an existing checkout session.cancelSession(id: string)– cancels an existing checkout session.complete(id: string, body: { pm_token: string })– marks the checkout session as completed using a payment method token.status(id: string)– retrieves the session processing status.
Errors
Non-2xx HTTP responses throw a CheckoutApiError, which exposes status and data fields.
try {
await client.getSession('missing')
} catch (error) {
if (error instanceof CheckoutApiError) {
console.error(error.status, error.message)
}
}All methods validate their inputs and throw when required parameters are missing.
