Skip to main content
POST
/
subscriptions
JavaScript
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
  bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

const subscription = await client.subscriptions.create({
  billing: { country: 'AF' },
  customer: { customer_id: 'customer_id' },
  product_id: 'product_id',
  quantity: 0,
});

console.log(subscription.payment_id);
import os
from dodopayments import DodoPayments

client = DodoPayments(
bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"), # This is the default and can be omitted
)
subscription = client.subscriptions.create(
billing={
"country": "AF"
},
customer={
"customer_id": "customer_id"
},
product_id="product_id",
quantity=0,
)
print(subscription.payment_id)
package main

import (
"context"
"fmt"

"github.com/dodopayments/dodopayments-go"
"github.com/dodopayments/dodopayments-go/option"
)

func main() {
client := dodopayments.NewClient(
option.WithBearerToken("My Bearer Token"),
)
subscription, err := client.Subscriptions.New(context.TODO(), dodopayments.SubscriptionNewParams{
Billing: dodopayments.F(dodopayments.BillingAddressParam{
Country: dodopayments.F(dodopayments.CountryCodeAf),
}),
Customer: dodopayments.F[dodopayments.CustomerRequestUnionParam](dodopayments.AttachExistingCustomerParam{
CustomerID: dodopayments.F("customer_id"),
}),
ProductID: dodopayments.F("product_id"),
Quantity: dodopayments.F(int64(0)),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", subscription.PaymentID)
}
package com.dodopayments.api.example;

import com.dodopayments.api.client.DodoPaymentsClient;
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;
import com.dodopayments.api.models.misc.CountryCode;
import com.dodopayments.api.models.payments.AttachExistingCustomer;
import com.dodopayments.api.models.payments.BillingAddress;
import com.dodopayments.api.models.subscriptions.SubscriptionCreateParams;
import com.dodopayments.api.models.subscriptions.SubscriptionCreateResponse;

public final class Main {
private Main() {}

public static void main(String[] args) {
DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

SubscriptionCreateParams params = SubscriptionCreateParams.builder()
.billing(BillingAddress.builder()
.country(CountryCode.AF)
.build())
.customer(AttachExistingCustomer.builder()
.customerId("customer_id")
.build())
.productId("product_id")
.quantity(0)
.build();
SubscriptionCreateResponse subscription = client.subscriptions().create(params);
}
}
package com.dodopayments.api.example

import com.dodopayments.api.client.DodoPaymentsClient
import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient
import com.dodopayments.api.models.misc.CountryCode
import com.dodopayments.api.models.payments.AttachExistingCustomer
import com.dodopayments.api.models.payments.BillingAddress
import com.dodopayments.api.models.subscriptions.SubscriptionCreateParams
import com.dodopayments.api.models.subscriptions.SubscriptionCreateResponse

fun main() {
val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

val params: SubscriptionCreateParams = SubscriptionCreateParams.builder()
.billing(BillingAddress.builder()
.country(CountryCode.AF)
.build())
.customer(AttachExistingCustomer.builder()
.customerId("customer_id")
.build())
.productId("product_id")
.quantity(0)
.build()
val subscription: SubscriptionCreateResponse = client.subscriptions().create(params)
}
require "dodopayments"

dodo_payments = Dodopayments::Client.new(
bearer_token: "My Bearer Token",
environment: "test_mode" # defaults to "live_mode"
)

subscription = dodo_payments.subscriptions.create(
billing: {country: :AF},
customer: {customer_id: "customer_id"},
product_id: "product_id",
quantity: 0
)

puts(subscription)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Dodopayments\Client;
use Dodopayments\Core\Exceptions\APIException;
use Dodopayments\Misc\CountryCode;
use Dodopayments\Misc\Currency;
use Dodopayments\Payments\PaymentMethodTypes;

$client = new Client(
bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
environment: 'test_mode',
);

try {
$subscription = $client->subscriptions->create(
billing: [
'country' => CountryCode::AF,
'city' => 'city',
'state' => 'state',
'street' => 'street',
'zipcode' => 'zipcode',
],
customer: ['customerID' => 'customer_id'],
productID: 'product_id',
quantity: 0,
addons: [['addonID' => 'addon_id', 'quantity' => 0]],
allowedPaymentMethodTypes: [PaymentMethodTypes::ACH],
billingCurrency: Currency::AED,
customerBusinessName: 'customer_business_name',
discountCode: 'discount_code',
discountCodes: ['string'],
force3DS: true,
mandateMinAmountInrPaise: 0,
metadata: ['foo' => 'string'],
onDemand: [
'mandateOnly' => true,
'adaptiveCurrencyFeesInclusive' => true,
'productCurrency' => Currency::AED,
'productDescription' => 'product_description',
'productPrice' => 0,
],
oneTimeProductCart: [
['productID' => 'product_id', 'quantity' => 0, 'amount' => 0]
],
paymentLink: true,
paymentMethodID: 'payment_method_id',
redirectImmediately: true,
requirePhoneNumber: true,
returnURL: 'return_url',
shortLink: true,
showSavedPaymentMethods: true,
taxID: 'tax_id',
trialPeriodDays: 0,
);

var_dump($subscription);
} catch (APIException $e) {
echo $e->getMessage();
}
using System;
using DodoPayments.Client;
using DodoPayments.Client.Models.Misc;
using DodoPayments.Client.Models.Payments;
using DodoPayments.Client.Models.Subscriptions;

DodoPaymentsClient client = new();

SubscriptionCreateParams parameters = new()
{
Billing = new()
{
Country = CountryCode.Af,
City = "city",
State = "state",
Street = "street",
Zipcode = "zipcode",
},
Customer = new AttachExistingCustomer("customer_id"),
ProductID = "product_id",
Quantity = 0,
};

var subscription = await client.Subscriptions.Create(parameters);

Console.WriteLine(subscription);
use dodopayments::Client;

#[tokio::main]
async fn main() -> dodopayments::Result<()> {
let client = Client::from_env()?;
let result = client
.subscriptions()
.create()
.body(dodopayments::models::SubscriptionsCreateParams {
billing: Some(Box::new(dodopayments::models::BillingAddress {
country: Box::new(dodopayments::models::CountryCode::Af),
city: None,
state: None,
street: None,
zipcode: None,
})),
customer: Some(Box::new(dodopayments::models::CustomerRequest::AttachExistingCustomer(Box::new(dodopayments::models::AttachExistingCustomer {
customer_id: "customer_id".to_string(),
})))),
product_id: Some("product_id".to_string()),
quantity: Some(0),
..Default::default()
})
.await?;
println!("{result:?}");
Ok(())
}
curl --request POST \
--url https://test.dodopayments.com/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"billing": {
"city": "<string>",
"state": "<string>",
"street": "<string>",
"zipcode": "<string>"
},
"customer": {
"customer_id": "<string>"
},
"product_id": "<string>",
"quantity": 1,
"addons": [
{
"addon_id": "<string>",
"quantity": 1
}
],
"allowed_payment_method_types": [],
"customer_business_name": "<string>",
"discount_code": "<string>",
"discount_codes": [
"<string>"
],
"force_3ds": true,
"mandate_min_amount_inr_paise": 123,
"metadata": {},
"on_demand": {
"mandate_only": true,
"adaptive_currency_fees_inclusive": true,
"product_description": "<string>",
"product_price": 123
},
"one_time_product_cart": [
{
"product_id": "<string>",
"quantity": 1,
"amount": 123
}
],
"payment_link": true,
"payment_method_id": "<string>",
"redirect_immediately": true,
"require_phone_number": true,
"return_url": "<string>",
"short_link": true,
"show_saved_payment_methods": true,
"tax_id": "<string>",
"trial_period_days": 123
}
'
{
  "addons": [
    {
      "addon_id": "<string>",
      "quantity": 123
    }
  ],
  "customer": {
    "customer_id": "<string>",
    "email": "<string>",
    "name": "<string>",
    "metadata": {},
    "phone_number": "<string>"
  },
  "metadata": {},
  "payment_id": "<string>",
  "recurring_pre_tax_amount": 1,
  "subscription_id": "<string>",
  "client_secret": "<string>",
  "discount_id": "<string>",
  "discount_ids": [
    "<string>"
  ],
  "expires_on": "2023-11-07T05:31:56Z",
  "one_time_product_cart": [
    {
      "product_id": "<string>",
      "quantity": 1
    }
  ],
  "payment_link": "<string>"
}
Deprecated API: This API will be deprecated soon. We recommend using Checkout Sessions instead, which provides a more powerful and customizable API to create payment links for one-time payments and subscriptions.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Request payload for creating a new subscription

This struct represents the data required to create a new subscription in the system. It includes details about the product, quantity, customer information, and billing details.

billing
object
required

Billing address information for the subscription

customer
Attach Existing Customer · object
required

Customer details for the subscription

product_id
string
required

Unique identifier of the product to subscribe to

quantity
integer<int32>
required

Number of units to subscribe for. Must be at least 1.

Required range: x >= 0
addons
Attach Addon Request · object[] | null

Attach addons to this subscription

allowed_payment_method_types
enum<string>[] | null

List of payment methods allowed during checkout.

Customers will never see payment methods that are not in this list. However, adding a method here does not guarantee customers will see it. Availability still depends on other factors (e.g., customer location, merchant settings).

All supported payment method types.

Used for disabled-payment-methods filtering and validation.

Available options:
ach,
affirm,
afterpay_clearpay,
alfamart,
ali_pay,
ali_pay_hk,
alma,
amazon_pay,
apple_pay,
atome,
bacs,
bancontact_card,
becs,
benefit,
bizum,
blik,
boleto,
bca_bank_transfer,
bni_va,
bri_va,
card_redirect,
cimb_va,
classic,
credit,
crypto_currency,
cashapp,
dana,
danamon_va,
debit,
duit_now,
efecty,
eft,
eps,
fps,
evoucher,
giropay,
givex,
google_pay,
go_pay,
gcash,
ideal,
interac,
indomaret,
klarna,
kakao_pay,
local_bank_redirect,
mandiri_va,
knet,
mb_way,
mobile_pay,
momo,
momo_atm,
multibanco,
online_banking_thailand,
online_banking_czech_republic,
online_banking_finland,
online_banking_fpx,
online_banking_poland,
online_banking_slovakia,
oxxo,
pago_efectivo,
permata_bank_transfer,
open_banking_uk,
pay_bright,
paypal,
paze,
pix,
pay_safe_card,
przelewy24,
prompt_pay,
pse,
red_compra,
red_pagos,
samsung_pay,
sepa,
sepa_bank_transfer,
sofort,
sunbit,
swish,
touch_n_go,
trustly,
twint,
upi_collect,
upi_intent,
vipps,
viet_qr,
venmo,
walley,
we_chat_pay,
seven_eleven,
lawson,
mini_stop,
family_mart,
seicomart,
pay_easy,
local_bank_transfer,
mifinity,
open_banking_pis,
direct_carrier_billing,
instant_bank_transfer,
billie,
zip,
revolut_pay,
naver_pay,
payco,
satispay
billing_currency
null | enum<string>

Fix the currency in which the end customer is billed. If Dodo Payments cannot support that currency for this transaction, it will not proceed

Available options:
AED,
ALL,
AMD,
ANG,
AOA,
ARS,
AUD,
AWG,
AZN,
BAM,
BBD,
BDT,
BGN,
BHD,
BIF,
BMD,
BND,
BOB,
BRL,
BSD,
BWP,
BYN,
BZD,
CAD,
CHF,
CLP,
CNY,
COP,
CRC,
CUP,
CVE,
CZK,
DJF,
DKK,
DOP,
DZD,
EGP,
ETB,
EUR,
FJD,
FKP,
GBP,
GEL,
GHS,
GIP,
GMD,
GNF,
GTQ,
GYD,
HKD,
HNL,
HRK,
HTG,
HUF,
IDR,
ILS,
INR,
IQD,
JMD,
JOD,
JPY,
KES,
KGS,
KHR,
KMF,
KRW,
KWD,
KYD,
KZT,
LAK,
LBP,
LKR,
LRD,
LSL,
LYD,
MAD,
MDL,
MGA,
MKD,
MMK,
MNT,
MOP,
MRU,
MUR,
MVR,
MWK,
MXN,
MYR,
MZN,
NAD,
NGN,
NIO,
NOK,
NPR,
NZD,
OMR,
PAB,
PEN,
PGK,
PHP,
PKR,
PLN,
PYG,
QAR,
RON,
RSD,
RUB,
RWF,
SAR,
SBD,
SCR,
SEK,
SGD,
SHP,
SLE,
SLL,
SOS,
SRD,
SSP,
STN,
SVC,
SZL,
THB,
TND,
TOP,
TRY,
TTD,
TWD,
TZS,
UAH,
UGX,
USD,
UYU,
UZS,
VES,
VND,
VUV,
WST,
XAF,
XCD,
XOF,
XPF,
YER,
ZAR,
ZMW
customer_business_name
string | null

Optional business / legal name associated with the tax id. When provided together with a valid tax id for a B2B purchase, this name is rendered on the invoice instead of the customer's personal name.

discount_code
string | null
deprecated

DEPRECATED: Use discount_codes instead. Cannot be used together with discount_codes.

discount_codes
string[] | null

Stacked discount codes to apply, in order of application. Max 20. Cannot be used together with discount_code.

force_3ds
boolean | null

Override merchant default 3DS behaviour for this subscription

mandate_min_amount_inr_paise
integer<int32> | null

Override the merchant-level mandate floor (in INR paise) for INR e-mandates on Indian-card recurring payments. The mandate amount sent to the processor is max(this_floor, actual_billing_amount), so this is effectively the customer-facing authorization ceiling whenever billing is lower. When unset, the merchant setting applies; when that's also unset, the system default of ₹15,000 applies.

metadata
Metadata · object

Additional metadata for the subscription Defaults to empty if not specified

on_demand
null | On Demand Subscription Request · object
one_time_product_cart
One-Time Product Cart Item · object[] | null

List of one time products that will be bundled with the first payment for this subscription

If true, generates a payment link. Defaults to false if not specified.

payment_method_id
string | null

Optional payment method ID to use for this subscription. If provided, customer_id must also be provided (via AttachExistingCustomer). The payment method will be validated for eligibility with the subscription's currency.

redirect_immediately
boolean

If true, redirects the customer immediately after payment completion False by default

require_phone_number
boolean

If true, the customer's phone number is required to create this subscription. Typically set alongside payment_link=true so merchants can enforce phone collection on the hosted payment page. Defaults to false.

return_url
string | null

Optional URL to redirect after successful subscription creation

If true, returns a shortened payment link. Defaults to false if not specified.

show_saved_payment_methods
boolean

Display saved payment methods of a returning customer False by default

tax_id
string | null

Tax ID in case the payment is B2B. If tax id validation fails the payment creation will fail

trial_period_days
integer<int32> | null

Optional trial period in days If specified, this value overrides the trial period set in the product's price Must be between 0 and 10000 days

Response

Subscription successfully initiated

addons
Addon Cart Response Item · object[]
required

Addons associated with this subscription

customer
object
required

Customer details associated with this subscription

metadata
Metadata · object
required

Additional metadata associated with the subscription

payment_id
string
required

First payment id for the subscription

recurring_pre_tax_amount
integer<int32>
required

Tax will be added to the amount and charged to the customer on each billing cycle

Required range: x >= 0
subscription_id
string
required

Unique identifier for the subscription

client_secret
string | null

Client secret used to load Dodo checkout SDK NOTE : Dodo checkout SDK will be coming soon

discount_id
string | null
deprecated

DEPRECATED: Use discount_ids instead. Returns the first discount's ID if present.

discount_ids
string[] | null

All stacked discount IDs applied, in order of application

expires_on
string<date-time> | null

Expiry timestamp of the payment link

one_time_product_cart
One-Time Product Cart Item Response · object[] | null

One time products associated with the purchase of subscription

URL to checkout page

Last modified on March 25, 2026