# createPaymentSession (Tokenized Payment)

> This API is used to generate a payment session for integrating client-side SDK. The API response provides encrypted session data, which can be used to initiate the client-side SDK. This SDK streamlines the payment process and frees you from manually calling multiple APIs.

`POST /v1/payments/createPaymentSession`

This API is used to generate a payment session for integrating client-side SDK. The API response provides encrypted session data, which can be used to initiate the client-side SDK. This SDK streamlines the payment process and frees you from manually calling multiple APIs.   

# Structure

A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see： 

-   [Request header](https://docs.antom.com/ac/ams/api_fund.md#ML5ur)
-   [Response header](https://docs.antom.com/ac/ams/api_fund.md#WWH90)

> **Note**: Set the data type of each field (except array) as String. This means that you must use double quotation marks (" ") to enclose the field value. Examples:
>
> -   If the data type of a field is Integer and its value is `20`, set it as "`20`". 
> -   If the data type of a field is Boolean and its value is `true`, set it as "`true`".

## Request parameters

#### productCode (String, REQUIRED)

Represents the payment product that is being used. The value is fixed as `AGREEMENT_PAYMENT`.

#### agreementInfo (AgreementInfo, REQUIRED)

The authorization information.

##### authState (String, REQUIRED)

The unique ID generated by the merchant to represent the authorization request.

More information:

- Maximum length: 256 characters

##### userLoginId (String)

The login ID that the user used to register in the payment method client. The login ID can be the user's email address or phone number.

Specify this parameter to free users from manually entering their login IDs.

More information:

- Maximum length: 64 characters

#### paymentMethod (PaymentMethod, REQUIRED)

The payment method that is used to collect the payment by the merchant or acquirer.

##### paymentMethodType (String, REQUIRED)

The payment method type that is included in payment method options.

More information:

- Maximum length: 64 characters

##### paymentMethodMetadata (PaymentMethodMetadata)

Payment method metadata.

**Scenario: First-time authorization** (First-time authorization)

###### firstName (String)

First name.

More information:

- Maximum length: 32 characters

###### lastName (String)

Last name.

More information:

- Maximum length: 32 characters

###### countryCode (String)

Country code of the buyer's phone number.

More information:

- Maximum length: 8 characters

###### billingAddress (Address)

The buyer's billing address.

###### address1 (String)

Address line 1, for example, the street address, PO box, and company name.

More information:

- Maximum length: 256 characters

###### address2 (String)

Address line 2, for example, the apartment, suite, unit, and building information.

More information:

- Maximum length: 256 characters

###### city (String)

The city, district, suburb, town, or village name.

More information:

- Maximum length: 32 characters

###### state (String)

The state, country, or province name.

> **Note**: For card payments, if your business entity is in the United States, and the card issuing country is in Canada, the United States, or the United Kingdom, set the value to a region code that consists of two to three characters and follows the ISO 3166-2 standard.

More information:

- Maximum length: 32 characters

###### region (String)

The 2-letter country or region code. For more information, see [ISO 3166 Country Codes](https://www.iso.org/obp/ui/#search) standard.

More information:

- Maximum length: 2 characters

###### zipCode (String)

ZIP or postal code.

> **Note**: For card payments, if your business entity is in the United States, specify this parameter according to the following parameter value requirements:
>
> -   Only contains numbers, letters, hyphens, and spaces.
> -   Must be within ten characters.

More information:

- Maximum length: 32 characters

###### billingPhoneNumber (String)

Buyer's phone number (without country code).

More information:

- Maximum length: 32 characters

###### billingEmail (String)

Buyer's billing email address.

More information:

- Maximum length: 64 characters

###### merchantExternalUserEnrollDate (String)

Buyer's onboarding timestamp (in Unix format) on the merchant side.

More information:

- Maximum length: 64 characters

###### merchantExternalUserId (String)

Buyer's account ID on the merchant side.

More information:

- Maximum length: 64 characters

**Scenario: Reauthorization** (Reauthorization)

###### isUpdateAsset (String)

Indicates whether to update the authorization. Defaults to `false`. Set this parameter to `true` when you update the authorization.

More information:

- Maximum length: 16 characters

###### accessToken (String)

The access token that is used to access the corresponding scope of the user resource.

> **Note**: This parameter must be specified when the value of _isUpdateAsset_ is `true`.

More information:

- Maximum length: 64 characters

#### paymentRedirectUrl (URL, REQUIRED)

The merchant page URL to which the user is redirected after a successful account binding.

More information:

- Maximum length: 2048 characters

#### scopes (Array<String>, REQUIRED)

The account binding scope. The value is fixed as `AGREEMENT_PAYMENT`.

## Response parameters

#### result (Result, REQUIRED)

The result of the API call.

##### resultCode (String, REQUIRED)

Result code. The result code that might be returned are listed in the **Result/Error codes** table on this page.

More information:

- Maximum length: 64 characters

##### resultStatus (String, REQUIRED)

Result status. Valid values are:

-   `S`: indicates that the result status is successful.
-   `F`: indicates that the result status is failed. 
-   `U`: indicates that the result status is unknown.

##### resultMessage (String, REQUIRED)

Result message that explains the result code.

More information:

- Maximum length: 256 characters

#### paymentSessionId (String, REQUIRED)

The encrypted ID that is assigned by Antom to identify a payment session.

More information:

- Maximum length: 64 characters

#### paymentSessionData (String, REQUIRED)

The encrypted authorization session data. Pass the data to your front end to initiate the client-side SDK.

More information:

- Maximum length: 4096 characters

#### paymentSessionExpiryTime (Datetime, REQUIRED)

The date and time when the authorization session expires.

More information:

- The value follows the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format. For example, "2019-11-27T12:01:01+08:00".

##

## Result/Error codes

| Code | Value | Message | Further action |
| --- | --- | --- | --- |
| SUCCESS | S | Success | The session is successfully created. No further action is needed. |
| PARAM_ILLEGAL | F | The required parameters are not passed, or illegal parameters exist. For example, a non-numeric input, an invalid date, or the length and type of the parameter are wrong. | Check and verify whether the required request fields (including the header fields and body fields) of the current API are correctly passed and valid. |
| PROCESS_FAIL | F | A general business failure occurred. | Do not retry. Human intervention is usually needed. It is recommended that you contact Antom Technical Support to troubleshoot the issue. |
| UNKNOWN_EXCEPTION | U | An API call has failed, which is caused by unknown reasons. | Call the interface again to resolve the issue. If not resolved, contact Antom Technical Support. |

## Request

```json
{
  "productCode": "AGREEMENT_PAYMENT",
  "agreementInfo": {
    "authState": "authState001"
  },
  "paymentRedirectUrl": "http://debug1688017773824.test.alipay.net:9090/amsdemo/result",
  "paymentMethod": {
    "paymentMethodType": "DANA"
  },
  "scopes": [
    "AGREEMENT_PAYMENT"
  ]
}
```

## Response

```json
{
  "paymentSessionData": "UNvjVWnWPXJA4BgW+vfjsQj7PbOraafHY19X+6EqMz6Kvvmsdk+akdLvoShW5avHX8e8J15P8uNVEf/PcCMyXg==&&SG&&111",
  "paymentSessionExpiryTime": "2023-04-06T03:28:49+08:00",
  "paymentSessionId": "UNvjVWnWPXJA4BgW+vfjsQj7PbOraafHY19X+6EqMz6Ikyj9FPVUOpv+DjiIZqMe",
  "result": {
    "resultCode": "SUCCESS",
    "resultMessage": "success.",
    "resultStatus": "S"
  }
}
```