open-index/open-npm huggingface dataset:
npm package: @juicypie/checkout-api
Description: Client for interacting with the checkout API.
Latest version: 0.0.23

# @juicypie/checkout-api

Typed client for interacting with the Checkout REST API from browsers or server runtimes.

## Installation

```bash
pnpm add @juicypie/checkout-api
```

## Quick start

```ts
import { createClient } from '@juicypie/checkout-api'

const client = createClient({ baseUrl: '/api' })

const newSession = await client.createCheckoutSession({
    amount: 2599,
    currency: 'usd',
    customer_email: 'demo@example.com',
})
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.

```ts
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.
npm package: @juicypie/checkout-js
Description: Browser SDK for mounting checkout experiences.
Latest version: 0.0.23

# @juicypie/checkout-js

Small browser SDK for embedding the checkout experience with Stripe Elements and the Checkout API client.

## Installation

```bash
pnpm add @juicypie/checkout-js
```

## Usage

```html
<div id="checkout-card"></div>
<script type="module">
    import Checkout from '@juicypie/checkout-js'

    Checkout.init({ baseUrl: '/api' })
    Checkout.mount('sess_123', {
        container: '#checkout-card',
        onResult(result) {
            if (result.status === 'succeeded') {
                console.log('Success', result.intent_id)
            } else {
                console.error(result.error)
            }
        },
    })
</script>
```

Call `Checkout.unmount()` when the component leaves the page or before mounting a new session.

### API

- `Checkout.init({ baseUrl, fetchImpl? })`
    - Must be called once per page load. Stores the API base URL and optional custom `fetch` implementation.
- `Checkout.mount(sessionId, { container?, onResult?, submitButtonText? })`
    - Fetches the session, loads Stripe.js once, renders an inline card element, and manages submit behaviour. The
      default container selector is `#checkout-card-container`.
- `Checkout.unmount()`
    - Cleans up DOM nodes, detaches listeners, and resets internal state.
- `Checkout.status(sessionId)`
    - Convenience proxy to the Checkout API `status` endpoint.

### Styling

The SDK renders a minimal form (card element + button). Override styles by targeting the form container you provide. You
can also pass a DOM node instead of a selector to fully control layout.

### Result handling

`onResult` receives:

```ts
{ status: 'succeeded' | 'failed' | 'processing'; intent_id?: string; error?: string }
```

Use this callback to transition your UI or surface errors to the customer.

## Browser support

The SDK relies on native `fetch`, `Promise`, and Stripe.js. For legacy browsers, provide appropriate polyfills before
initialising the checkout.