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

# Localpayment对象

Localpayment 对象是您访问 Smart Fields SDK 的入口点。它提供用于创建支付字段、处理令牌和管理支付流程的方法。此对象通过使用您的公钥调用 `LP` 构造函数创建。

## 初始化

要开始使用 Localpayment Smart Fields，您必须先使用您的公共 API 密钥初始化 `LP` 对象。这将创建用于所有 Smart Fields 操作的主接口。

```javascript theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
const localpayment = LP({
    clientCode: 'your_client_code', // Your client code here 
    apiKey: 'your_api_key' // Your secret API key for authentication
});
```

### 配置选项

| 参数 | 类型 | 必需的 | 描述 |
| - | - | - | - |
| `clientCode` | string | 是的 | Localpayment 为您提供的唯一商户标识符。 |
| `apiKey` | string | 是的 | 您的用于身份验证请求的密钥。 |

***

## 方法

### `createSession()`

创建一个与 Localpayment 后端的新会话。此会话有效期有限（10 分钟），且必须在挂载任何支付字段之前创建。

* **返回**：`Promise<void>`
* **抛出**：如果网络请求失败或凭据无效，则抛出错误。

#### 例子

### `create(fieldType)`

创建一个安全支付字段实例。该字段在挂载之前是不可见的。

* **返回**：`LPField` 实例。

#### 参数

| 参数 | 类型 | 必需的 | 描述 |
| :- | :- | :- | :- |
| `fieldType` | String | 是的 | 要创建的字段类型。可接受的值：`pan`、`cvv`、`expiration`。 |

#### 例子

```javascript theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
// Create field instances
const panField = localpayment.create('pan');
const cvvField = localpayment.create('cvv');
const expirationField = localpayment.create('expiration');
```

### `getSessionData()`

获取当前活动会话的数据，包括会话 ID 和访问令牌。这对于后端令牌整合步骤至关重要。

* 返回：包含会话数据的 `Object`。
  * `sessionId`（String）：当前会话的唯一标识符。
  * `accessToken`（String）：用于验证合并请求的短期令牌。
  * `clientCode`（String）：用于初始化 SDK 的客户端代码。
  * `apiKey`（String）：用于初始化 SDK 的 API 密钥。

#### 例子

```javascript theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
const sessionData = localpayment.getSessionData();
// Example response: { sessionId: 'd069f375-c07c-4ac8-9f8a-6abbeb31f459', accessToken: 'eyJhbGci...', clientCode: '0001', apiKey: 'IIBCgKCAQEAtI...' }
```


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