# create

> Use this API to initiate a subscription creation request. After this API is called successfully, you can get the authorization URL and redirect the user to the URL to authorize the subscription. After the user authorizes the subscription successfully, Antom initiates an automatic deduction in each subscription period and notifies you of the payment result.

`POST /v1/subscriptions/create`

Use this API to initiate a subscription creation request. After this API is called successfully, you can get the authorization URL and redirect the user to the URL to authorize the subscription. After the user authorizes the subscription successfully, Antom initiates an automatic deduction in each subscription period and notifies you of the payment result.  

# 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

#### subscriptionRequestId (String, REQUIRED)

The unique ID assigned by a merchant to identify a subscription request. Antom uses this field for idempotency control.

More information:

- This field is an API idempotency field.For subscription requests that are initiated with the same value of subscriptionRequestId and reach a final status of S or F, the same result is to be returned for the request.
- Maximum length: 64 characters

#### subscriptionDescription (String, REQUIRED)

The description of the subscription, used for displaying user consumption records and other actions.

More information:

- Maximum length: 256 characters

#### subscriptionRedirectUrl (URL, REQUIRED)

The merchant page URL that the user is redirected to after authorizing the subscription.

More information:

- Maximum length: 2048 characters

#### subscriptionStartTime (Datetime, REQUIRED)

The date and time when the subscription becomes active.

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".

#### subscriptionEndTime (Datetime)

The date and time when the subscription ends.

> **Note**: Specify this parameter when you want to designate the subscription end time.

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".

#### periodRule (PeriodRule, REQUIRED)

The subscription period rule, used to define a subscription's billing period.

##### periodType (String, REQUIRED)

The subscription period type. Valid values are:

-   `YEAR`: indicates that the subscription period is measured in years. 
-   `MONTH`: indicates that the subscription period is measured in months. 
-   `WEEK`: indicates that the subscription period is measured in weeks. 
-   `DAY`: indicates that the subscription period is measured in days.

More information:

- Maximum length: 20 characters

##### periodCount (Integer, REQUIRED)

The number of period types within one subscription period. For example, if the value of _periodType_ is `MONTH` and the value of _periodCount_ is `2`, it means that the subscription period is two months.

More information:

- Value range: 1 - unlimited

#### subscriptionExpiryTime (Datetime)

A specific date and time after which the created subscription expires. When the subscription expires, the order must be terminated. The default value of this parameter is 30 minutes after the subscription creation request is sent.

> **Note**: Specify this parameter if you want to designate the subscription creation expiration time. The specified payment expiration time must be less than 48 hours after the subscription request is sent.

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".

#### paymentMethod (PaymentMethod, REQUIRED)

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

##### paymentMethodType (String, REQUIRED)

The payment method that is used to accept the subscription payment. See [Payment methods](https://docs.antom.com/ac/pm/enumeration_values.md) to check the valid values.

> **Note**: Card payment method is not currently supported when you work with Antom as your acquirer.

More information:

- Maximum length: 64 characters

##### paymentMethodId (String)

The unique ID that is used to identify a payment method.

Pass the corresponding token to this field when the user has a bound payment method.

More information:

- Maximum length: 128 characters

#### subscriptionNotificationUrl (URL, REQUIRED)

The URL that is used to receive the subscription result notification. 

You can also configure the subscription notification URL in Antom Dashboard. If you specify this URL in both this API and Antom Dashboard, the URL configured in the API takes precedence.

> **Note**: Only one subscription notification URL can be configured in Antom Dashboard.

More information:

- Maximum length: 2048 characters

#### paymentNotificationUrl (URL, REQUIRED)

The URL that is used to receive the payment result notification for each subscription period.

You can also configure the subscription notification URL in [Antom Dashboard](https://global.alipay.com/ilogin/account_login.htm?goto=https%3A%2F%2Fglobal.alipay.com%2Fopen%2Fconsole%2Fdeveloper%2Fapp%2Flist&from_site=MERCHANT&terminal_type=pc&loginScene=MERCHANT&locale=cn&loginId=&_route=QK). If you specify this URL in both this API and Antom Dashboard, the URL configured in the API takes precedence.

> **Note**: You can only configure one subscription notification URL in Antom Dashboard.

More information:

- Maximum length: 2048 characters

#### orderInfo (OrderInfo, REQUIRED)

The order information for the subscription. This field is used for different purposes:

-   During the payment process, this field is mainly used by Antom for risk control or anti-money laundering.
-   After the payment is completed, this field is used for recording and reporting purposes such as purchase tracking and regulatory reporting.

##### orderAmount (Amount, REQUIRED)

The total amount of the order before discounts or taxes are applied. The value of this parameter is displayed on user consumption records or the payment result page.

###### currency (String, REQUIRED)

The transaction currency that is specified in the contract. A 3-letter currency code that follows the [ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) standard.

More information:

- Maximum length: 3 characters

###### value (Integer, REQUIRED)

The amount to charge as a positive integer in the smallest currency unit. (That is, 100 cents to charge $1.00, or 100 to charge JPY 100, a 0-decimal currency).

> **Note**: For details about the smallest currency unit, see [Smallest unit of the currency](https://docs.antom.com/ac/ref/cc.md#ONkIe).

More information:

- Value range: 1 - unlimited

#### paymentAmount (Amount, REQUIRED)

The payment amount charged to the user per subscription period.

##### currency (String, REQUIRED)

The transaction currency, which is a 3-letter currency code that follows the [ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) standard.

More information:

- Maximum length: 3 characters

##### value (Integer, REQUIRED)

The value of the amount as a positive integer in the smallest currency unit. For example, if the currency is USD and the amount is $1.00, set the value of this parameter to `100`; or if the currency is JPY and the amount is ￥1, set the value of this parameter to `1`.

For details about the smallest currency unit, see [Smallest unit of the currency](https://docs.antom.com/ac/ref/cc.md#ONkIe).

For details about the minimum payment amount allowed for each payment method, see [Minimum amount rules](https://docs.antom.com/ac/ref/cc.md#q9R5A).

> **Note**: Due to the currency practices in Indonesia, when the currency is IDR, round the amount with Banker's Rounding and fix the last two digits of this parameter as `00`.

More information:

- Value range: 1 - unlimited

#### settlementStrategy (SettlementStrategy, REQUIRED)

The settlement strategy for the payment request.

##### settlementCurrency (String, REQUIRED)

The ISO currency code of the currency that the merchant wants to be settled against. The field is required if the merchant signed up for multiple currencies to settle.

More information:

- Maximum length: 3 characters

#### env (Env, REQUIRED)

Information about the environment where the order is placed, such as the device information.

##### terminalType (String, REQUIRED)

The terminal type the merchant service applies to. Valid values are:

-   `WEB`: The client-side terminal type is a website, which is opened via a PC browser.
-   `WAP`: The client-side terminal type is an H5 page, which is opened via a mobile browser.
-   `APP`: The client-side terminal type is a mobile application.

More information:

- Maximum length: 20 characters

##### osType (String)

The OS type. Valid values are:

-   `IOS`: indicates the operation system is Apple's iOS.
-   `ANDROID`: indicates the operation system is Google's Android.

> **Note**: Specify this parameter when _terminalType_ is `APP` or `WAP`.

More information:

- Maximum length: 20 characters

#### trials (Array<Trial>)

The list of trial information of a subscription.

> **Note**: Specify this parameter if the subscription includes any trial periods.

##### trialStartPeriod (Integer, REQUIRED)

The start subscription period of the trial. For example, if the trial starts from the first subscription period, specify this parameter as `1`.

More information:

- Value range: 1 - unlimited

##### trialAmount (Amount, REQUIRED)

The discounted amount for each subscription trial period. The value of this parameter must be a positive number.

###### currency (String, REQUIRED)

The transaction currency, which is a 3-letter currency code that follows the [ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) standard.

More information:

- Maximum length: 3 characters

###### value (String, REQUIRED)

The value of the amount as a positive integer in the smallest currency unit. For example, if the currency is USD and the amount is $1.00, set the value of this parameter to `100`; or if the currency is JPY and the amount is ￥1, set the value of this parameter to `1`.

For details about the smallest currency unit, see [Smallest unit of the currency](https://docs.antom.com/ac/ref/cc.md#ONkIe).

For details about the minimum payment amount allowed for each payment method, see [Minimum amount rules](https://docs.antom.com/ac/ref/cc.md#q9R5A).

> Note: Due to the currency practices in Indonesia, when the currency is IDR, round the amount with Banker's Rounding and fix the last two digits of this parameter as `00`.

More information:

- Maximum length: 16 characters
- Value range: 1 - unlimited

##### trialEndPeriod (Integer)

The end subscription period of the trial. For example, if the trial ends at the third subscription period, specify this parameter as `3`.

> **Note**: Specify this parameter if the end subscription period is different from the start subscription period. If you leave this parameter empty, the default value of this parameter is the same as the value of _trialStartPeriod_.

More information:

- Value range: 1 - unlimited

## Response parameters

#### result (Result, REQUIRED)

Indicates whether this API is called successfully. If this API is successfully called, the subscription authorization URL is returned.

##### resultCode (String, REQUIRED)

The result code. Possible values are listed in the _Result/Error codes_ table on this page.

More information:

- Maximum length: 64 characters

##### resultStatus (String, REQUIRED)

The result status. Valid values are:

-   `S`: indicates that this API is called successfully and the authorization URL is returned.
-   `F`: indicates that this API call is failed. The authorization URL is not returned.
-   `U`: indicates that the API call status is unknown. Retry the calling process.

##### resultMessage (String, REQUIRED)

The result message that explains the result code.

More information:

- Maximum length: 256 characters

#### schemeUrl (URL)

The URL scheme that redirects users to open an app in an Android or iOS system when the target app is installed.

> **Note**: When the value of _result.resultCode_ is `S`, at least one of _schemeUrl_, _applinkUrl,_ and _normalUrl_ is to be returned.

More information:

- Maximum length: 2048 characters

#### applinkUrl (URL)

The URL that redirects users to open an app when the target app is installed, or to open a WAP page when the target app is not installed. For Android, the URL is a Native App Link. For iOS, the URL is a Universal Link.

> **Note**: When the value of _result.resultCode_ is `S`, at least one of _schemeUrl_, _applinkUrl,_ and _normalUrl_ is to be returned.

More information:

- Maximum length: 2048 characters

#### normalUrl (URL)

The URL that redirects users to a WAP or Web page in the default browser or the embedded WebView.

> Note: When the value of _result.resultCode_ is `S`, at least one of _schemeUrl_, _applinkUrl,_ and _normalUrl_ is to be returned.

More information:

- Maximum length: 2048 characters

#### appIdentifier (URL)

An Android package name, which is used for Android app to open a cashier page.

> **Note**: This field is returned when _result.resultCode_ is `S` and _terminalType_ is `APP` or `WAP`.

More information:

- Maximum length: 128 characters

## Result process logic

For different request results, different actions are to be performed. See the following list for details:

-   If the value of _result.resultStatus_ is `S`, the authorization URL is successfully returned by the _schemeUrl_, _applinkUrl,_ or _normalUrl_ field in the response. You can redirect the user to this URL to authorize the subscription payment.
-   If the value of _result.resultStatus_ is `U`, the API call status is unknown. You can call this API again to retry the process.
-   If the value of _result.resultStatus_ is `F`, the authorization URL failed to be returned. Generally, this case is caused by system defects or system failure. Check the error codes and take the corresponding actions or contact Antom technical support.

## Result/Error codes

| Code | Value | Message | Further action |
| --- | --- | --- | --- |
| SUCCESS | S | Success | The API is called successfully. Obtain schemeUrl, applinkUrl, or normalUrl from the response. |
| ACCESS_DENIED | F | Access is denied. | Contact Antom Technical Support for detailed reasons. |
| CLIENT_FORBIDDEN_ACCESS_API | F | Access is denied. | Contact Antom Technical Support for detailed reasons. |
| INVALID_API | F | The called API is invalid or not active. | Contact Antom Technical Support to resolve the issue. |
| INVALID_CLIENT_STATUS | F | The client status is invalid. | Contact Antom Technical Support for detailed reasons. |
| INVALID_SIGNATURE | F | The signature is not validated. The private key used to sign a request does not match the public key of Antom Dashboard. | Check whether the private key used to sign a request matches the public key of Antom Dashboard. The following signature references are useful:The signature field in a request header How to calculate a signature |
| KEY_NOT_FOUND | F | The private key or public key of <span>Antom</span> or the merchant is not found. | Check whether the private key or public key exists. If not, upload the private key in Antom Dashboard. |
| MERCHANT_NOT_REGISTERED | F | The merchant is not registered. | Please register the merchant by using the registration interface. Contact Antom Technical Support if failed to call the registration interface. |
| OAUTH_FAILED | F | OAuth process failed. | Contact Antom Technical Support for detailed reasons. |
| 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. |
| PAYMENT_NOT_QUALIFIED | F | The merchant is not qualified to pay because the merchant is not registered, does not have a contract for Tokenized Payment, or is forbidden to make a payment. | Contact Antom Technical Support for detailed reasons. |
| 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. |
| RISK_REJECT | F | The transaction cannot be further processed because of risk control. If the user has already paid for the transaction, the transaction will be refunded. | If the user does not receive the refund within two weeks, contact Antom Technical Support. |
| UNKNOWN_CLIENT | F | The client is unknown. | Contact Antom Technical Support for detailed reasons. |
| REQUEST_TRAFFIC_EXCEED_LIMIT | U | The request traffic exceeds the limit. | Call the API again to resolve the issue. If not resolved, contact Antom Technical Support. |
| UNKNOWN_EXCEPTION | U | An API call has failed, which is caused by unknown reasons. | Call the API again to resolve the issue. If not resolved, contact Antom Technical Support. |
| REPEAT_REQ_INCONSISTENT | F | The amount or currency is different from the previous request. | Ensure all the fields in the requests are the same or use a new subscriptionRequestId to initiate the payment again. |

## Request

### SUBSCRIPTION_CREATION

```json
{
  "paymentMethod": {
    "paymentMethodType": "GCASH"
  },
  "env": {
    "osType": "ANDROID",
    "terminalType": "WAP"
  },
  "paymentAmount": {
    "currency": "USD",
    "value": "1100"
  },
  "paymentNotificationUrl": "https://www.alipay.com",
  "periodRule": {
    "periodType": "YEAR",
    "periodCount": 1
  },
  "settlementStrategy": {
    "settlementCurrency": "USD"
  },
  "subscriptionDescription": "Subscription test",
  "subscriptionEndTime": "2024-08-09T14:55:16+08:00",
  "subscriptionExpiryTime": "2023-08-09T14:55:16+08:00",
  "subscriptionNotificationUrl": "https://www.alipay.com",
  "orderInfo": {
    "orderAmount": {
      "currency": "USD",
      "value": "1100"
    }
  },
  "subscriptionRedirectUrl": "https://www.alipay.com",
  "subscriptionRequestId": "merchant_subscription_2100000_200000987654321",
  "subscriptionStartTime": "2023-08-09T14:30:16+08:00"
}
```

### SUBSCRIPTION_CREATION_TRIALS

```json
{
  "paymentMethod": {
    "paymentMethodType": "GCASH"
  },
  "env": {
    "osType": "ANDROID",
    "terminalType": "WAP"
  },
  "paymentAmount": {
    "currency": "USD",
    "value": "1100"
  },
  "paymentNotificationUrl": "https://www.alipay.com",
  "periodRule": {
    "periodType": "YEAR",
    "periodCount": 1
  },
  "settlementStrategy": {
    "settlementCurrency": "USD"
  },
  "subscriptionDescription": "Subscription test",
  "subscriptionEndTime": "2024-08-09T14:55:16+08:00",
  "subscriptionExpiryTime": "2023-08-09T14:55:16+08:00",
  "subscriptionNotificationUrl": "https://www.alipay.com",
  "orderInfo": {
    "orderAmount": {
      "currency": "USD",
      "value": "1100"
    }
  },
  "subscriptionRedirectUrl": "https://www.alipay.com",
  "subscriptionRequestId": "merchant_subscription_2100001111_0000987654321",
  "subscriptionStartTime": "2023-08-09T14:30:16+08:00",
  "trials": [
    {
      "trialAmount": {
        "currency": "USD",
        "value": "0"
      },
      "trialEndPeriod": 4,
      "trialStartPeriod": 2
    },
    {
      "trialAmount": {
        "currency": "USD",
        "value": "100"
      },
      "trialEndPeriod": 5,
      "trialStartPeriod": 5
    }
  ]
}
```

## Response

```json
{
  "result": {
    "resultStatus": "S",
    "resultCode": "SUCCESS",
    "resultMessage": "success."
  },
  "applinkUrl": "http://xmock.inc.alipay.net/applinkUrl/test/url.htm",
  "normalUrl": "http://xmock.inc.alipay.net/normalUrl/test/url.htm",
  "schemeUrl": "http://xmock.inc.alipay.net/schemeUrl/test/url.htm",
  "appIdentifier": "http://xmock.inc.alipay.net/appIdentifier/test/url.htm"
}
```