formulate 1.2.0

formulate is a standalone server that listens for web form data submissions.
use rocket::serde::Deserialize;
// correlate. verb, have a mutual relationship or connection, in which one thing affects or depends on another

/// This module contains structure for different type of Stripe Events which may be sent to us.

/// Represents customer details from Stripe.
#[derive(Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct StripeCustomerDetails<'s> {
    pub email: &'s str,
    pub name: &'s str,
}

/// Stripe Charge details
#[derive(Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct StripeChargeObject<'s> {
    pub id: &'s str,
    pub created: i64,
    pub currency: &'s str,
    pub paid: bool,
    pub status: &'s str,
    pub amount: u32,
    pub billing_details: StripeCustomerDetails<'s>,
    pub calculated_statement_descriptor: Option<&'s str>,
    pub receipt_url: Option<&'s str>,
}

/// Stripe Checkout Session details
#[derive(Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct StripeCheckoutObject<'s> {
    pub id: &'s str,
    pub created: i64,
    pub currency: &'s str,
    pub payment_status: &'s str,
    pub status: &'s str,
    pub amount_total: u32,
    pub customer_details: StripeCustomerDetails<'s>,
}

/// Enum for the different types of webhook data we deal with
#[derive(Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
#[serde(untagged)]
pub enum StripeData<'s> {
    StripeCharge {
        #[serde(borrow)]
        object: StripeChargeObject<'s>,
    },
    StripeCheckout {
        #[serde(borrow)]
        object: StripeCheckoutObject<'s>,
    },
}

/// Stripe webhook event submission details
#[derive(Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct StripeEvent<'s> {
    #[serde(alias = "id")]
    pub _id: &'s str,
    #[serde(borrow)]
    pub data: StripeData<'s>,
    #[serde(rename(deserialize = "type"))]
    pub event_type: &'s str,
}