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

Code before:

    // Check if this is a mandate payment
    if router_data.request.is_mandate_payment() {
        // This is a merchant-initiated transaction for a recurring payment
        mandate_fields.card_on_file_indicator = Some(CardOnFileIndicator::RecurringPayment);
        mandate_fields.initiated_by = Some(InitiatedBy::Merchant);
        mandate_fields.stored_credential_indicator = Some(StoredCredentialIndicator::Used);
        mandate_fields.billing_method = Some(BillingMethod::Recurring);
        // Get the initial transaction ID if available
        mandate_fields.initial_transaction_id = router_data.request.related_transaction_id.clone();
    } else if router_data.request.setup_mandate_details.is_some() {
        // This is the initial transaction that will be used for future mandate payments
        mandate_fields.card_on_file_indicator = Some(CardOnFileIndicator::RecurringPayment);
        mandate_fields.initiated_by = Some(InitiatedBy::Customer);
        mandate_fields.stored_credential_indicator = Some(StoredCredentialIndicator::Stored);
        mandate_fields.billing_method = Some(BillingMethod::InitialRecurring);
    } else if router_data.request.off_session.unwrap_or(false) {
        // Off-session payment (merchant-initiated)
        mandate_fields.card_on_file_indicator = Some(CardOnFileIndicator::GeneralPurposeStorage);
        mandate_fields.initiated_by = Some(InitiatedBy::Merchant);
        mandate_fields.stored_credential_indicator = Some(StoredCredentialIndicator::Used);
    } else {
        // Regular customer-initiated transaction
        mandate_fields.initiated_by = Some(InitiatedBy::Customer);
    }

    mandate_fields
}

// Auth Struct for CeleroCommerce API key authentication
pub struct CeleroAuthType {
    pub(super) api_key: Secret<String>,
}

impl TryFrom<&ConnectorAuthType> for CeleroAuthType {
    type Error = error_stack::Report<errors::ConnectorError>;
    fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
        match auth_type {
            ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
                api_key: api_key.clone(),
            }),
            _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
        }
    }
}
// CeleroCommerce API Response Structures
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum CeleroResponseStatus {
    #[serde(alias = "success", alias = "Success", alias = "SUCCESS")]
    Success,
    #[serde(alias = "error", alias = "Error", alias = "ERROR")]

Review comment (suggestion):
This cases not required. For MIT check in payment method type if payment is of type mandate payment. Take reference from NMI

Code after:
// Helper function to determine CIT/MIT fields based on mandate data
fn determine_cit_mit_fields(
    router_data: &PaymentsAuthorizeRouterData,
) -> Result<(CeleroMandateFields, CeleroPaymentMethod), error_stack::Report<errors::ConnectorError>>
{
    // Default null values
    let mut mandate_fields = CeleroMandateFields::default();

    // First check if there's a mandate_id in the request
    match router_data
        .request
        .mandate_id
        .clone()
        .and_then(|mandate_ids| mandate_ids.mandate_reference_id)
    {
        // If there's a connector mandate ID, this is a MIT (Merchant Initiated Transaction)
        Some(api_models::payments::MandateReferenceId::ConnectorMandateId(
            connector_mandate_id,
        )) => {
            mandate_fields.card_on_file_indicator = Some(CardOnFileIndicator::RecurringPayment);
            mandate_fields.initiated_by = Some(InitiatedBy::Merchant); // This is a MIT
            mandate_fields.stored_credential_indicator = Some(StoredCredentialIndicator::Used);
            mandate_fields.billing_method = Some(BillingMethod::Recurring);
            mandate_fields.initial_transaction_id =
                connector_mandate_id.get_connector_mandate_request_reference_id();
            Ok((
                mandate_fields,
                CeleroPaymentMethod::Customer(CeleroCustomer {
                    id: Some(router_data.get_customer_id()?),
                    payment_method_id: connector_mandate_id.get_payment_method_id(),
                }),
            ))
        }
        // For other mandate types that might not be supported
        Some(api_models::payments::MandateReferenceId::NetworkMandateId(_))
        | Some(api_models::payments::MandateReferenceId::NetworkTokenWithNTI(_)) => {
            // These might need different handling or return an error
            Err(errors::ConnectorError::NotImplemented(
                get_unimplemented_payment_method_error_message("Celero"),
            )
            .into())
        }
        // If no mandate ID is present, check if it's a mandate payment
        None => {
            if router_data.request.is_mandate_payment() {
                // This is a customer-initiated transaction for a recurring payment
                mandate_fields.initiated_by = Some(InitiatedBy::Customer);
                mandate_fields.card_on_file_indicator = Some(CardOnFileIndicator::RecurringPayment);
                mandate_fields.billing_method = Some(BillingMethod::Recurring);
                mandate_fields.stored_credential_indicator = Some(StoredCredentialIndicator::Used);
            }