correlate 0.3.0

correlate is a standalone server that listens for Stripe webhook events and sends notification emails about successful orders.
use rocket::serde::Deserialize;

/// Individual product variant price configuration
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct ProductVariant {
    pub name: String,
    pub price: String,
    pub sku: String,
}

/// Product config from Rocket.toml that's accessible through AppConfig
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct ProductsConfig {
    pub products: Vec<ProductVariant>,
}

impl ProductsConfig {
    /// Get the price for a specific product variant
    ///
    /// # Arguments
    ///
    /// * `name` - The name of the product
    /// * `sku` - The SKU (variant) of the product
    ///
    /// # Returns
    ///
    /// * `Option<&str>` - The price as a string if found, None otherwise
    pub fn get_price(&self, name: &str, sku: &str) -> Option<&str> {
        // Find the matching variant and return its price
        self.products
            .iter()
            .find(|variant| {
                // Convert inputs to lowercase for case-insensitive comparison
                variant.name.to_lowercase() == name.to_lowercase()
                    && variant.sku.to_lowercase() == sku.to_lowercase()
            })
            .map(|variant| variant.price.as_str())
    }
}