sellapp-sdk 0.2.0

Official Rust SDK for the SellApp API: manage products, orders, subscriptions, and customers.
// This file is auto-generated by oagen. Do not edit.

#[allow(unused_imports)]
use super::*;
#[allow(unused_imports)]
use crate::enums::*;
use serde::{Deserialize, Serialize};
/// The provider's own preview of the change, so most of its keys differ per provider. Stripe and subscriptions the store bills in house also say whether the change costs anything today, in `payment_required`, and when the subscription renews next, in `renewal_date`. PayPal and Razorpay previews carry neither and price no proration: PayPal reports that the buyer has to approve the change with PayPal, and Razorpay returns the new plan's price.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(remote = "Self")]
pub struct SubscriptionPlanChangePreviewPayload {
    /// The provider that previewed the change: `stripe`, `paypal`, `razorpay`, or `internal` for a subscription the store bills in house.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub provider: Option<String>,
    /// Whether confirming the change charges the customer today. `true` means `amount_due` is due now. Stripe charges it when the change is confirmed. A subscription the store bills in house bills it as a proration order, which the customer pays through the confirmation's `approval_url`. On Stripe this happens when the preview asks for `invoice_now`, and whenever the change starts a new billing period, such as a monthly plan moving to a yearly one or a free plan moving to a paid one, whatever `proration_behavior` says. In house, it happens when an immediate change leaves a difference to pay for the rest of the period. `false` means nothing is charged today, and any `amount_due` the preview still carries is the customer's next invoice, collected on `renewal_date`. A plan change during a trial is always `false`.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub payment_required: Option<bool>,
    /// When the subscription renews next once the change is made. That is the end of the current billing period, or the end of the new one when a Stripe change starts a new period.
    #[serde(
        skip_serializing_if = "Option::is_none",
        default,
        deserialize_with = "crate::runtime_schema::present_nullable"
    )]
    pub renewal_date: Option<Option<String>>,
    /// An amount in the currency's minor units, so `1500` is USD 15.00. With `payment_required: true` it is what the customer pays today. With `payment_required: false` it is the total of the next invoice, including the change's prorations. A subscription the store bills in house sends it only when `payment_required` is `true`. Stripe leaves it out, along with its other totals, when an unprorated change (`proration_behavior: none`) keeps the current billing period, and during a trial.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub amount_due: Option<i64>,
    /// Sent only while the subscription still has payments left at a discount from a subscription coupon or promotion and will renew, so not when it is set to cancel, because any plan change ends that discount. It is a sentence to show the customer before they confirm, naming what each payment bills after the change, for example `Changing plan ends your discount; after this change you'll pay $20.00 / month.` A Stripe preview's amounts already leave the discount out. A subscription the store bills in house credits the unused part of the current period at the discounted price the customer paid for it, not at the plan price.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub discount_warning: Option<String>,
    /// Fields returned by a newer API version that are not yet known to this SDK.
    #[serde(default, flatten)]
    pub additional_properties: std::collections::HashMap<String, serde_json::Value>,
}
impl Serialize for SubscriptionPlanChangePreviewPayload {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        Self::serialize(self, serializer)
    }
}
impl<'de> Deserialize<'de> for SubscriptionPlanChangePreviewPayload {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let mut value = serde_json::Value::deserialize(deserializer)?;
        crate::runtime_schema::model(&value, "SubscriptionPlanChangePreviewPayload", false)
            .map_err(serde::de::Error::custom)?;
        crate::runtime_schema::retain_model_fields(
            &mut value,
            "SubscriptionPlanChangePreviewPayload",
        );
        Self::deserialize(value).map_err(serde::de::Error::custom)
    }
}
impl SubscriptionPlanChangePreviewPayload {
    /// Validate the serialized request, including schema constraints and compatibility rules.
    pub fn validate_request(&self) -> Result<(), crate::error::Error> {
        let value = serde_json::to_value(self)
            .map_err(|e| crate::error::Error::Serialization(e.to_string()))?;
        crate::runtime_schema::model(&value, "SubscriptionPlanChangePreviewPayload", true)
    }
}