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};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct DiscountResponse {
    /// The 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`).
    #[serde(rename = "amount")]
    pub amount: i32,
    /// The business this discount belongs to.
    #[serde(rename = "business_id")]
    pub business_id: String,
    /// The discount code (up to 16 chars).
    #[serde(rename = "code")]
    pub code: String,
    /// Timestamp when the discount is created
    #[serde(rename = "created_at")]
    pub created_at: String,
    /// The unique discount ID
    #[serde(rename = "discount_id")]
    pub discount_id: String,
    /// Optional date/time after which discount is expired.
    #[serde(rename = "expires_at", skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,
    /// Name for the Discount
    #[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")]
    pub preserve_on_plan_change: bool,
    /// List of product IDs to which this discount is restricted.
    #[serde(rename = "restricted_to")]
    pub restricted_to: 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>,
    /// How many times this discount has been used.
    #[serde(rename = "times_used")]
    pub times_used: i32,
    /// The type of discount, e.g. `percentage`, `flat`, or `flat_per_unit`.
    #[serde(rename = "type")]
    pub r#type: models::DiscountType,
    /// Usage limit for this discount, if any.
    #[serde(rename = "usage_limit", skip_serializing_if = "Option::is_none")]
    pub usage_limit: Option<i32>,
}

impl DiscountResponse {
    pub fn new(amount: i32, business_id: String, code: String, created_at: String, discount_id: String, preserve_on_plan_change: bool, restricted_to: Vec<String>, times_used: i32, r#type: models::DiscountType) -> DiscountResponse {
        DiscountResponse {
            amount,
            business_id,
            code,
            created_at,
            discount_id,
            expires_at: None,
            name: None,
            preserve_on_plan_change,
            restricted_to,
            subscription_cycles: None,
            times_used,
            r#type,
            usage_limit: None,
        }
    }
}