Create Subscription

Create a subscription for a customer.

Request

use dodopayments_rust::{
    models::CreateSubscriptionRequest, to_pretty_json, DodoPaymentsClientBuilder,
};

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("DODO_API_KEY")?;

    let client = DodoPaymentsClientBuilder::new()
        .bearer_token(&api_key)
        .enviroment("test_mode")
        .build()?;

    let resp = client
        .subscriptions()
        .create()
        .body(CreateSubscriptionRequest {
            product_id: "prod_xxxxxxxxxx".to_string(),

            ..Default::default()
        })
        .send()
        .await?;

    println!("{}", to_pretty_json(&resp)?);

    Ok(())
}

Body

FieldTypeDescription
addonsobjectAttach addons to this subscription
allowed_payment_method_typesobjectList 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).
billingBillingAddressBilling address information for the subscription
billing_currencyobject
customerCustomerRequestCustomer details for the subscription
discount_codeobjectDiscount Code to apply to the subscription
force_3dsobjectOverride merchant default 3DS behaviour for this subscription
metadataMetadataAdditional metadata for the subscription Defaults to empty if not specified
on_demandobject
one_time_product_cartobjectList of one time products that will be bundled with the first payment for this subscription
payment_linkobjectIf true, generates a payment link. Defaults to false if not specified.
payment_method_idobjectOptional 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.
product_idstringUnique identifier of the product to subscribe to
quantityintegerNumber of units to subscribe for. Must be at least 1.
redirect_immediatelybooleanIf true, redirects the customer immediately after payment completion False by default
return_urlobjectOptional URL to redirect after successful subscription creation
short_linkobjectIf true, returns a shortened payment link. Defaults to false if not specified.
show_saved_payment_methodsbooleanDisplay saved payment methods of a returning customer False by default
tax_idobjectTax ID in case the payment is B2B. If tax id validation fails the payment creation will fail
trial_period_daysobjectOptional 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

Responses

200 Status

FieldTypeDescription
addonsarray<AddonCartResponseItem>Addons associated with this subscription
client_secretobjectClient secret used to load Dodo checkout SDK NOTE : Dodo checkout SDK will be coming soon
customerCustomerLimitedDetailsResponseCustomer details associated with this subscription
discount_idobjectThe discount id if discount is applied
expires_onobjectExpiry timestamp of the payment link
metadataMetadataAdditional metadata associated with the subscription
one_time_product_cartobjectOne time products associated with the purchase of subscription
payment_idstringFirst payment id for the subscription
payment_linkobjectURL to checkout page
recurring_pre_tax_amountintegerTax will be added to the amount and charged to the customer on each billing cycle
subscription_idstringUnique identifier for the subscription

Subscription successfully initiated

422 Status

Invalid Request Object or Parameters

500 Status

Something went wrong :(