Hoppa till huvudinnehåll
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);
{
  "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>",
  "expires_on": "2023-11-07T05:31:56Z",
  "one_time_product_cart": [
    {
      "product_id": "<string>",
      "quantity": 1
    }
  ],
  "payment_link": "<string>"
}
Avvecklad API: Denna API kommer snart att avvecklas. Vi rekommenderar att använda Checkout Sessions istället, som erbjuder en mer kraftfull och anpassningsbar API för att skapa betalningslänkar för engångsbetalningar och prenumerationer.

Auktoriseringar

Authorization
string
header
obligatorisk

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

Kropp

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
obligatorisk

Billing address information for the subscription

customer
Attach Existing Customer · object
obligatorisk

Customer details for the subscription

product_id
string
obligatorisk

Unique identifier of the product to subscribe to

quantity
integer<int32>
obligatorisk

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

Obligatoriskt intervall: 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).

Tillgängliga alternativ:
credit,
debit,
upi_collect,
upi_intent,
apple_pay,
cashapp,
google_pay,
multibanco,
bancontact_card,
eps,
ideal,
przelewy24,
paypal,
affirm,
klarna,
sepa,
ach,
amazon_pay,
afterpay_clearpay
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

Tillgängliga alternativ:
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
discount_code
string | null

Discount Code to apply to the subscription

force_3ds
boolean | null

Override merchant default 3DS behaviour for this subscription

metadata
object

Additional metadata for the subscription Defaults to empty if not specified

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

redirect_immediately
boolean

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

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

Svar

Subscription successfully initiated

addons
Addon Cart Response Item · object[]
obligatorisk

Addons associated with this subscription

customer
object
obligatorisk

Customer details associated with this subscription

metadata
object
obligatorisk

Additional metadata associated with the subscription

payment_id
string
obligatorisk

First payment id for the subscription

recurring_pre_tax_amount
integer<int32>
obligatorisk

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

Obligatoriskt intervall: x >= 0
subscription_id
string
obligatorisk

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

The discount id if discount is applied

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