Create a subscription
Creates a new subscription for a customer. The subscription will be billed according to the specified plan.
curl --request POST \
--url https://sandbox-api.paynext.com/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-API-Version: <x-api-version>' \
--data '
{
"customer": {
"id": "cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac"
},
"plan": {
"id": "price_a5b8fc11-971b-477a-b758-e7fa46260226"
},
"subscription": {
"metadata": {
"key": "value"
}
}
}
'const options = {
method: 'POST',
headers: {
'X-API-Version': '<x-api-version>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
customer: {id: 'cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac'},
plan: {id: 'price_a5b8fc11-971b-477a-b758-e7fa46260226'},
subscription: {metadata: {key: 'value'}}
})
};
fetch('https://sandbox-api.paynext.com/subscriptions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sandbox-api.paynext.com/subscriptions"
payload := strings.NewReader("{\n \"customer\": {\n \"id\": \"cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac\"\n },\n \"plan\": {\n \"id\": \"price_a5b8fc11-971b-477a-b758-e7fa46260226\"\n },\n \"subscription\": {\n \"metadata\": {\n \"key\": \"value\"\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Version", "<x-api-version>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://sandbox-api.paynext.com/subscriptions")
.header("X-API-Version", "<x-api-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer\": {\n \"id\": \"cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac\"\n },\n \"plan\": {\n \"id\": \"price_a5b8fc11-971b-477a-b758-e7fa46260226\"\n },\n \"subscription\": {\n \"metadata\": {\n \"key\": \"value\"\n }\n }\n}")
.asString();import requests
url = "https://sandbox-api.paynext.com/subscriptions"
payload = {
"customer": { "id": "cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac" },
"plan": { "id": "price_a5b8fc11-971b-477a-b758-e7fa46260226" },
"subscription": { "metadata": { "key": "value" } }
}
headers = {
"X-API-Version": "<x-api-version>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://sandbox-api.paynext.com/subscriptions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer' => [
'id' => 'cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac'
],
'plan' => [
'id' => 'price_a5b8fc11-971b-477a-b758-e7fa46260226'
],
'subscription' => [
'metadata' => [
'key' => 'value'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-API-Version: <x-api-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"id": "sub_123e4567-e89b-12d3-a456-426614174000",
"current_period_end": "<string>",
"cancelled_at": "2026-06-10T14:32:08Z",
"cancellation_details": {
"reason": "fraud_prevention",
"trigger_payment_id": "pay_e8a1b2c3-1d2e-3f4a-5b6c-7d8e9f0a1b2c"
},
"current_period_start": "<string>",
"next_billing_date": "2025-06-26T12:00:00Z",
"past_due": {
"attempt_count": 2,
"max_attempts_count": 7
},
"plan": {
"id": "price_1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d",
"archived_at": "2025-06-01T10:00:00Z",
"interval": "days",
"interval_count": 1,
"name": "Pro Plan",
"price": {
"amount": 1999,
"currency": "AED"
},
"tax": {
"collect_tax": "<unknown>"
},
"trial_interval": "days",
"trial_interval_count": 14,
"trial_price": {
"amount": 1999,
"currency": "AED"
},
"type": "recurring"
},
"status": "trial",
"metadata": {
"key": "value"
},
"created_at": "2025-05-26T10:00:00Z",
"updated_at": "2025-05-27T10:00:00Z"
}{
"error": {
"type": "invalid_request_error",
"message": "Missing required parameter: email",
"code": "parameter_missing",
"param": "email"
}
}{
"error": {
"type": "invalid_request_error",
"message": "Missing required parameter: email",
"code": "parameter_missing",
"param": "email"
}
}{
"error": {
"type": "invalid_request_error",
"message": "Missing required parameter: email",
"code": "parameter_missing",
"param": "email"
}
}Authorizations
Authentication header of the form api key, where api key is your organization api key.
Headers
Specifies the version of the API to use
2.0.0 Body
Create subscription
Response
Returns the subscription object after successful creation.
Unique identifier for the subscription
"sub_123e4567-e89b-12d3-a456-426614174000"
UTC timestamp of when the subscription became cancelled; null unless the subscription is cancelled
"2026-06-10T14:32:08Z"
Server-attested cancellation attribution. Always present; sub-fields are null unless the subscription is cancelled (or scheduled for cancellation).
Show child attributes
Show child attributes
Next scheduled billing date for the subscription
"2025-06-26T12:00:00Z"
Information about past due attempts
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Current status of the subscription
trial, active, past_due, cancelled, scheduled_for_cancellation Custom metadata associated with the subscription A dictionary of key-value pairs.
Show child attributes
Show child attributes
{ "key": "value" }
The date and time at which the subscription was created in UTC format
"2025-05-26T10:00:00Z"
The date and time of the last subscription update in UTC format
"2025-05-27T10:00:00Z"
Was this page helpful?
curl --request POST \
--url https://sandbox-api.paynext.com/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-API-Version: <x-api-version>' \
--data '
{
"customer": {
"id": "cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac"
},
"plan": {
"id": "price_a5b8fc11-971b-477a-b758-e7fa46260226"
},
"subscription": {
"metadata": {
"key": "value"
}
}
}
'const options = {
method: 'POST',
headers: {
'X-API-Version': '<x-api-version>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
customer: {id: 'cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac'},
plan: {id: 'price_a5b8fc11-971b-477a-b758-e7fa46260226'},
subscription: {metadata: {key: 'value'}}
})
};
fetch('https://sandbox-api.paynext.com/subscriptions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sandbox-api.paynext.com/subscriptions"
payload := strings.NewReader("{\n \"customer\": {\n \"id\": \"cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac\"\n },\n \"plan\": {\n \"id\": \"price_a5b8fc11-971b-477a-b758-e7fa46260226\"\n },\n \"subscription\": {\n \"metadata\": {\n \"key\": \"value\"\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Version", "<x-api-version>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://sandbox-api.paynext.com/subscriptions")
.header("X-API-Version", "<x-api-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer\": {\n \"id\": \"cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac\"\n },\n \"plan\": {\n \"id\": \"price_a5b8fc11-971b-477a-b758-e7fa46260226\"\n },\n \"subscription\": {\n \"metadata\": {\n \"key\": \"value\"\n }\n }\n}")
.asString();import requests
url = "https://sandbox-api.paynext.com/subscriptions"
payload = {
"customer": { "id": "cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac" },
"plan": { "id": "price_a5b8fc11-971b-477a-b758-e7fa46260226" },
"subscription": { "metadata": { "key": "value" } }
}
headers = {
"X-API-Version": "<x-api-version>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://sandbox-api.paynext.com/subscriptions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer' => [
'id' => 'cus_0c3663c1-ab8e-4c87-b19c-c72814ffe1ac'
],
'plan' => [
'id' => 'price_a5b8fc11-971b-477a-b758-e7fa46260226'
],
'subscription' => [
'metadata' => [
'key' => 'value'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-API-Version: <x-api-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"id": "sub_123e4567-e89b-12d3-a456-426614174000",
"current_period_end": "<string>",
"cancelled_at": "2026-06-10T14:32:08Z",
"cancellation_details": {
"reason": "fraud_prevention",
"trigger_payment_id": "pay_e8a1b2c3-1d2e-3f4a-5b6c-7d8e9f0a1b2c"
},
"current_period_start": "<string>",
"next_billing_date": "2025-06-26T12:00:00Z",
"past_due": {
"attempt_count": 2,
"max_attempts_count": 7
},
"plan": {
"id": "price_1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d",
"archived_at": "2025-06-01T10:00:00Z",
"interval": "days",
"interval_count": 1,
"name": "Pro Plan",
"price": {
"amount": 1999,
"currency": "AED"
},
"tax": {
"collect_tax": "<unknown>"
},
"trial_interval": "days",
"trial_interval_count": 14,
"trial_price": {
"amount": 1999,
"currency": "AED"
},
"type": "recurring"
},
"status": "trial",
"metadata": {
"key": "value"
},
"created_at": "2025-05-26T10:00:00Z",
"updated_at": "2025-05-27T10:00:00Z"
}{
"error": {
"type": "invalid_request_error",
"message": "Missing required parameter: email",
"code": "parameter_missing",
"param": "email"
}
}{
"error": {
"type": "invalid_request_error",
"message": "Missing required parameter: email",
"code": "parameter_missing",
"param": "email"
}
}{
"error": {
"type": "invalid_request_error",
"message": "Missing required parameter: email",
"code": "parameter_missing",
"param": "email"
}
}