Skip to main content

Create subscription

Prerequisites

To create a subscription you need to meet the following requirements:

  • you need to have a Customer with an attached Payment Instrument. Please follow this tutorial to fulfill these requirements.
  • you need to have a Product. Please follow this tutorial to fulfill this requirement.
  • you need to have a Plan. Please follow this tutorial to fulfill this requirement.

Create a one-time-order

After you have a customer, product and edit plan you could create a one-time-order.

If you want to create a one-time-order please use a request similar to this one:

curl -i -X POST \
'https://stage-api.payments.ai/v1/organizations/:organizationId/subscriptions/one-time-order' \
-H 'Content-Type: application/json' \
-H 'Authorization: ApiKey <keyValue>' \
-d '{
"customerId": "Szymon_subscription_many_items",
"items": [
{
"plan": {
"id": "szymon-one-time-order-plan",
}
}
]
}' -v

If you want to create a one-time-order with flexible plan use:

curl -i -X POST \
'https://stage-api.payments.ai/v1/organizations/:organizationId/subscriptions/one-time-order' \
-H 'Content-Type: application/json' \
-H 'Authorization: ApiKey <keyValue>' \
-d '{
"customerId": "Szymon_subscription_many_items",
"items": [
{
"plan": {
"id": "szymon-one-time-order-plan",
"name": "test",
"currency": "USD",
"productId": "szymon-one-time-order",
"pricing": {
"formula": "fixed-fee",
"price": 1
}
}
}
]
}' -v

Create a subscription

After you have a customer, product and edit plan you could create a subscription.

If you want to create a subscription please use a request similar to this one:

curl -i -X POST \
'https://stage-api.payments.ai/v1/organizations/:organizationId/subscriptions' \
-H 'Content-Type: application/json' \
-H 'Authorization: ApiKey <keyValue>' \
-d '{
"customerId": "Szymon_subscription_many_items",
"items": [
{
"plan": {
"id": "szymon-one-time-order-plan",
}
}
]
}' -v

If you want to create a subscription with flexible plan use:

curl -i -X POST \
'https://stage-api.payments.ai/v1/organizations/:organizationId/subscriptions' \
-H 'Content-Type: application/json' \
-H 'Authorization: ApiKey <keyValue>' \
-d '{
"autopay":true,
"customerId":"Szymon_subscription_many_items",
"isTrialOnly":false,
"trial":{
"enabled":true,
"endTime":"2024-08-26T15:30:00Z"
},
"items":[
{
"quantity":1,
"plan":{
"id":"one-trial-final",
"name":"test-szymon-1-dollar-plan",
"productId":"szymon-1-dollar",
"currency":"USD",
"pricing":{
"formula":"fixed-fee",
"price":5
},
"recurringInterval":{
"unit": "day",
"limit":1,
"length":1,
"billingTiming":"prepaid"
},
"trial":{
"price":0,
"period":{
"unit":"day",
"length":1
}
}
}
}
]
}' -v