# Lite

## **Installation**

**NPM**

```bash
npm install @d24/sdk-minimal
```

**HTML Script Tag**

{% code overflow="wrap" %}

```html
<script type="module" src="https://d24sdk.s3.amazonaws.com/releases/d24-minimal-1.0.19.es.js"></script>
```

{% endcode %}

{% hint style="success" %}
**Ensure to install the latest version in this** [**link**](https://www.npmjs.com/package/@d24/sdk-minimal)**!**
{% endhint %}

## **Constructor**

Initializes the SDK. This must be called before any other methods.

`new SDK(publicKey, options)`

**Parameters**

<table><thead><tr><th width="210.90625">Parameter</th><th width="106.8203125">Type</th><th width="213.34765625">Description</th><th width="106.78515625">Required</th><th width="116.96484375">Possible Values</th></tr></thead><tbody><tr><td><code>publicKey</code></td><td><code>string</code></td><td>Your public API key provided by D24.</td><td>Yes</td><td><br></td></tr><tr><td><code>options</code></td><td><code>object</code></td><td>Configuration options for the SDK.</td><td>Yes</td><td><br></td></tr><tr><td><code>options.environment</code></td><td><code>string</code></td><td>The environment to use.</td><td>Yes</td><td><code>'stg'</code>, <code>'production'</code></td></tr></tbody></table>

### **Usage**

```javascript
// NPM/ESM
import SDK from '@d24/sdk-minimal';
new SDK('as1i2nxal12bvd', { environment: 'stg' });

// UMD/Script Tag
new window.D24.SDK('as1i2nxal12bvd', { environment: 'stg' });

```

#### **Errors**

| Error Message                                     | Reason                                                 |
| ------------------------------------------------- | ------------------------------------------------------ |
| `SDK was already instantiate.`                    | The SDK constructor was called more than once.         |
| `The environment [environment] is not supported.` | An invalid value was passed for `options.environment`. |

## **Methods**

**`generateToken({ card })`**

Validates credit card details and exchanges them for a secure, single-use token. This is an asynchronous method.

**Returns:** `Promise<{token: string}>` - A promise that resolves to an object containing the token.

### **Parameters**

<table><thead><tr><th width="222.890625">Parameter</th><th width="96.83984375">Type</th><th width="313.46484375">Description</th><th width="107.671875">Required</th></tr></thead><tbody><tr><td><code>card</code></td><td><code>object</code></td><td>An object containing the credit card details.</td><td>Yes</td></tr><tr><td><code>card.number</code></td><td><code>string</code></td><td>The full credit card number.</td><td>Yes</td></tr><tr><td><code>card.holder</code></td><td><code>string</code></td><td>The full name of the cardholder.</td><td>Yes</td></tr><tr><td><code>card.cvv</code></td><td><code>string</code></td><td>The 3-digit (or 4-digit for Amex) security code.</td><td>Yes</td></tr><tr><td><code>card.expirationMonth</code></td><td><code>string</code></td><td>The 2-digit expiration month (e.g., "09").</td><td>Yes</td></tr><tr><td><code>card.expirationYear</code></td><td><code>string</code></td><td>The 2-digit expiration year (e.g., "25").</td><td>Yes</td></tr></tbody></table>

### **Usage**

```javascript
const cardDetails = {
  number: '4509953566233704',
  holder: 'Juan Perez',
  cvv: '123',
  expirationMonth: '11',
  expirationYear: '25',
};

try {
  const response = await window.D24.generateToken({ card: cardDetails });
  const token = response.token;
  // Send token to your server
} catch (error) {
  // Handle validation errors from the Joi library or API errors.
  console.error(error);
}

```

**Errors**

| Error Message                                                    | Reason                                                                                                   |
| ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| `You must instantiate D24CreditCardSDK before using SDK methods` | `generateToken` was called before the SDK was initialized with `new SDK()`.                              |
| (Joi Validation Error)                                           | The `card` object failed validation. The error message will describe the specific field that is invalid. |


---

# Agent Instructions: 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:

```
GET https://docs.pandablue.com/api-reference-1/fragment-sdk/lite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
