> ## Documentation Index
> Fetch the complete documentation index at: https://docs.khaime.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Components

> Reference for KhaimeCheckout and KhaimePaymentElement components

# Components

## KhaimeCheckout

The main checkout component with order summary and payment form.

```tsx theme={null}
import { KhaimeCheckout } from '@khaimehq/react';

<KhaimeCheckout
  token="eyJ..."
  onSuccess={(result) => console.log('Paid!', result)}
  onError={(error) => console.error(error)}
/>
```

### Props

**token** `string` *required*

The payment token from your Khaime API. This is an opaque string - pass it directly without parsing.

**productName** `string`

Override the product name shown in the order summary. If not provided, uses the name from the token.

**productImage** `string`

Override the product image URL. If not provided, uses the image from the token.

**showOrderSummary** `boolean` (default: true)

Whether to show the order summary section above the payment form.

**submitButtonText** `string`

Custom text for the submit button. Defaults to "Pay {amount}".

**returnUrl** `string`

URL to redirect to after 3D Secure authentication (Stripe only). Defaults to current page.

**appearance** `KhaimeAppearance`

Your brand colour as `primaryColor` (a hex colour, `#rgb` or `#rrggbb`), plus optional card form styling. See [Styling](#styling).

**onSuccess** `(result: PaymentResult) =\> void`

Called when payment is successful.

**onError** `(error: PaymentError) =\> void`

Called when payment fails.

**onReady** `() =\> void`

Called when the payment form is ready to accept input.

**onClose** `() =\> void`

Called when user closes the payment popup (Paystack only).

### Example with All Props

```tsx theme={null}
<KhaimeCheckout
  token={token}
  productName="Premium Plan"
  productImage="https://example.com/product.png"
  showOrderSummary={true}
  submitButtonText="Subscribe Now"
  returnUrl="https://myapp.com/checkout/complete"
  onSuccess={(result) => {
    console.log('Gateway used:', result.gateway);
    console.log('Payment ID:', result.paymentIntentId || result.reference);
    router.push('/success');
  }}
  onError={(error) => {
    toast.error(error.message);
  }}
  onReady={() => {
    console.log('Checkout ready');
  }}
  onClose={() => {
    console.log('User closed popup');
  }}
/>
```

***

## KhaimePaymentElement

A minimal payment form without the order summary. Use this when you want to build your own checkout UI.

```tsx theme={null}
import { KhaimePaymentElement } from '@khaimehq/react';

<KhaimePaymentElement
  token="eyJ..."
  onSuccess={(result) => console.log('Paid!')}
/>
```

### Props

**token** `string` *required*

The payment token from your Khaime API.

**returnUrl** `string`

URL to redirect to after 3D Secure authentication.

**className** `string`

CSS class name to apply to the container.

**onSuccess** `(result: PaymentResult) =\> void`

Called when payment is successful.

**onError** `(error: PaymentError) =\> void`

Called when payment fails.

**onReady** `() =\> void`

Called when the payment form is ready.

**onClose** `() =\> void`

Called when user closes the popup (Paystack only).

### Example: Custom Checkout Layout

```tsx theme={null}
function CustomCheckout({ token, product }) {
  return (
    <div className="checkout-container">
      {/* Your custom order summary */}
      <div className="order-summary">
        <img src={product.image} alt={product.name} />
        <h2>{product.name}</h2>
        <p className="price">${product.price}</p>
      </div>

      {/* Just the payment form */}
      <KhaimePaymentElement
        token={token}
        className="payment-form"
        onSuccess={(result) => {
          // Handle success
        }}
      />
    </div>
  );
}
```

***

## Types

### PaymentResult

Returned in the `onSuccess` callback.

```typescript theme={null}
interface PaymentResult {
  success: boolean;
  paymentIntentId?: string;  // Present for Stripe payments
  reference?: string;        // Present for Paystack payments
  gateway: 'stripe' | 'paystack' | 'startbutton';
}
```

### PaymentError

Returned in the `onError` callback.

```typescript theme={null}
interface PaymentError {
  code: string;
  message: string;
}
```

### Common Error Codes

| Code | Description |
| - | - |
| `card_declined` | The card was declined |
| `insufficient_funds` | Insufficient funds |
| `expired_card` | The card has expired |
| `invalid_cvc` | Invalid CVC code |
| `processing_error` | Error processing the payment |
| `missing_credentials` | Payment token is invalid or missing data |

***

## Styling

### Brand colour

Pass your brand colour as `appearance.primaryColor`. It colours the Pay button and the amount for every payment method.

```tsx theme={null}
<KhaimeCheckout
  token={token}
  appearance={{ primaryColor: '#008751' }}
/>
```

* Use a hex colour: `#rgb` or `#rrggbb`. Anything else is ignored and the default colours are used.
* Button text turns black or white, whichever reads better on your colour.
* Without `primaryColor`, the checkout uses your store's brand colour when one is set, then the default colours.
* You can also set the colour per checkout when you create it, with `appearance.primary_color` in [Create Charge](https://docs.khaime.com/api-reference/payments/create-intent.md). `primaryColor` on the component wins.
* This styles the parts Khaime draws on your page. Pages the payment provider shows after the button keep that provider's look.

### Card form styling

For card payments, `appearance` also takes the card form's styling options:

```tsx theme={null}
<KhaimeCheckout
  token={token}
  appearance={{
    primaryColor: '#008751',
    theme: 'stripe',
    variables: {
      borderRadius: '8px',
    },
  }}
/>
```

Your `primaryColor` becomes the card form's primary colour unless you set `variables.colorPrimary` yourself.

### Using className

```tsx theme={null}
<KhaimePaymentElement
  token={token}
  className="my-payment-form"
/>
```

```css theme={null}
.my-payment-form button {
  background-color: #your-brand-color;
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.