Repository: juspay/hyperswitch
File: crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs (Rust)

Code before:
    Braintree,
}

impl ChargebeeWebhookBody {
    pub fn get_webhook_object_from_body(body: &[u8]) -> CustomResult<Self, errors::ConnectorError> {
        let webhook_body = body
            .parse_struct::<Self>("ChargebeeWebhookBody")
            .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
        Ok(webhook_body)
    }
}

impl ChargebeeInvoiceBody {
    pub fn get_invoice_webhook_data_from_body(
        body: &[u8],
    ) -> CustomResult<Self, errors::ConnectorError> {
        let webhook_body = body
            .parse_struct::<Self>("ChargebeeInvoiceBody")
            .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
        Ok(webhook_body)
    }
}
// Structure to extract MIT payment data from invoice_generated webhook
#[derive(Debug, Clone)]
pub struct ChargebeeMitPaymentData {
    pub invoice_id: String,
    pub amount_due: MinorUnit,
    pub currency_code: enums::Currency,
    pub status: String,
    pub customer_id: CustomerId,
    pub subscription_id: SubscriptionId,
    pub first_invoice: bool,
}

impl TryFrom<ChargebeeInvoiceBody> for ChargebeeMitPaymentData {
    type Error = error_stack::Report<errors::ConnectorError>;

    fn try_from(webhook_body: ChargebeeInvoiceBody) -> Result<Self, Self::Error> {
        let invoice = webhook_body.content.invoice;

        Ok(Self {
            invoice_id: invoice.id,
            amount_due: invoice.total,
            currency_code: invoice.currency_code,
            status: invoice.status.unwrap_or_else(|| "payment_due".to_string()),
            customer_id: invoice.customer_id,
            subscription_id: invoice.subscription_id,
            first_invoice: invoice.first_invoice.unwrap_or(false),
        })
    }
}

Review comment (suggestion):
```suggestion
    pub invoice_id: id_type::InvoiceId,
```

Code after:
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum ChargebeeGateway {
    Stripe,
    Braintree,
}

impl ChargebeeWebhookBody {
    pub fn get_webhook_object_from_body(body: &[u8]) -> CustomResult<Self, errors::ConnectorError> {
        let webhook_body = body
            .parse_struct::<Self>("ChargebeeWebhookBody")
            .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
        Ok(webhook_body)
    }
}

impl ChargebeeInvoiceBody {
    pub fn get_invoice_webhook_data_from_body(
        body: &[u8],
    ) -> CustomResult<Self, errors::ConnectorError> {
        let webhook_body = body
            .parse_struct::<Self>("ChargebeeInvoiceBody")
            .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
        Ok(webhook_body)
    }
}
// Structure to extract MIT payment data from invoice_generated webhook
#[derive(Debug, Clone)]
pub struct ChargebeeMitPaymentData {
    pub invoice_id: InvoiceId,
    pub amount_due: MinorUnit,
    pub currency_code: enums::Currency,
    pub status: Option<ChargebeeInvoiceStatus>,
    pub customer_id: CustomerId,
    pub subscription_id: SubscriptionId,
    pub first_invoice: bool,
}

impl TryFrom<ChargebeeInvoiceBody> for ChargebeeMitPaymentData {
    type Error = error_stack::Report<errors::ConnectorError>;

    fn try_from(webhook_body: ChargebeeInvoiceBody) -> Result<Self, Self::Error> {
        let invoice = webhook_body.content.invoice;

        Ok(Self {
            invoice_id: invoice.id,
            amount_due: invoice.total,
            currency_code: invoice.currency_code,
            status: invoice.status,