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

Code before:
    }

    fn get_webhook_resource_object(
        &self,
        request: &webhooks::IncomingWebhookRequestDetails<'_>,
    ) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
        let webhook_body: peachpayments::PeachpaymentsIncomingWebhook = request
            .body
            .parse_struct("PeachpaymentsIncomingWebhook")
            .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;

        let transaction = webhook_body
            .transaction
            .ok_or(errors::ConnectorError::WebhookResourceObjectNotFound)?;

        let payments_response = peachpayments::PeachpaymentsPaymentsResponse {
            transaction_id: transaction.transaction_id.clone(),
            response_code: transaction.response_code,
            transaction_result: transaction.transaction_result,
            ecommerce_card_payment_only_transaction_data: transaction
                .ecommerce_card_payment_only_transaction_data,
            original_transaction_id: transaction.original_transaction_id,
            reference_id: Some(transaction.reference_id),
            error_message: transaction.error_message,
            payment_method: Some(transaction.payment_method),
        };

        Ok(Box::new(payments_response))
    }

    async fn verify_webhook_source(
        &self,
        _request: &webhooks::IncomingWebhookRequestDetails<'_>,
        _merchant_id: &id_type::MerchantId,
        _connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,
        _connector_account_details: common_utils::crypto::Encryptable<Secret<serde_json::Value>>,
        _connector_name: &str,
    ) -> CustomResult<bool, errors::ConnectorError> {
        Ok(false)
    }
}

static PEACHPAYMENTS_SUPPORTED_PAYMENT_METHODS: LazyLock<SupportedPaymentMethods> =
    LazyLock::new(|| {
        let supported_capture_methods = vec![
            enums::CaptureMethod::Manual,
            enums::CaptureMethod::SequentialAutomatic,
        ];

        let supported_card_network = vec![
            common_enums::CardNetwork::Visa,

Review comment (suggestion):
Instead of creating a new struct PeachpaymentsIncomingWebhook and then parsing it to PeachpaymentsPaymentsResponse

Make PeachpaymentsPaymentsResponse an enum with 2 structs 1 for payments and 1 for webhooks

Refere Adyen

Code after:
    }

    fn get_webhook_resource_object(
        &self,
        request: &webhooks::IncomingWebhookRequestDetails<'_>,
    ) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
        let webhook_body: peachpayments::PeachpaymentsIncomingWebhook = request
            .body
            .parse_struct("PeachpaymentsIncomingWebhook")
            .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;

        Ok(Box::new(webhook_body))
    }

    async fn verify_webhook_source(
        &self,
        _request: &webhooks::IncomingWebhookRequestDetails<'_>,
        _merchant_id: &id_type::MerchantId,
        _connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,
        _connector_account_details: common_utils::crypto::Encryptable<Secret<serde_json::Value>>,
        _connector_name: &str,
    ) -> CustomResult<bool, errors::ConnectorError> {
        Ok(false)
    }
}

static PEACHPAYMENTS_SUPPORTED_PAYMENT_METHODS: LazyLock<SupportedPaymentMethods> =
    LazyLock::new(|| {
        let supported_capture_methods = vec![
            enums::CaptureMethod::Manual,
            enums::CaptureMethod::SequentialAutomatic,
        ];

        let supported_card_network = vec![
            common_enums::CardNetwork::Visa,
            common_enums::CardNetwork::Mastercard,
            common_enums::CardNetwork::AmericanExpress,
        ];

        let mut peachpayments_supported_payment_methods = SupportedPaymentMethods::new();

        peachpayments_supported_payment_methods.add(
            enums::PaymentMethod::Card,
            enums::PaymentMethodType::Credit,
            PaymentMethodDetails {
                mandates: enums::FeatureStatus::NotSupported,
                refunds: enums::FeatureStatus::NotSupported,
                supported_capture_methods: supported_capture_methods.clone(),
                specific_features: Some(
                    api_models::feature_matrix::PaymentMethodSpecificFeatures::Card({
                        api_models::feature_matrix::CardSpecificFeatures {