dodopayments_rust 2.2.2

Rust SDK for Dodo Payments API
Documentation
/*
 * public
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.87.0
 * 
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// CreateDiscountRequest : Request body for creating a discount.  `code` is optional; if not provided, we generate a random 16-char code.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct CreateDiscountRequest {
    /// The 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.
    #[serde(rename = "amount")]
    pub amount: i32,
    /// Optionally supply a code (will be uppercased). - Must be at least 3 characters if provided. - If omitted, a random 16-character code is generated.
    #[serde(rename = "code", skip_serializing_if = "Option::is_none")]
    pub code: Option<String>,
    /// When the discount expires, if ever.
    #[serde(rename = "expires_at", skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,
    #[serde(rename = "name", skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Whether this discount should be preserved when a subscription changes plans. Default: false (discount is removed on plan change)
    #[serde(rename = "preserve_on_plan_change", skip_serializing_if = "Option::is_none")]
    pub preserve_on_plan_change: Option<bool>,
    /// List of product IDs to restrict usage (if any).
    #[serde(rename = "restricted_to", skip_serializing_if = "Option::is_none")]
    pub restricted_to: Option<Vec<String>>,
    /// Number 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.
    #[serde(rename = "subscription_cycles", skip_serializing_if = "Option::is_none")]
    pub subscription_cycles: Option<i32>,
    /// The discount type (e.g. `percentage`, `flat`, or `flat_per_unit`).
    #[serde(rename = "type")]
    pub r#type: models::DiscountType,
    /// How many times this discount can be used (if any). Must be >= 1 if provided.
    #[serde(rename = "usage_limit", skip_serializing_if = "Option::is_none")]
    pub usage_limit: Option<i32>,
}

impl CreateDiscountRequest {
    /// Request body for creating a discount.  `code` is optional; if not provided, we generate a random 16-char code.
    pub fn new(amount: i32, r#type: models::DiscountType) -> CreateDiscountRequest {
        CreateDiscountRequest {
            amount,
            code: None,
            expires_at: None,
            name: None,
            preserve_on_plan_change: None,
            restricted_to: None,
            subscription_cycles: None,
            r#type,
            usage_limit: None,
        }
    }
}