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

/// CreateSubscriptionRequest : 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.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct CreateSubscriptionRequest {
    /// Attach addons to this subscription
    #[serde(rename = "addons", skip_serializing_if = "Option::is_none")]
    pub addons: Option<Vec<models::AttachAddonReq>>,
    /// 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).
    #[serde(rename = "allowed_payment_method_types", skip_serializing_if = "Option::is_none")]
    pub allowed_payment_method_types: Option<Vec<models::PaymentMethodTypes>>,
    /// Billing address information for the subscription
    #[serde(rename = "billing")]
    pub billing: Box<models::BillingAddress>,
    /// Fix the currency in which the end customer is billed. If Dodo Payments cannot support that currency for this transaction, it will not proceed
    #[serde(rename = "billing_currency", skip_serializing_if = "Option::is_none")]
    pub billing_currency: Option<models::Currency>,
    /// Customer details for the subscription
    #[serde(rename = "customer")]
    pub customer: Box<models::CustomerRequest>,
    /// Discount Code to apply to the subscription
    #[serde(rename = "discount_code", skip_serializing_if = "Option::is_none")]
    pub discount_code: Option<String>,
    /// Override merchant default 3DS behaviour for this subscription
    #[serde(rename = "force_3ds", skip_serializing_if = "Option::is_none")]
    pub force_3ds: Option<bool>,
    /// Additional metadata for the subscription Defaults to empty if not specified
    #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")]
    pub metadata: Option<std::collections::HashMap<String, String>>,
    #[serde(rename = "on_demand", skip_serializing_if = "Option::is_none")]
    pub on_demand: Option<Box<models::OnDemandSubscriptionReq>>,
    /// List of one time products that will be bundled with the first payment for this subscription
    #[serde(rename = "one_time_product_cart", skip_serializing_if = "Option::is_none")]
    pub one_time_product_cart: Option<Vec<models::OneTimeProductCartItemReq>>,
    /// If true, generates a payment link. Defaults to false if not specified.
    #[serde(rename = "payment_link", skip_serializing_if = "Option::is_none")]
    pub payment_link: Option<bool>,
    /// Optional 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.
    #[serde(rename = "payment_method_id", skip_serializing_if = "Option::is_none")]
    pub payment_method_id: Option<String>,
    /// Unique identifier of the product to subscribe to
    #[serde(rename = "product_id")]
    pub product_id: String,
    /// Number of units to subscribe for. Must be at least 1.
    #[serde(rename = "quantity")]
    pub quantity: i32,
    /// If true, redirects the customer immediately after payment completion False by default
    #[serde(rename = "redirect_immediately", skip_serializing_if = "Option::is_none")]
    pub redirect_immediately: Option<bool>,
    /// Optional URL to redirect after successful subscription creation
    #[serde(rename = "return_url", skip_serializing_if = "Option::is_none")]
    pub return_url: Option<String>,
    /// If true, returns a shortened payment link. Defaults to false if not specified.
    #[serde(rename = "short_link", skip_serializing_if = "Option::is_none")]
    pub short_link: Option<bool>,
    /// Display saved payment methods of a returning customer False by default
    #[serde(rename = "show_saved_payment_methods", skip_serializing_if = "Option::is_none")]
    pub show_saved_payment_methods: Option<bool>,
    /// Tax ID in case the payment is B2B. If tax id validation fails the payment creation will fail
    #[serde(rename = "tax_id", skip_serializing_if = "Option::is_none")]
    pub tax_id: Option<String>,
    /// 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
    #[serde(rename = "trial_period_days", skip_serializing_if = "Option::is_none")]
    pub trial_period_days: Option<i32>,
}

impl CreateSubscriptionRequest {
    /// 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.
    pub fn new(billing: models::BillingAddress, customer: models::CustomerRequest, product_id: String, quantity: i32) -> CreateSubscriptionRequest {
        CreateSubscriptionRequest {
            addons: None,
            allowed_payment_method_types: None,
            billing: Box::new(billing),
            billing_currency: None,
            customer: Box::new(customer),
            discount_code: None,
            force_3ds: None,
            metadata: None,
            on_demand: None,
            one_time_product_cart: None,
            payment_link: None,
            payment_method_id: None,
            product_id,
            quantity,
            redirect_immediately: None,
            return_url: None,
            short_link: None,
            show_saved_payment_methods: None,
            tax_id: None,
            trial_period_days: None,
        }
    }
}