Create Discount

Create a discount for your account.

Request

use dodopayments_rust::{
    models::{CreateDiscountRequest, DiscountType},
    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
        .discounts()
        .create()
        .body(CreateDiscountRequest {
            amount: 10,
            r#type: DiscountType::Percentage,
            ..Default::default()
        })
        .send()
        .await?;

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

    Ok(())
}

Body

FieldTypeDescription
amountintegerThe discount amount. - If discount_type is not percentage, amount is in USD cents. For example, 100 means $1.00. Only USD is allowed. - If discount_type is percentage, amount is in basis points. For example, 540 means 5.4%. Must be at least 1.
codeobjectOptionally supply a code (will be uppercased). - Must be at least 3 characters if provided. - If omitted, a random 16-character code is generated.
expires_atobjectWhen the discount expires, if ever.
nameobject
preserve_on_plan_changebooleanWhether this discount should be preserved when a subscription changes plans. Default: false (discount is removed on plan change)
restricted_toobjectList of product IDs to restrict usage (if any).
subscription_cyclesobjectNumber of subscription billing cycles this discount is valid for. If not provided, the discount will be applied indefinitely to all recurring payments related to the subscription.
typeDiscountTypeThe discount type (e.g. percentage, flat, or flat_per_unit).
usage_limitobjectHow many times this discount can be used (if any). Must be >= 1 if provided.

Responses

200 Status

FieldTypeDescription
amountintegerThe discount amount. - If discount_type is percentage, this is in basis points (e.g., 540 => 5.4%). - Otherwise, this is USD cents (e.g., 100 => $1.00).
business_idstringThe business this discount belongs to.
codestringThe discount code (up to 16 chars).
created_atstringTimestamp when the discount is created
discount_idstringThe unique discount ID
expires_atobjectOptional date/time after which discount is expired.
nameobjectName for the Discount
preserve_on_plan_changebooleanWhether this discount should be preserved when a subscription changes plans. Default: false (discount is removed on plan change)
restricted_toarray<string>List of product IDs to which this discount is restricted.
subscription_cyclesobjectNumber of subscription billing cycles this discount is valid for. If not provided, the discount will be applied indefinitely to all recurring payments related to the subscription.
times_usedintegerHow many times this discount has been used.
typeDiscountTypeThe type of discount, e.g. percentage, flat, or flat_per_unit.
usage_limitobjectUsage limit for this discount, if any.
  • If discount_type is percentage, this is in basis points (e.g., 540 => 5.4%). If not provided, the discount will be applied indefinitely to

  • If discount_type is percentage, this is in basis points (e.g., 540 => 5.4%). If not provided, the discount will be applied indefinitely to

  • If discount_type is percentage, this is in basis points (e.g., 540 => 5.4%). If not provided, the discount will be applied indefinitely to

  • If discount_type is percentage, this is in basis points (e.g., 540 => 5.4%). If not provided, the discount will be applied indefinitely to

Created discount

  • If discount_type is percentage, this is in basis points (e.g., 540 => 5.4%). If not provided, the discount will be applied indefinitely to

422 Status

Invalid Request Object or Parameters

500 Status

Something went wrong :(