// File: crates/hyperswitch_connectors/src/connectors/bankofamerica.rs
// Module: hyperswitch_connectors
// Public functions: 3
// Public structs: 1

pub mod transformers;

use std::sync::LazyLock;

use base64::Engine;
use common_enums::enums;
use common_utils::{
    consts,
    errors::CustomResult,
    ext_traits::BytesExt,
    request::{Method, Request, RequestBuilder, RequestContent},
    types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
    payment_method_data::PaymentMethodData,
    router_data::{AccessToken, ErrorResponse, RouterData},
    router_flow_types::{
        access_token_auth::AccessTokenAuth,
        payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
        refunds::{Execute, RSync},
    },
    router_request_types::{
        AccessTokenRequestData, PaymentMethodTokenizationData, PaymentsAuthorizeData,
        PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData,
        RefundsData, SetupMandateRequestData,
    },
    router_response_types::{
        ConnectorInfo, PaymentMethodDetails, PaymentsResponseData, RefundsResponseData,
        SupportedPaymentMethods, SupportedPaymentMethodsExt,
    },
    types::{
        PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
        PaymentsSyncRouterData, RefundSyncRouterData, RefundsRouterData, SetupMandateRouterData,
    },
};
use hyperswitch_interfaces::{
    api::{
        self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorSpecifications,
        ConnectorValidation,
    },
    configs::Connectors,
    errors,
    events::connector_api_logs::ConnectorEvent,
    types::{
        PaymentsAuthorizeType, PaymentsCaptureType, PaymentsSyncType, PaymentsVoidType,
        RefundExecuteType, RefundSyncType, Response, SetupMandateType,
    },
    webhooks,
};
use masking::{ExposeInterface, Mask, Maskable, PeekInterface};
use ring::{digest, hmac};
use time::OffsetDateTime;
use transformers as bankofamerica;
use url::Url;

use crate::{
    connectors::bankofamerica::transformers::BankOfAmericaRouterData,
    constants::{self, headers},
    types::ResponseRouterData,
    utils::{self, convert_amount, PaymentMethodDataType, RefundsRequestData},
};

pub const V_C_MERCHANT_ID: &str = "v-c-merchant-id";

#[derive(Clone)]
pub struct Bankofamerica {
    amount_convertor: &'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync),
}

impl Bankofamerica {
    pub fn new() -> &'static Self {
        &Self {
            amount_convertor: &StringMajorUnitForConnector,
        }
    }
}

impl api::Payment for Bankofamerica {}
impl api::PaymentSession for Bankofamerica {}
impl api::ConnectorAccessToken for Bankofamerica {}
impl api::MandateSetup for Bankofamerica {}
impl api::PaymentAuthorize for Bankofamerica {}
impl api::PaymentSync for Bankofamerica {}
impl api::PaymentCapture for Bankofamerica {}
impl api::PaymentVoid for Bankofamerica {}
impl api::Refund for Bankofamerica {}
impl api::RefundExecute for Bankofamerica {}
impl api::RefundSync for Bankofamerica {}
impl api::PaymentToken for Bankofamerica {}

impl Bankofamerica {
    pub fn generate_digest(&self, payload: &[u8]) -> String {
        let payload_digest = digest::digest(&digest::SHA256, payload);
        consts::BASE64_ENGINE.encode(payload_digest)
    }

    pub fn generate_signature(
        &self,
        auth: bankofamerica::BankOfAmericaAuthType,
        host: String,
        resource: &str,
        payload: &String,
        date: OffsetDateTime,
        http_method: Method,
    ) -> CustomResult<String, errors::ConnectorError> {
        let bankofamerica::BankOfAmericaAuthType {
            api_key,
            merchant_account,
            api_secret,
        } = auth;
        let is_post_method = matches!(http_method, Method::Post);
        let digest_str = if is_post_method { "digest " } else { "" };
        let headers = format!("host date (request-target) {digest_str}{V_C_MERCHANT_ID}");
        let request_target = if is_post_method {
            format!("(request-target): post {resource}\ndigest: SHA-256={payload}\n")
        } else {
            format!("(request-target): get {resource}\n")
        };
        let signature_string = format!(
            "host: {host}\ndate: {date}\n{request_target}{V_C_MERCHANT_ID}: {}",
            merchant_account.peek()
        );
        let key_value = consts::BASE64_ENGINE
            .decode(api_secret.expose())
            .change_context(errors::ConnectorError::InvalidConnectorConfig {
                config: "connector_account_details.api_secret",
            })?;
        let key = hmac::Key::new(hmac::HMAC_SHA256, &key_value);
        let signature_value =
            consts::BASE64_ENGINE.encode(hmac::sign(&key, signature_string.as_bytes()).as_ref());
        let signature_header = format!(
            r#"keyid="{}", algorithm="HmacSHA256", headers="{headers}", signature="{signature_value}""#,
            api_key.peek()
        );

        Ok(signature_header)
    }
}

impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, PaymentsResponseData>
    for Bankofamerica
{
    // Not Implemented (R)
}

impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Bankofamerica
where
    Self: ConnectorIntegration<Flow, Request, Response>,
{
    fn build_headers(
        &self,
        req: &RouterData<Flow, Request, Response>,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        let date = OffsetDateTime::now_utc();
        let boa_req = self.get_request_body(req, connectors)?;
        let http_method = self.get_http_method();
        let auth = bankofamerica::BankOfAmericaAuthType::try_from(&req.connector_auth_type)?;
        let merchant_account = auth.merchant_account.clone();
        let base_url = connectors.bankofamerica.base_url.as_str();
        let boa_host =
            Url::parse(base_url).change_context(errors::ConnectorError::RequestEncodingFailed)?;
        let host = boa_host
            .host_str()
            .ok_or(errors::ConnectorError::RequestEncodingFailed)?;
        let path: String = self
            .get_url(req, connectors)?
            .chars()
            .skip(base_url.len() - 1)
            .collect();
        let sha256 = self.generate_digest(boa_req.get_inner_value().expose().as_bytes());
        let signature = self.generate_signature(
            auth,
            host.to_string(),
            path.as_str(),
            &sha256,
            date,
            http_method,
        )?;

        let mut headers = vec![
            (
                headers::CONTENT_TYPE.to_string(),
                self.get_content_type().to_string().into(),
            ),
            (
                headers::ACCEPT.to_string(),
                "application/hal+json;charset=utf-8".to_string().into(),
            ),
            (V_C_MERCHANT_ID.to_string(), merchant_account.into_masked()),
            ("Date".to_string(), date.to_string().into()),
            ("Host".to_string(), host.to_string().into()),
            ("Signature".to_string(), signature.into_masked()),
        ];
        if matches!(http_method, Method::Post | Method::Put) {
            headers.push((
                "Digest".to_string(),
                format!("SHA-256={sha256}").into_masked(),
            ));
        }
        Ok(headers)
    }
}

impl ConnectorCommon for Bankofamerica {
    fn id(&self) -> &'static str {
        "bankofamerica"
    }

    fn get_currency_unit(&self) -> api::CurrencyUnit {
        api::CurrencyUnit::Base
    }

    fn common_get_content_type(&self) -> &'static str {
        "application/json;charset=utf-8"
    }

    fn base_url<'a>(&self, connectors: &'a Connectors) -> &'a str {
        connectors.bankofamerica.base_url.as_ref()
    }

    fn build_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaErrorResponse = res
            .response
            .parse_struct("BankOfAmerica ErrorResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        event_builder.map(|i| i.set_error_response_body(&response));
        router_env::logger::info!(connector_response=?response);

        let error_message = if res.status_code == 401 {
            constants::CONNECTOR_UNAUTHORIZED_ERROR
        } else {
            hyperswitch_interfaces::consts::NO_ERROR_MESSAGE
        };
        match response {
            transformers::BankOfAmericaErrorResponse::StandardError(response) => {
                let (code, message, reason) = match response.error_information {
                    Some(ref error_info) => {
                        let detailed_error_info = error_info.details.as_ref().map(|details| {
                            details
                                .iter()
                                .map(|det| format!("{} : {}", det.field, det.reason))
                                .collect::<Vec<_>>()
                                .join(", ")
                        });
                        (
                            error_info.reason.clone(),
                            error_info.reason.clone(),
                            transformers::get_error_reason(
                                Some(error_info.message.clone()),
                                detailed_error_info,
                                None,
                            ),
                        )
                    }
                    None => {
                        let detailed_error_info = response.details.map(|details| {
                            details
                                .iter()
                                .map(|det| format!("{} : {}", det.field, det.reason))
                                .collect::<Vec<_>>()
                                .join(", ")
                        });
                        (
                            response.reason.clone().map_or(
                                hyperswitch_interfaces::consts::NO_ERROR_CODE.to_string(),
                                |reason| reason.to_string(),
                            ),
                            response
                                .reason
                                .map_or(error_message.to_string(), |reason| reason.to_string()),
                            transformers::get_error_reason(
                                response.message,
                                detailed_error_info,
                                None,
                            ),
                        )
                    }
                };

                Ok(ErrorResponse {
                    status_code: res.status_code,
                    code,
                    message,
                    reason,
                    attempt_status: None,
                    connector_transaction_id: None,
                    network_advice_code: None,
                    network_decline_code: None,
                    network_error_message: None,
                    connector_metadata: None,
                })
            }
            transformers::BankOfAmericaErrorResponse::AuthenticationError(response) => {
                Ok(ErrorResponse {
                    status_code: res.status_code,
                    code: hyperswitch_interfaces::consts::NO_ERROR_CODE.to_string(),
                    message: response.response.rmsg.clone(),
                    reason: Some(response.response.rmsg),
                    attempt_status: None,
                    connector_transaction_id: None,
                    network_advice_code: None,
                    network_decline_code: None,
                    network_error_message: None,
                    connector_metadata: None,
                })
            }
        }
    }
}

impl ConnectorValidation for Bankofamerica {
    fn validate_mandate_payment(
        &self,
        pm_type: Option<enums::PaymentMethodType>,
        pm_data: PaymentMethodData,
    ) -> CustomResult<(), errors::ConnectorError> {
        let mandate_supported_pmd = std::collections::HashSet::from([
            PaymentMethodDataType::Card,
            PaymentMethodDataType::ApplePay,
            PaymentMethodDataType::GooglePay,
        ]);
        utils::is_mandate_supported(pm_data, pm_type, mandate_supported_pmd, self.id())
    }
}

impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Bankofamerica {
    //TODO: implement sessions flow
}

impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for Bankofamerica {}

impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsResponseData>
    for Bankofamerica
{
    fn get_headers(
        &self,
        req: &SetupMandateRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }
    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }
    fn get_url(
        &self,
        _req: &SetupMandateRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        Ok(format!("{}pts/v2/payments/", self.base_url(connectors)))
    }
    fn get_request_body(
        &self,
        req: &SetupMandateRouterData,
        _connectors: &Connectors,
    ) -> CustomResult<RequestContent, errors::ConnectorError> {
        let connector_req = bankofamerica::BankOfAmericaPaymentsRequest::try_from(req)?;
        Ok(RequestContent::Json(Box::new(connector_req)))
    }

    fn build_request(
        &self,
        req: &RouterData<SetupMandate, SetupMandateRequestData, PaymentsResponseData>,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Post)
                .url(&SetupMandateType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(SetupMandateType::get_headers(self, req, connectors)?)
                .set_body(SetupMandateType::get_request_body(self, req, connectors)?)
                .build(),
        ))
    }
    fn handle_response(
        &self,
        data: &SetupMandateRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<SetupMandateRouterData, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaSetupMandatesResponse = res
            .response
            .parse_struct("BankOfAmericaSetupMandatesResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);

        RouterData::try_from(ResponseRouterData {
            response,
            data: data.clone(),
            http_code: res.status_code,
        })
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }

    fn get_5xx_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaServerErrorResponse = res
            .response
            .parse_struct("BankOfAmericaServerErrorResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        event_builder.map(|event| event.set_response_body(&response));
        router_env::logger::info!(error_response=?response);

        let attempt_status = match response.reason {
            Some(reason) => match reason {
                transformers::Reason::SystemError => Some(enums::AttemptStatus::Failure),
                transformers::Reason::ServerTimeout | transformers::Reason::ServiceTimeout => None,
            },
            None => None,
        };
        Ok(ErrorResponse {
            status_code: res.status_code,
            reason: response.status.clone(),
            code: response
                .status
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_CODE.to_string()),
            message: response
                .message
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_MESSAGE.to_string()),
            attempt_status,
            connector_transaction_id: None,
            network_advice_code: None,
            network_decline_code: None,
            network_error_message: None,
            connector_metadata: None,
        })
    }
}

impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData>
    for Bankofamerica
{
    fn get_headers(
        &self,
        req: &PaymentsAuthorizeRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }

    fn get_url(
        &self,
        _req: &PaymentsAuthorizeRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        Ok(format!(
            "{}pts/v2/payments/",
            ConnectorCommon::base_url(self, connectors)
        ))
    }

    fn get_request_body(
        &self,
        req: &PaymentsAuthorizeRouterData,
        _connectors: &Connectors,
    ) -> CustomResult<RequestContent, errors::ConnectorError> {
        let amount = convert_amount(
            self.amount_convertor,
            req.request.minor_amount,
            req.request.currency,
        )?;

        let connector_router_data = BankOfAmericaRouterData::try_from((amount, req))?;
        let connector_req =
            bankofamerica::BankOfAmericaPaymentsRequest::try_from(&connector_router_data)?;

        Ok(RequestContent::Json(Box::new(connector_req)))
    }

    fn build_request(
        &self,
        req: &PaymentsAuthorizeRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Post)
                .url(&PaymentsAuthorizeType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(PaymentsAuthorizeType::get_headers(self, req, connectors)?)
                .set_body(PaymentsAuthorizeType::get_request_body(
                    self, req, connectors,
                )?)
                .build(),
        ))
    }

    fn handle_response(
        &self,
        data: &PaymentsAuthorizeRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<PaymentsAuthorizeRouterData, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaPaymentsResponse = res
            .response
            .parse_struct("Bankofamerica PaymentResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);
        RouterData::try_from(ResponseRouterData {
            response,
            data: data.clone(),
            http_code: res.status_code,
        })
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }

    fn get_5xx_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaServerErrorResponse = res
            .response
            .parse_struct("BankOfAmericaServerErrorResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        event_builder.map(|event| event.set_response_body(&response));
        router_env::logger::info!(error_response=?response);

        let attempt_status = match response.reason {
            Some(reason) => match reason {
                transformers::Reason::SystemError => Some(enums::AttemptStatus::Failure),
                transformers::Reason::ServerTimeout | transformers::Reason::ServiceTimeout => None,
            },
            None => None,
        };
        Ok(ErrorResponse {
            status_code: res.status_code,
            reason: response.status.clone(),
            code: response
                .status
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_CODE.to_string()),
            message: response
                .message
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_MESSAGE.to_string()),
            attempt_status,
            connector_transaction_id: None,
            network_advice_code: None,
            network_decline_code: None,
            network_error_message: None,
            connector_metadata: None,
        })
    }
}

impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Bankofamerica {
    fn get_headers(
        &self,
        req: &PaymentsSyncRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }

    fn get_http_method(&self) -> Method {
        Method::Get
    }

    fn get_url(
        &self,
        req: &PaymentsSyncRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        let connector_payment_id = req
            .request
            .connector_transaction_id
            .get_connector_transaction_id()
            .change_context(errors::ConnectorError::MissingConnectorTransactionID)?;
        Ok(format!(
            "{}tss/v2/transactions/{connector_payment_id}",
            self.base_url(connectors)
        ))
    }

    fn build_request(
        &self,
        req: &PaymentsSyncRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Get)
                .url(&PaymentsSyncType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(PaymentsSyncType::get_headers(self, req, connectors)?)
                .build(),
        ))
    }

    fn handle_response(
        &self,
        data: &PaymentsSyncRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<PaymentsSyncRouterData, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaTransactionResponse = res
            .response
            .parse_struct("BankOfAmerica PaymentSyncResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);
        RouterData::try_from(ResponseRouterData {
            response,
            data: data.clone(),
            http_code: res.status_code,
        })
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }
}

impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> for Bankofamerica {
    fn get_headers(
        &self,
        req: &PaymentsCaptureRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }

    fn get_url(
        &self,
        req: &PaymentsCaptureRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        let connector_payment_id = req.request.connector_transaction_id.clone();
        Ok(format!(
            "{}pts/v2/payments/{connector_payment_id}/captures",
            self.base_url(connectors)
        ))
    }

    fn get_request_body(
        &self,
        req: &PaymentsCaptureRouterData,
        _connectors: &Connectors,
    ) -> CustomResult<RequestContent, errors::ConnectorError> {
        let amount = convert_amount(
            self.amount_convertor,
            req.request.minor_amount_to_capture,
            req.request.currency,
        )?;

        let connector_router_data = BankOfAmericaRouterData::try_from((amount, req))?;
        let connector_req =
            bankofamerica::BankOfAmericaCaptureRequest::try_from(&connector_router_data)?;

        Ok(RequestContent::Json(Box::new(connector_req)))
    }

    fn build_request(
        &self,
        req: &PaymentsCaptureRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Post)
                .url(&PaymentsCaptureType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(PaymentsCaptureType::get_headers(self, req, connectors)?)
                .set_body(PaymentsCaptureType::get_request_body(
                    self, req, connectors,
                )?)
                .build(),
        ))
    }

    fn handle_response(
        &self,
        data: &PaymentsCaptureRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<PaymentsCaptureRouterData, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaPaymentsResponse = res
            .response
            .parse_struct("BankOfAmerica PaymentResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);
        RouterData::try_from(ResponseRouterData {
            response,
            data: data.clone(),
            http_code: res.status_code,
        })
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }

    fn get_5xx_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaServerErrorResponse = res
            .response
            .parse_struct("BankOfAmericaServerErrorResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        event_builder.map(|event| event.set_response_body(&response));
        router_env::logger::info!(error_response=?response);

        Ok(ErrorResponse {
            status_code: res.status_code,
            reason: response.status.clone(),
            code: response
                .status
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_CODE.to_string()),
            message: response
                .message
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_MESSAGE.to_string()),
            attempt_status: None,
            connector_transaction_id: None,
            network_advice_code: None,
            network_decline_code: None,
            network_error_message: None,
            connector_metadata: None,
        })
    }
}

impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Bankofamerica {
    fn get_headers(
        &self,
        req: &PaymentsCancelRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_url(
        &self,
        req: &PaymentsCancelRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        let connector_payment_id = req.request.connector_transaction_id.clone();
        Ok(format!(
            "{}pts/v2/payments/{connector_payment_id}/reversals",
            self.base_url(connectors)
        ))
    }

    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }

    fn get_request_body(
        &self,
        req: &PaymentsCancelRouterData,
        _connectors: &Connectors,
    ) -> CustomResult<RequestContent, errors::ConnectorError> {
        let minor_amount =
            req.request
                .minor_amount
                .ok_or(errors::ConnectorError::MissingRequiredField {
                    field_name: "Amount",
                })?;
        let currency =
            req.request
                .currency
                .ok_or(errors::ConnectorError::MissingRequiredField {
                    field_name: "Currency",
                })?;

        let amount = convert_amount(self.amount_convertor, minor_amount, currency)?;

        let connector_router_data = BankOfAmericaRouterData::try_from((amount, req))?;
        let connector_req =
            bankofamerica::BankOfAmericaVoidRequest::try_from(&connector_router_data)?;

        Ok(RequestContent::Json(Box::new(connector_req)))
    }

    fn build_request(
        &self,
        req: &PaymentsCancelRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Post)
                .url(&PaymentsVoidType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(PaymentsVoidType::get_headers(self, req, connectors)?)
                .set_body(PaymentsVoidType::get_request_body(self, req, connectors)?)
                .build(),
        ))
    }

    fn handle_response(
        &self,
        data: &PaymentsCancelRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<PaymentsCancelRouterData, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaPaymentsResponse = res
            .response
            .parse_struct("BankOfAmerica PaymentResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);
        RouterData::try_from(ResponseRouterData {
            response,
            data: data.clone(),
            http_code: res.status_code,
        })
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }

    fn get_5xx_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaServerErrorResponse = res
            .response
            .parse_struct("BankOfAmericaServerErrorResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        event_builder.map(|event| event.set_response_body(&response));
        router_env::logger::info!(error_response=?response);

        Ok(ErrorResponse {
            status_code: res.status_code,
            reason: response.status.clone(),
            code: response
                .status
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_CODE.to_string()),
            message: response
                .message
                .unwrap_or(hyperswitch_interfaces::consts::NO_ERROR_MESSAGE.to_string()),
            attempt_status: None,
            connector_transaction_id: None,
            network_advice_code: None,
            network_decline_code: None,
            network_error_message: None,
            connector_metadata: None,
        })
    }
}

impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Bankofamerica {
    fn get_headers(
        &self,
        req: &RefundsRouterData<Execute>,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }

    fn get_url(
        &self,
        req: &RefundsRouterData<Execute>,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        let connector_payment_id = req.request.connector_transaction_id.clone();
        Ok(format!(
            "{}pts/v2/payments/{connector_payment_id}/refunds",
            self.base_url(connectors)
        ))
    }

    fn get_request_body(
        &self,
        req: &RefundsRouterData<Execute>,
        _connectors: &Connectors,
    ) -> CustomResult<RequestContent, errors::ConnectorError> {
        let amount = convert_amount(
            self.amount_convertor,
            req.request.minor_refund_amount,
            req.request.currency,
        )?;

        let connector_router_data = BankOfAmericaRouterData::try_from((amount, req))?;
        let connector_req =
            bankofamerica::BankOfAmericaRefundRequest::try_from(&connector_router_data)?;

        Ok(RequestContent::Json(Box::new(connector_req)))
    }

    fn build_request(
        &self,
        req: &RefundsRouterData<Execute>,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        let request = RequestBuilder::new()
            .method(Method::Post)
            .url(&RefundExecuteType::get_url(self, req, connectors)?)
            .attach_default_headers()
            .headers(RefundExecuteType::get_headers(self, req, connectors)?)
            .set_body(RefundExecuteType::get_request_body(self, req, connectors)?)
            .build();
        Ok(Some(request))
    }

    fn handle_response(
        &self,
        data: &RefundsRouterData<Execute>,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<RefundsRouterData<Execute>, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaRefundResponse = res
            .response
            .parse_struct("bankofamerica RefundResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;

        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);

        RouterData::try_from(ResponseRouterData {
            response,
            data: data.clone(),
            http_code: res.status_code,
        })
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }
}

impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Bankofamerica {
    fn get_headers(
        &self,
        req: &RefundSyncRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
        self.build_headers(req, connectors)
    }

    fn get_content_type(&self) -> &'static str {
        self.common_get_content_type()
    }

    fn get_http_method(&self) -> Method {
        Method::Get
    }

    fn get_url(
        &self,
        req: &RefundSyncRouterData,
        connectors: &Connectors,
    ) -> CustomResult<String, errors::ConnectorError> {
        let refund_id = req.request.get_connector_refund_id()?;
        Ok(format!(
            "{}tss/v2/transactions/{refund_id}",
            self.base_url(connectors)
        ))
    }

    fn build_request(
        &self,
        req: &RefundSyncRouterData,
        connectors: &Connectors,
    ) -> CustomResult<Option<Request>, errors::ConnectorError> {
        Ok(Some(
            RequestBuilder::new()
                .method(Method::Get)
                .url(&RefundSyncType::get_url(self, req, connectors)?)
                .attach_default_headers()
                .headers(RefundSyncType::get_headers(self, req, connectors)?)
                .build(),
        ))
    }

    fn handle_response(
        &self,
        data: &RefundSyncRouterData,
        event_builder: Option<&mut ConnectorEvent>,
        res: Response,
    ) -> CustomResult<RefundSyncRouterData, errors::ConnectorError> {
        let response: bankofamerica::BankOfAmericaRsyncResponse = res
            .response
            .parse_struct("bankofamerica RefundSyncResponse")
            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
        event_builder.map(|i| i.set_response_body(&response));
        router_env::logger::info!(connector_response=?response);
        RouterData::try_from(ResponseRouterData {
            response,
            data: data.clone(),
            http_code: res.status_code,
        })
    }

    fn get_error_response(
        &self,
        res: Response,
        event_builder: Option<&mut ConnectorEvent>,
    ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
        self.build_error_response(res, event_builder)
    }
}

#[async_trait::async_trait]
impl webhooks::IncomingWebhook for Bankofamerica {
    fn get_webhook_object_reference_id(
        &self,
        _request: &webhooks::IncomingWebhookRequestDetails<'_>,
    ) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {
        Err(report!(errors::ConnectorError::WebhooksNotImplemented))
    }

    fn get_webhook_event_type(
        &self,
        _request: &webhooks::IncomingWebhookRequestDetails<'_>,
    ) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError> {


// Struct: RiskFactorsInner
// File: crates/hyperswitch_connectors/src/connectors/worldpay/response.rs
// Module: hyperswitch_connectors
// Implementations: 1

pub struct RiskFactorsInner


// Struct: HyperwalletAuthType
// File: crates/hyperswitch_connectors/src/connectors/hyperwallet/transformers.rs
// Module: hyperswitch_connectors
// Implementations: 0

pub struct HyperwalletAuthType


// File: crates/analytics/src/api_event/metrics/api_count.rs
// Module: analytics

use std::collections::HashSet;

use api_models::analytics::{
    api_event::{ApiEventDimensions, ApiEventFilters, ApiEventMetricsBucketIdentifier},
    Granularity, TimeRange,
};
use common_utils::errors::ReportSwitchExt;
use error_stack::ResultExt;
use time::PrimitiveDateTime;

use super::ApiEventMetricRow;
use crate::{
    query::{Aggregate, GroupByClause, QueryBuilder, QueryFilter, SeriesBucket, ToSql, Window},
    types::{AnalyticsCollection, AnalyticsDataSource, MetricsError, MetricsResult},
};

#[derive(Default)]
pub(super) struct ApiCount;

#[async_trait::async_trait]
impl<T> super::ApiEventMetric<T> for ApiCount
where
    T: AnalyticsDataSource + super::ApiEventMetricAnalytics,
    PrimitiveDateTime: ToSql<T>,
    AnalyticsCollection: ToSql<T>,
    Granularity: GroupByClause<T>,
    Aggregate<&'static str>: ToSql<T>,
    Window<&'static str>: ToSql<T>,
{
    async fn load_metrics(
        &self,
        _dimensions: &[ApiEventDimensions],
        merchant_id: &common_utils::id_type::MerchantId,
        filters: &ApiEventFilters,
        granularity: Option<Granularity>,
        time_range: &TimeRange,
        pool: &T,
    ) -> MetricsResult<HashSet<(ApiEventMetricsBucketIdentifier, ApiEventMetricRow)>> {
        let mut query_builder: QueryBuilder<T> = QueryBuilder::new(AnalyticsCollection::ApiEvents);

        query_builder
            .add_select_column(Aggregate::Count {
                field: None,
                alias: Some("api_count"),
            })
            .switch()?;
        if !filters.flow_type.is_empty() {
            query_builder
                .add_filter_in_range_clause(ApiEventDimensions::FlowType, &filters.flow_type)
                .attach_printable("Error adding flow_type filter")
                .switch()?;
        }
        query_builder
            .add_select_column(Aggregate::Min {
                field: "created_at",
                alias: Some("start_bucket"),
            })
            .switch()?;
        query_builder
            .add_select_column(Aggregate::Max {
                field: "created_at",
                alias: Some("end_bucket"),
            })
            .switch()?;
        if let Some(granularity) = granularity {
            granularity
                .set_group_by_clause(&mut query_builder)
                .attach_printable("Error adding granularity")
                .switch()?;
        }

        query_builder
            .add_filter_clause("merchant_id", merchant_id)
            .switch()?;

        time_range
            .set_filter_clause(&mut query_builder)
            .attach_printable("Error filtering time range")
            .switch()?;

        query_builder
            .execute_query::<ApiEventMetricRow, _>(pool)
            .await
            .change_context(MetricsError::QueryBuildingError)?
            .change_context(MetricsError::QueryExecutionFailure)?
            .into_iter()
            .map(|i| {
                Ok((
                    ApiEventMetricsBucketIdentifier::new(TimeRange {
                        start_time: match (granularity, i.start_bucket) {
                            (Some(g), Some(st)) => g.clip_to_start(st)?,
                            _ => time_range.start_time,
                        },
                        end_time: granularity.as_ref().map_or_else(
                            || Ok(time_range.end_time),
                            |g| i.end_bucket.map(|et| g.clip_to_end(et)).transpose(),
                        )?,
                    }),
                    i,
                ))
            })
            .collect::<error_stack::Result<
                HashSet<(ApiEventMetricsBucketIdentifier, ApiEventMetricRow)>,
                crate::query::PostProcessingError,
            >>()
            .change_context(MetricsError::PostProcessingFailure)
    }
}


// Function: generate_pm_vaulting_req_from_update_request
// File: crates/router/src/core/payment_methods/transformers.rs
// Module: router

pub fn generate_pm_vaulting_req_from_update_request(
    pm_create: domain::PaymentMethodVaultingData,
    pm_update: api::PaymentMethodUpdateData,
) -> domain::PaymentMethodVaultingData


                authentication_type: None,
                payment_method: None,
                error_message: None,
                payment_method_id: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::RejectUpdate {
                status,
                error_code,
                error_message,
                updated_by,
            } => Self {
                status: Some(status),
                modified_at: common_utils::date_time::now(),
                error_code,
                error_message,
                updated_by,
                amount: None,
                net_amount: None,
                currency: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::BlocklistUpdate {
                status,
                error_code,
                error_message,
                updated_by,
            } => Self {
                status: Some(status),
                modified_at: common_utils::date_time::now(),
                error_code,
                connector: Some(None),
                error_message,
                updated_by,
                merchant_connector_id: Some(None),
                amount: None,
                net_amount: None,
                currency: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                authentication_type: None,
                payment_method: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::ConnectorMandateDetailUpdate {
                connector_mandate_detail,
                updated_by,
            } => Self {
                payment_method_id: None,
                modified_at: common_utils::date_time::now(),
                updated_by,
                amount: None,
                net_amount: None,
                currency: None,
                status: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::PaymentMethodDetailsUpdate {
                payment_method_id,
                updated_by,
            } => Self {
                payment_method_id,
                modified_at: common_utils::date_time::now(),
                updated_by,
                amount: None,
                net_amount: None,
                currency: None,
                status: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::ResponseUpdate {
                status,
                connector,
                connector_transaction_id,
                authentication_type,
                payment_method_id,
                mandate_id,
                connector_metadata,
                payment_token,
                error_code,
                error_message,
                error_reason,
                connector_response_reference_id,
                amount_capturable,
                updated_by,
                authentication_data,
                encoded_data,
                unified_code,
                unified_message,
                capture_before,
                extended_authorization_applied,
                payment_method_data,
                connector_mandate_detail,
                charges,
                setup_future_usage_applied,
                network_transaction_id,
                is_overcapture_enabled,
            } => {
                let (connector_transaction_id, processor_transaction_data) =
                    connector_transaction_id
                        .map(ConnectorTransactionId::form_id_and_data)
                        .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
                        .unwrap_or((None, None));
                Self {
                    status: Some(status),
                    connector: connector.map(Some),
                    connector_transaction_id,
                    authentication_type,
                    payment_method_id,
                    modified_at: common_utils::date_time::now(),
                    mandate_id,
                    connector_metadata,
                    error_code,
                    error_message,
                    payment_token,
                    error_reason,
                    connector_response_reference_id,
                    amount_capturable,
                    updated_by,
                    authentication_data,
                    encoded_data,
                    unified_code,
                    unified_message,
                    payment_method_data,
                    processor_transaction_data,
                    connector_mandate_detail,
                    charges,
                    amount: None,
                    net_amount: None,
                    currency: None,
                    amount_to_capture: None,
                    payment_method: None,
                    cancellation_reason: None,
                    browser_info: None,
                    payment_method_type: None,
                    payment_experience: None,
                    business_sub_label: None,
                    straight_through_algorithm: None,
                    preprocessing_step_id: None,
                    capture_method: None,
                    multiple_capture_count: None,
                    surcharge_amount: None,
                    tax_amount: None,
                    merchant_connector_id: None,
                    external_three_ds_authentication_attempted: None,
                    authentication_connector: None,
                    authentication_id: None,
                    fingerprint_id: None,
                    payment_method_billing_address_id: None,
                    client_source: None,
                    client_version: None,
                    customer_acceptance: None,
                    card_network: None,
                    capture_before,
                    extended_authorization_applied,
                    shipping_cost: None,
                    order_tax_amount: None,
                    card_discovery: None,
                    issuer_error_code: None,
                    issuer_error_message: None,
                    setup_future_usage_applied,
                    routing_approach: None,
                    connector_request_reference_id: None,
                    network_transaction_id,
                    is_overcapture_enabled,
                    network_details: None,
                    is_stored_credential: None,
                    request_extended_authorization: None,
                }
            }
            PaymentAttemptUpdate::ErrorUpdate {
                connector,
                status,
                error_code,
                error_message,
                error_reason,
                amount_capturable,
                updated_by,
                unified_code,
                unified_message,
                connector_transaction_id,
                payment_method_data,
                authentication_type,
                issuer_error_code,
                issuer_error_message,
                network_details,
            } => {
                let (connector_transaction_id, processor_transaction_data) =
                    connector_transaction_id
                        .map(ConnectorTransactionId::form_id_and_data)
                        .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
                        .unwrap_or((None, None));
                Self {
                    connector: connector.map(Some),
                    status: Some(status),
                    error_message,
                    error_code,
                    modified_at: common_utils::date_time::now(),
                    error_reason,
                    amount_capturable,
                    updated_by,
                    unified_code,
                    unified_message,
                    connector_transaction_id,
                    payment_method_data,
                    authentication_type,
                    processor_transaction_data,
                    issuer_error_code,
                    issuer_error_message,
                    amount: None,
                    net_amount: None,
                    currency: None,
                    amount_to_capture: None,
                    payment_method: None,
                    payment_method_id: None,
                    cancellation_reason: None,
                    mandate_id: None,
                    browser_info: None,
                    payment_token: None,
                    connector_metadata: None,
                    payment_method_type: None,
                    payment_experience: None,
                    business_sub_label: None,
                    straight_through_algorithm: None,
                    preprocessing_step_id: None,
                    capture_method: None,
                    connector_response_reference_id: None,
                    multiple_capture_count: None,
                    surcharge_amount: None,
                    tax_amount: None,
                    merchant_connector_id: None,
                    authentication_data: None,
                    encoded_data: None,
                    external_three_ds_authentication_attempted: None,
                    authentication_connector: None,
                    authentication_id: None,
                    fingerprint_id: None,
                    payment_method_billing_address_id: None,
                    client_source: None,
                    client_version: None,
                    customer_acceptance: None,
                    card_network: None,
                    capture_before: None,
                    extended_authorization_applied: None,
                    shipping_cost: None,
                    order_tax_amount: None,
                    connector_mandate_detail: None,
                    card_discovery: None,
                    charges: None,
                    setup_future_usage_applied: None,
                    routing_approach: None,
                    connector_request_reference_id: None,
                    network_transaction_id: None,
                    is_overcapture_enabled: None,
                    network_details,
                    is_stored_credential: None,
                    request_extended_authorization: None,
                }
            }
            PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self {
                status: Some(status),
                modified_at: common_utils::date_time::now(),
                updated_by,
                amount: None,
                net_amount: None,
                currency: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                capture_before: None,
                extended_authorization_applied: None,
                order_tax_amount: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::UpdateTrackers {
                payment_token,
                connector,
                straight_through_algorithm,
                amount_capturable,
                surcharge_amount,
                tax_amount,
                updated_by,
                merchant_connector_id,
                routing_approach,
                is_stored_credential,
            } => Self {
                payment_token,
                modified_at: common_utils::date_time::now(),
                connector: connector.map(Some),
                straight_through_algorithm,
                amount_capturable,
                surcharge_amount,
                tax_amount,
                updated_by,
                merchant_connector_id: merchant_connector_id.map(Some),
                amount: None,
                net_amount: None,
                currency: None,
                status: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                capture_before: None,
                extended_authorization_applied: None,
                order_tax_amount: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::UnresolvedResponseUpdate {
                status,
                connector,
                connector_transaction_id,
                payment_method_id,
                error_code,
                error_message,
                error_reason,
                connector_response_reference_id,
                updated_by,
            } => {
                let (connector_transaction_id, processor_transaction_data) =
                    connector_transaction_id
                        .map(ConnectorTransactionId::form_id_and_data)
                        .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
                        .unwrap_or((None, None));
                Self {
                    status: Some(status),
                    connector: connector.map(Some),
                    connector_transaction_id,
                    payment_method_id,
                    modified_at: common_utils::date_time::now(),
                    error_code,
                    error_message,
                    error_reason,
                    connector_response_reference_id,
                    updated_by,
                    processor_transaction_data,
                    amount: None,
                    net_amount: None,
                    currency: None,
                    amount_to_capture: None,
                    authentication_type: None,
                    payment_method: None,
                    cancellation_reason: None,
                    mandate_id: None,
                    browser_info: None,
                    payment_token: None,
                    connector_metadata: None,
                    payment_method_data: None,
                    payment_method_type: None,
                    payment_experience: None,
                    business_sub_label: None,
                    straight_through_algorithm: None,
                    preprocessing_step_id: None,
                    capture_method: None,
                    multiple_capture_count: None,
                    surcharge_amount: None,
                    tax_amount: None,
                    amount_capturable: None,
                    merchant_connector_id: None,
                    authentication_data: None,
                    encoded_data: None,
                    unified_code: None,
                    unified_message: None,
                    external_three_ds_authentication_attempted: None,
                    authentication_connector: None,
                    authentication_id: None,
                    fingerprint_id: None,
                    payment_method_billing_address_id: None,
                    client_source: None,
                    client_version: None,
                    customer_acceptance: None,
                    card_network: None,
                    shipping_cost: None,
                    capture_before: None,
                    extended_authorization_applied: None,
                    order_tax_amount: None,
                    connector_mandate_detail: None,
                    card_discovery: None,
                    charges: None,
                    issuer_error_code: None,
                    issuer_error_message: None,
                    setup_future_usage_applied: None,
                    routing_approach: None,
                    connector_request_reference_id: None,
                    network_transaction_id: None,
                    is_overcapture_enabled: None,
                    network_details: None,
                    is_stored_credential: None,
                    request_extended_authorization: None,
                }
            }
            PaymentAttemptUpdate::PreprocessingUpdate {
                status,
                payment_method_id,
                connector_metadata,
                preprocessing_step_id,
                connector_transaction_id,
                connector_response_reference_id,
                updated_by,
            } => {
                let (connector_transaction_id, processor_transaction_data) =
                    connector_transaction_id
                        .map(ConnectorTransactionId::form_id_and_data)
                        .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
                        .unwrap_or((None, None));
                Self {
                    status: Some(status),
                    payment_method_id,
                    modified_at: common_utils::date_time::now(),
                    connector_metadata,
                    preprocessing_step_id,
                    connector_transaction_id,
                    connector_response_reference_id,
                    updated_by,
                    processor_transaction_data,
                    amount: None,
                    net_amount: None,
                    currency: None,
                    amount_to_capture: None,
                    connector: None,
                    authentication_type: None,
                    payment_method: None,
                    error_message: None,
                    cancellation_reason: None,
                    mandate_id: None,
                    browser_info: None,
                    payment_token: None,
                    error_code: None,
                    payment_method_data: None,
                    payment_method_type: None,
                    payment_experience: None,
                    business_sub_label: None,
                    straight_through_algorithm: None,
                    error_reason: None,
                    capture_method: None,
                    multiple_capture_count: None,
                    surcharge_amount: None,
                    tax_amount: None,
                    amount_capturable: None,
                    merchant_connector_id: None,
                    authentication_data: None,
                    encoded_data: None,
                    unified_code: None,
                    unified_message: None,
                    external_three_ds_authentication_attempted: None,
                    authentication_connector: None,
                    authentication_id: None,
                    fingerprint_id: None,
                    payment_method_billing_address_id: None,
                    client_source: None,
                    client_version: None,
                    customer_acceptance: None,
                    card_network: None,
                    capture_before: None,
                    extended_authorization_applied: None,
                    shipping_cost: None,
                    order_tax_amount: None,
                    connector_mandate_detail: None,
                    card_discovery: None,
                    charges: None,
                    issuer_error_code: None,
                    issuer_error_message: None,
                    setup_future_usage_applied: None,
                    routing_approach: None,
                    connector_request_reference_id: None,
                    network_transaction_id: None,
                    is_overcapture_enabled: None,
                    network_details: None,
                    is_stored_credential: None,
                    request_extended_authorization: None,
                }
            }
            PaymentAttemptUpdate::CaptureUpdate {
                multiple_capture_count,
                updated_by,
                amount_to_capture,
            } => Self {
                multiple_capture_count,
                modified_at: common_utils::date_time::now(),
                updated_by,
                amount_to_capture,
                amount: None,
                net_amount: None,
                currency: None,
                status: None,
                connector_transaction_id: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::AmountToCaptureUpdate {
                status,
                amount_capturable,
                updated_by,
            } => Self {
                status: Some(status),
                modified_at: common_utils::date_time::now(),
                amount_capturable: Some(amount_capturable),
                updated_by,
                amount: None,
                net_amount: None,
                currency: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                capture_before: None,
                extended_authorization_applied: None,
                order_tax_amount: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::ConnectorResponse {
                authentication_data,
                encoded_data,
                connector_transaction_id,
                connector,
                updated_by,
                charges,
            } => {
                let (connector_transaction_id, processor_transaction_data) =
                    connector_transaction_id
                        .map(ConnectorTransactionId::form_id_and_data)
                        .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
                        .unwrap_or((None, None));
                Self {
                    authentication_data,
                    encoded_data,
                    connector_transaction_id,
                    connector: connector.map(Some),
                    modified_at: common_utils::date_time::now(),
                    updated_by,
                    processor_transaction_data,
                    charges,
                    amount: None,
                    net_amount: None,
                    currency: None,
                    status: None,
                    amount_to_capture: None,
                    authentication_type: None,
                    payment_method: None,
                    error_message: None,
                    payment_method_id: None,
                    cancellation_reason: None,
                    mandate_id: None,
                    browser_info: None,
                    payment_token: None,
                    error_code: None,
                    connector_metadata: None,
                    payment_method_data: None,
                    payment_method_type: None,
                    payment_experience: None,
                    business_sub_label: None,
                    straight_through_algorithm: None,
                    preprocessing_step_id: None,
                    error_reason: None,
                    capture_method: None,
                    connector_response_reference_id: None,
                    multiple_capture_count: None,
                    surcharge_amount: None,
                    tax_amount: None,
                    amount_capturable: None,
                    merchant_connector_id: None,
                    unified_code: None,
                    unified_message: None,
                    external_three_ds_authentication_attempted: None,
                    authentication_connector: None,
                    authentication_id: None,
                    fingerprint_id: None,
                    payment_method_billing_address_id: None,
                    client_source: None,
                    client_version: None,
                    customer_acceptance: None,
                    card_network: None,
                    shipping_cost: None,
                    capture_before: None,
                    extended_authorization_applied: None,
                    order_tax_amount: None,
                    connector_mandate_detail: None,
                    card_discovery: None,
                    issuer_error_code: None,
                    issuer_error_message: None,
                    setup_future_usage_applied: None,
                    routing_approach: None,
                    connector_request_reference_id: None,
                    network_transaction_id: None,
                    is_overcapture_enabled: None,
                    network_details: None,
                    is_stored_credential: None,
                    request_extended_authorization: None,
                }
            }
            PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
                amount,
                amount_capturable,
            } => Self {
                amount: Some(amount),
                modified_at: common_utils::date_time::now(),
                amount_capturable: Some(amount_capturable),
                net_amount: None,
                currency: None,
                status: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                updated_by: String::default(),
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                external_three_ds_authentication_attempted: None,
                authentication_connector: None,
                authentication_id: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::AuthenticationUpdate {
                status,
                external_three_ds_authentication_attempted,
                authentication_connector,
                authentication_id,
                updated_by,
            } => Self {
                status: Some(status),
                modified_at: common_utils::date_time::now(),
                external_three_ds_authentication_attempted,
                authentication_connector,
                authentication_id,
                updated_by,
                amount: None,
                net_amount: None,
                currency: None,
                connector_transaction_id: None,
                amount_to_capture: None,
                connector: None,
                authentication_type: None,
                payment_method: None,
                error_message: None,
                payment_method_id: None,
                cancellation_reason: None,
                mandate_id: None,
                browser_info: None,
                payment_token: None,
                error_code: None,
                connector_metadata: None,
                payment_method_data: None,
                payment_method_type: None,
                payment_experience: None,
                business_sub_label: None,
                straight_through_algorithm: None,
                preprocessing_step_id: None,
                error_reason: None,
                capture_method: None,
                connector_response_reference_id: None,
                multiple_capture_count: None,
                surcharge_amount: None,
                tax_amount: None,
                amount_capturable: None,
                merchant_connector_id: None,
                authentication_data: None,
                encoded_data: None,
                unified_code: None,
                unified_message: None,
                fingerprint_id: None,
                payment_method_billing_address_id: None,
                client_source: None,
                client_version: None,
                customer_acceptance: None,
                card_network: None,
                shipping_cost: None,
                order_tax_amount: None,
                capture_before: None,
                extended_authorization_applied: None,
                processor_transaction_data: None,
                connector_mandate_detail: None,
                card_discovery: None,
                charges: None,
                issuer_error_code: None,
                issuer_error_message: None,
                setup_future_usage_applied: None,
                routing_approach: None,
                connector_request_reference_id: None,
                network_transaction_id: None,
                is_overcapture_enabled: None,
                network_details: None,
                is_stored_credential: None,
                request_extended_authorization: None,
            },
            PaymentAttemptUpdate::ManualUpdate {
                status,
                error_code,
                error_message,
                error_reason,
                updated_by,
                unified_code,
                unified_message,
                connector_transaction_id,
            } => {
                let (connector_transaction_id, processor_transaction_data) =
                    connector_transaction_id
                        .map(ConnectorTransactionId::form_id_and_data)
                        .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
                        .unwrap_or((None, None));
                Self {
                    status,
                    error_code: error_code.map(Some),
                    modified_at: common_utils::date_time::now(),
                    error_message: error_message.map(Some),
                    error_reason: error_reason.map(Some),
                    updated_by,
                    unified_code: unified_code.map(Some),
                    unified_message: unified_message.map(Some),
                    connector_transaction_id,
                    processor_transaction_data,
                    amount: None,
                    net_amount: None,
                    currency: None,
                    amount_to_capture: None,
                    connector: None,
                    authentication_type: None,
                    payment_method: None,
                    payment_method_id: None,
                    cancellation_reason: None,
                    mandate_id: None,
                    browser_info: None,
                    payment_token: None,
                    connector_metadata: None,
                    payment_method_data: None,
                    payment_method_type: None,
                    payment_experience: None,
                    business_sub_label: None,
                    straight_through_algorithm: None,
                    preprocessing_step_id: None,
                    capture_method: None,
                    connector_response_reference_id: None,
                    multiple_capture_count: None,
                    surcharge_amount: None,
                    tax_amount: None,
                    amount_capturable: None,
                    merchant_connector_id: None,
                    authentication_data: None,
                    encoded_data: None,
                    external_three_ds_authentication_attempted: None,
                    authentication_connector: None,
                    authentication_id: None,
                    fingerprint_id: None,
                    payment_method_billing_address_id: None,
                    client_source: None,
                    client_version: None,
                    customer_acceptance: None,
                    card_network: None,
                    shipping_cost: None,
                    capture_before: None,
                    extended_authorization_applied: None,
                    order_tax_amount: None,
                    connector_mandate_detail: None,
                    card_discovery: None,
                    charges: None,


// Implementation: impl ResourceId
// File: crates/common_utils/src/types/authentication.rs
// Module: common_utils
// Methods: 1 total (1 public)

impl ResourceId


// Function: create_identity_from_certificate_and_key
// File: crates/external_services/src/http_client/client.rs
// Module: external_services

pub fn create_identity_from_certificate_and_key(
    encoded_certificate: masking::Secret<String>,
    encoded_certificate_key: masking::Secret<String>,
) -> Result<reqwest::Identity, error_stack::Report<HttpClientError>>


// Function: should_call_connector
// File: crates/router/src/core/payments.rs
// Module: router

pub fn should_call_connector<Op: Debug, F: Clone, D>(operation: &Op, payment_data: &D) -> bool
where
    D: OperationSessionGetters<F> + Send + Sync + Clone,


// Function: delete_evidence_file
// File: crates/router/src/core/disputes/transformers.rs
// Module: router

pub fn delete_evidence_file(
    dispute_evidence: DisputeEvidence,
    evidence_type: EvidenceType,
) -> DisputeEvidence


// Implementation: impl PaymentSync for for Riskified
// File: crates/hyperswitch_connectors/src/connectors/riskified.rs
// Module: hyperswitch_connectors
// Methods: 0 total (0 public)

impl PaymentSync for for Riskified


// Struct: Trustpayments
// File: crates/hyperswitch_connectors/src/connectors/trustpayments.rs
// Module: hyperswitch_connectors
// Implementations: 17
// Traits: api::Payment, api::PaymentSession, api::ConnectorAccessToken, api::MandateSetup, api::PaymentAuthorize, api::PaymentSync, api::PaymentCapture, api::PaymentVoid, api::Refund, api::RefundExecute, api::RefundSync, api::PaymentToken, ConnectorCommon, ConnectorValidation, webhooks::IncomingWebhook, ConnectorSpecifications

pub struct Trustpayments

api::Payment api::PaymentSession api::ConnectorAccessToken api::MandateSetup api::PaymentAuthorize api::PaymentSync api::PaymentCapture api::PaymentVoid api::Refund api::RefundExecute api::RefundSync api::PaymentToken ConnectorCommon ConnectorValidation webhooks::IncomingWebhook ConnectorSpecifications


// Struct: Authorization
// File: crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs
// Module: hyperswitch_connectors
// Implementations: 0

pub struct Authorization


// Trait: RoutingEventLogAnalytics
// File: crates/analytics/src/routing_events/events.rs
// Module: analytics

pub trait RoutingEventLogAnalytics: LoadRow<RoutingEventsResult>


// Implementation: impl api::MandateSetup for for Gigadat
// File: crates/hyperswitch_connectors/src/connectors/gigadat.rs
// Module: hyperswitch_connectors
// Methods: 0 total (0 public)

impl api::MandateSetup for for Gigadat


// Function: get_network_token_webhook_details
// File: crates/common_types/src/callback_mapper.rs
// Module: common_types

// Documentation: Retrieves the details of the network token webhook type from callback mapper data.

pub fn get_network_token_webhook_details(
        &self,
    ) -> (id_type::MerchantId, String, id_type::CustomerId)


// Implementation: impl Responder
// File: crates/router/src/routes/payments.rs
// Module: router
// Methods: 0 total (0 public)

impl Responder