> For the complete documentation index, see [llms.txt](https://docs.coda.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coda.co/codapay/hosted-component-integration/alternative-payment-methods/interact-with-the-codacomponent-sdk.md).

# Interact with the CodaComponent SDK

The CodaComponent SDK is a client-side JavaScript library that renders payment channel UIs into your checkout page. Use this reference to manage the component's lifecycle and handle state-driven events.

### `CodaComponent()`

*Creates a new* CodaComponent *instance.*

**Code Example**

```javascript
const codaComponent = CodaComponent();
```

**Returns**

SDK Instance: An object containing the `components` function.

### `.components({ clientSecret })`

*Sets up the environment for payment elements and authorizes the session.*

**Parameters**

* `clientSecret` (string): Required. The JWT returned from the charge creation on your backend.

**Code Example**

```javascript
const components = codaComponent.components({
  clientSecret: 'eyJ...'
});
```

**Returns**

Components Factory: An object used to generate specific payment UI elements: `{ create: Function }`.

### `.create(type)`

*Generates a specific payment component instance, such as the card input form.*

**Parameters**

* `type` (string): Required. The type of component to create (currently supports `'charge'`)

**Code Example**

```javascript
const chargeComponent = components.create('charge');
```

**Returns**

`ChargeComponent`: The instance used for mounting and managing the payment form.

### `.mount(selector)`

*Injects the secure payment form into a specific DOM element on your page.*

**Parameters**

* `selector` (string): Required. A CSS selector identifying the container where the form should be rendered (e.g., `'#payment-form'`).

**Code Example**

```javascript
chargeComponent.mount('#payment-form');
```

### `.on(event, callback)`

*Registers a listener for specific component events to synchronize your UI with the payment state.*

**Available Events**

| **Event**    | **Callback Signature** | **When Fired**                              |
| ------------ | ---------------------- | ------------------------------------------- |
| `userLoaded` | `() => void`           | Form finishes loading                       |
| `success`    | `() => void`           | The payment has been completed successfully |
| `failed`     | `() => void`           | The payment has failed                      |

**Code Example**

```javascript
chargeComponent.on('success', () => {
  console.log('Payment successful!');
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coda.co/codapay/hosted-component-integration/alternative-payment-methods/interact-with-the-codacomponent-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
