Bug: [BUG] Deserialization Error Due to Error Coming in HTML format from Bluesnap Connector



### Bug Description

The Bluesnap Connector propagates errors received from its cloud service (Cloudflare). Cloudflare returns these errors in HTML format, and Bluesnap forwards them in the same HTML format. When an error is received in HTML format, the backend's deserialization fails because it expects the response to be in JSON format.

### Expected Behavior

The code should ensure any unexpected responses from the connector are appropriately logged and handled, providing meaningful and actionable error information to the caller.

### Actual Behavior

The server returns a 500 Internal Server Error without handling the issue gracefully.

### Steps To Reproduce

Only triggered when Bluesnap propagates error in HTML format. Bluesnap normally generates error in JSON format.


### Context For The Bug

_No response_

### Environment

Are you using hyperswitch hosted version? No

If not (or if building/running locally), please provide the following details:
1. Operating System or Linux distribution: mac
2. Rust version (output of `rustc --version`): `rustc 1.83.0 (90b35a623 2024-11-26)`
3. App version (output of `cargo r --features vergen -- --version`): ``


### Have you spent some time checking if this bug has been raised before?

- [x] I checked and didn't find a similar issue

### Have you read the Contributing Guidelines?

- [x] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

Yes, I am willing to submit a PR!
diff --git a/crates/hyperswitch_connectors/src/connectors/bluesnap.rs b/crates/hyperswitch_connectors/src/connectors/bluesnap.rs
index 8fac36424e2..3f319ee74f5 100644
--- a/crates/hyperswitch_connectors/src/connectors/bluesnap.rs
+++ b/crates/hyperswitch_connectors/src/connectors/bluesnap.rs
@@ -11,7 +11,7 @@ use common_utils::{
     request::{Method, Request, RequestBuilder, RequestContent},
     types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
 };
-use error_stack::{report, ResultExt};
+use error_stack::{report, Report, ResultExt};
 use hyperswitch_domain_models::{
     router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
     router_flow_types::{
@@ -55,9 +55,9 @@ use crate::{
     utils::{
         construct_not_supported_error_report, convert_amount,
         get_error_code_error_message_based_on_priority, get_header_key_value, get_http_header,
-        to_connector_meta_from_secret, to_currency_lower_unit, ConnectorErrorType,
-        ConnectorErrorTypeMapping, ForeignTryFrom, PaymentsAuthorizeRequestData,
-        RefundsRequestData, RouterData as _,
+        handle_json_response_deserialization_failure, to_connector_meta_from_secret,
+        to_currency_lower_unit, ConnectorErrorType, ConnectorErrorTypeMapping, ForeignTryFrom,
+        PaymentsAuthorizeRequestData, RefundsRequestData, RouterData as _,
     },
 };
 
@@ -132,74 +132,84 @@ impl ConnectorCommon for Bluesnap {
         event_builder: Option<&mut ConnectorEvent>,
     ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
         logger::debug!(bluesnap_error_response=?res);
-        let response: bluesnap::BluesnapErrors = res
-            .response
-            .parse_struct("BluesnapErrorResponse")
-            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
-
-        event_builder.map(|i| i.set_error_response_body(&response));
-        router_env::logger::info!(connector_response=?response);
+        let response_data: Result<
+            bluesnap::BluesnapErrors,
+            Report<common_utils::errors::ParsingError>,
+        > = res.response.parse_struct("BluesnapErrors");
+
+        match response_data {
+            Ok(response) => {
+                event_builder.map(|i| i.set_error_response_body(&response));
+                router_env::logger::info!(connector_response=?response);
 
-        let response_error_message = match response {
-            bluesnap::BluesnapErrors::Payment(error_response) => {
-                let error_list = error_response.message.clone();
-                let option_error_code_message = get_error_code_error_message_based_on_priority(
-                    self.clone(),
-                    error_list.into_iter().map(|errors| errors.into()).collect(),
-                );
-                let reason = error_response
-                    .message
-                    .iter()
-                    .map(|error| error.description.clone())
-                    .collect::<Vec<String>>()
-                    .join(" & ");
-                ErrorResponse {
-                    status_code: res.status_code,
-                    code: option_error_code_message
-                        .clone()
-                        .map(|error_code_message| error_code_message.error_code)
-                        .unwrap_or(NO_ERROR_CODE.to_string()),
-                    message: option_error_code_message
-                        .map(|error_code_message| error_code_message.error_message)
-                        .unwrap_or(NO_ERROR_MESSAGE.to_string()),
-                    reason: Some(reason),
-                    attempt_status: None,
-                    connector_transaction_id: None,
-                }
-            }
-            bluesnap::BluesnapErrors::Auth(error_res) => ErrorResponse {
-                status_code: res.status_code,
-                code: error_res.error_code.clone(),
-                message: error_res.error_name.clone().unwrap_or(error_res.error_code),
-                reason: Some(error_res.error_description),
-                attempt_status: None,
-                connector_transaction_id: None,
-            },
-            bluesnap::BluesnapErrors::General(error_response) => {
-                let (error_res, attempt_status) = if res.status_code == 403
-                    && error_response.contains(BLUESNAP_TRANSACTION_NOT_FOUND)
-                {
-                    (
-                        format!(
-                            "{} in bluesnap dashboard",
-                            REQUEST_TIMEOUT_PAYMENT_NOT_FOUND
-                        ),
-                        Some(enums::AttemptStatus::Failure), // when bluesnap throws 403 for payment not found, we update the payment status to failure.
-                    )
-                } else {
-                    (error_response.clone(), None)
+                let response_error_message = match response {
+                    bluesnap::BluesnapErrors::Payment(error_response) => {
+                        let error_list = error_response.message.clone();
+                        let option_error_code_message =
+                            get_error_code_error_message_based_on_priority(
+                                self.clone(),
+                                error_list.into_iter().map(|errors| errors.into()).collect(),
+                            );
+                        let reason = error_response
+                            .message
+                            .iter()
+                            .map(|error| error.description.clone())
+                            .collect::<Vec<String>>()
+                            .join(" & ");
+                        ErrorResponse {
+                            status_code: res.status_code,
+                            code: option_error_code_message
+                                .clone()
+                                .map(|error_code_message| error_code_message.error_code)
+                                .unwrap_or(NO_ERROR_CODE.to_string()),
+                            message: option_error_code_message
+                                .map(|error_code_message| error_code_message.error_message)
+                                .unwrap_or(NO_ERROR_MESSAGE.to_string()),
+                            reason: Some(reason),
+                            attempt_status: None,
+                            connector_transaction_id: None,
+                        }
+                    }
+                    bluesnap::BluesnapErrors::Auth(error_res) => ErrorResponse {
+                        status_code: res.status_code,
+                        code: error_res.error_code.clone(),
+                        message: error_res.error_name.clone().unwrap_or(error_res.error_code),
+                        reason: Some(error_res.error_description),
+                        attempt_status: None,
+                        connector_transaction_id: None,
+                    },
+                    bluesnap::BluesnapErrors::General(error_response) => {
+                        let (error_res, attempt_status) = if res.status_code == 403
+                            && error_response.contains(BLUESNAP_TRANSACTION_NOT_FOUND)
+                        {
+                            (
+                                format!(
+                                    "{} in bluesnap dashboard",
+                                    REQUEST_TIMEOUT_PAYMENT_NOT_FOUND
+                                ),
+                                Some(enums::AttemptStatus::Failure), // when bluesnap throws 403 for payment not found, we update the payment status to failure.
+                            )
+                        } else {
+                            (error_response.clone(), None)
+                        };
+                        ErrorResponse {
+                            status_code: res.status_code,
+                            code: NO_ERROR_CODE.to_string(),
+                            message: error_response,
+                            reason: Some(error_res),
+                            attempt_status,
+                            connector_transaction_id: None,
+                        }
+                    }
                 };
-                ErrorResponse {
-                    status_code: res.status_code,
-                    code: NO_ERROR_CODE.to_string(),
-                    message: error_response,
-                    reason: Some(error_res),
-                    attempt_status,
-                    connector_transaction_id: None,
-                }
+                Ok(response_error_message)
+            }
+            Err(error_msg) => {
+                event_builder.map(|event| event.set_error(serde_json::json!({"error": res.response.escape_ascii().to_string(), "status_code": res.status_code})));
+                router_env::logger::error!(deserialization_error =? error_msg);
+                handle_json_response_deserialization_failure(res, "bluesnap")
             }
-        };
-        Ok(response_error_message)
+        }
     }
 }
 

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [x] Bugfix
- [ ] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->
The code ensures any unexpected responses from the connector are appropriately logged and handled, providing meaningful and actionable error information to the caller.

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
The Bluesnap Connector propagates errors received from its cloud service (Cloudflare). Cloudflare returns these errors in HTML format, and Bluesnap forwards them in the same HTML format. When an error is received in HTML format, the backend's deserialization fails because it expects the response to be in JSON format.

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
Unable to test 5xx error codes

Normal testing done through postman
1. Payment Connector - Create

Request - 

```
curl --location 'http://localhost:8080/account/merchant_1737978930/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "payment_processor",
    "connector_name": "bluesnap",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key":"Hyperswitch_P4yments",
        "key1":"API_16769616681841700433194"
    },
    "test_mode": false,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa",
                        "Mastercard",
                        "Interac",
                        "AmericanExpress",
                        "JCB",
                        "DinersClub",
                        "Discover",
                        "CartesBancaires",
                        "UnionPay"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "AmericanExpress",
                        "Visa",
                        "Mastercard",
                        "Discover",
                        "Interac",
                        "JCB",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "google_pay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "apple_pay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "payment_method_type": "klarna",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "affirm",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "afterpay_clearpay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245"
    },
    "connector_webhook_details": {
        "merchant_secret": "MyWebhookSecret"
    },
    "business_country": "US",
    "business_label": "default"
}'
```

Response - 

```
{
    "connector_type": "payment_processor",
    "connector_name": "bluesnap",
    "connector_label": "bluesnap_US_default",
    "merchant_connector_id": "mca_thvNFxLqnEvxlCuNYHHd",
    "profile_id": "pro_y9tlfRoNqyKFoTv0jV7q",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key": "Hy****************ts",
        "key1": "AP***********************94"
    },
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "payment_experience": null,
                    "card_networks": [
                        "Visa",
                        "Mastercard",
                        "Interac",
                        "AmericanExpress",
                        "JCB",
                        "DinersClub",
                        "Discover",
                        "CartesBancaires",
                        "UnionPay"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "payment_experience": null,
                    "card_networks": [
                        "AmericanExpress",
                        "Visa",
                        "Mastercard",
                        "Discover",
                        "Interac",
                        "JCB",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "google_pay",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "apple_pay",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "payment_method_type": "klarna",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "affirm",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "afterpay_clearpay",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "connector_webhook_details": {
        "merchant_secret": "MyWebhookSecret",
        "additional_secret": null
    },
    "metadata": {
        "city": "NY",
        "unit": "245"
    },
    "test_mode": false,
    "disabled": false,
    "frm_configs": null,
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "applepay_verified_domains": null,
    "pm_auth_config": null,
    "status": "active",
    "additional_merchant_data": null,
    "connector_wallets_details": null
}
```
2A. Payments - Create (Successful Transaction)

Request -

```
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_5KAXSZnLdrlEc2TqZsnrEfcnQqo6DfAQssC12bYyQ446NkHIfrF9eS9D5zHGcNQd' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "bluesnapsavecard_123",
    "email": "guest@example.com",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4263982640269299",
            "card_exp_month": "4",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "card_cvc": "738"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country":"US",
            "first_name": "PiX"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
```

Response - 

```
{
    "payment_id": "pay_GlBb0QHBglMPzrs7KUFH",
    "merchant_id": "merchant_1737978930",
    "status": "succeeded",
    "amount": 6540,
    "net_amount": 6540,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 6540,
    "connector": "bluesnap",
    "client_secret": "pay_GlBb0QHBglMPzrs7KUFH_secret_EjtASO8UyEF7lbwqbBp3",
    "created": "2025-01-27T12:14:05.253Z",
    "currency": "USD",
    "customer_id": "bluesnapsavecard_123",
    "customer": {
        "id": "bluesnapsavecard_123",
        "name": null,
        "email": "guest@example.com",
        "phone": null,
        "phone_country_code": null
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "9299",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "426398",
            "card_extended_bin": null,
            "card_exp_month": "4",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_Nf1u8P35zmlUmjQeySy1",
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": null,
    "phone": null,
    "return_url": "https://duck.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "bluesnapsavecard_123",
        "created_at": 1737980045,
        "expires": 1737983645,
        "secret": "epk_986f5561194a4f0099af0a64b111798c"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "1072270280",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "1072270280",
    "payment_link": null,
    "profile_id": "pro_y9tlfRoNqyKFoTv0jV7q",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_thvNFxLqnEvxlCuNYHHd",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-27T12:29:05.253Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-01-27T12:14:09.598Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}
```

2B. Payments - Create (Failed Transaction, producing error)

Request - 

```
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_5KAXSZnLdrlEc2TqZsnrEfcnQqo6DfAQssC12bYyQ446NkHIfrF9eS9D5zHGcNQd' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "bluesnapsavecard_123",
    "email": "guest@example.com",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4347699988887777",
            "card_exp_month": "1",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "card_cvc": "555"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country":"US",
            "first_name": "PiX"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
```

Response - 

```
{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "bluesnapsavecard_123",
    "email": "guest@example.com",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4347699988887777",
            "card_exp_month": "1",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "card_cvc": "555"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country":"US",
            "first_name": "PiX"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}
```
Cypress Test

<img width="842" alt="Screenshot 2025-01-30 at 13 02 43" src="https://github.com/user-attachments/assets/e81ccafb-1f51-44db-9199-d4b97405050d" />

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible


Unable to test 5xx error codes

Normal testing done through postman
1. Payment Connector - Create

Request - 

```
curl --location 'http://localhost:8080/account/merchant_1737978930/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "payment_processor",
    "connector_name": "bluesnap",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key":"Hyperswitch_P4yments",
        "key1":"API_16769616681841700433194"
    },
    "test_mode": false,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa",
                        "Mastercard",
                        "Interac",
                        "AmericanExpress",
                        "JCB",
                        "DinersClub",
                        "Discover",
                        "CartesBancaires",
                        "UnionPay"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "AmericanExpress",
                        "Visa",
                        "Mastercard",
                        "Discover",
                        "Interac",
                        "JCB",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "google_pay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "apple_pay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "payment_method_type": "klarna",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "affirm",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "afterpay_clearpay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245"
    },
    "connector_webhook_details": {
        "merchant_secret": "MyWebhookSecret"
    },
    "business_country": "US",
    "business_label": "default"
}'
```

Response - 

```
{
    "connector_type": "payment_processor",
    "connector_name": "bluesnap",
    "connector_label": "bluesnap_US_default",
    "merchant_connector_id": "mca_thvNFxLqnEvxlCuNYHHd",
    "profile_id": "pro_y9tlfRoNqyKFoTv0jV7q",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key": "Hy****************ts",
        "key1": "AP***********************94"
    },
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "payment_experience": null,
                    "card_networks": [
                        "Visa",
                        "Mastercard",
                        "Interac",
                        "AmericanExpress",
                        "JCB",
                        "DinersClub",
                        "Discover",
                        "CartesBancaires",
                        "UnionPay"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "payment_experience": null,
                    "card_networks": [
                        "AmericanExpress",
                        "Visa",
                        "Mastercard",
                        "Discover",
                        "Interac",
                        "JCB",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "google_pay",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "apple_pay",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "payment_method_type": "klarna",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "affirm",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "afterpay_clearpay",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "connector_webhook_details": {
        "merchant_secret": "MyWebhookSecret",
        "additional_secret": null
    },
    "metadata": {
        "city": "NY",
        "unit": "245"
    },
    "test_mode": false,
    "disabled": false,
    "frm_configs": null,
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "applepay_verified_domains": null,
    "pm_auth_config": null,
    "status": "active",
    "additional_merchant_data": null,
    "connector_wallets_details": null
}
```
2A. Payments - Create (Successful Transaction)

Request -

```
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_5KAXSZnLdrlEc2TqZsnrEfcnQqo6DfAQssC12bYyQ446NkHIfrF9eS9D5zHGcNQd' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "bluesnapsavecard_123",
    "email": "guest@example.com",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4263982640269299",
            "card_exp_month": "4",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "card_cvc": "738"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country":"US",
            "first_name": "PiX"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
```

Response - 

```
{
    "payment_id": "pay_GlBb0QHBglMPzrs7KUFH",
    "merchant_id": "merchant_1737978930",
    "status": "succeeded",
    "amount": 6540,
    "net_amount": 6540,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 6540,
    "connector": "bluesnap",
    "client_secret": "pay_GlBb0QHBglMPzrs7KUFH_secret_EjtASO8UyEF7lbwqbBp3",
    "created": "2025-01-27T12:14:05.253Z",
    "currency": "USD",
    "customer_id": "bluesnapsavecard_123",
    "customer": {
        "id": "bluesnapsavecard_123",
        "name": null,
        "email": "guest@example.com",
        "phone": null,
        "phone_country_code": null
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "9299",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "426398",
            "card_extended_bin": null,
            "card_exp_month": "4",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_Nf1u8P35zmlUmjQeySy1",
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": null,
    "phone": null,
    "return_url": "https://duck.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "bluesnapsavecard_123",
        "created_at": 1737980045,
        "expires": 1737983645,
        "secret": "epk_986f5561194a4f0099af0a64b111798c"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "1072270280",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "1072270280",
    "payment_link": null,
    "profile_id": "pro_y9tlfRoNqyKFoTv0jV7q",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_thvNFxLqnEvxlCuNYHHd",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-27T12:29:05.253Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-01-27T12:14:09.598Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}
```

2B. Payments - Create (Failed Transaction, producing error)

Request - 

```
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_5KAXSZnLdrlEc2TqZsnrEfcnQqo6DfAQssC12bYyQ446NkHIfrF9eS9D5zHGcNQd' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "bluesnapsavecard_123",
    "email": "guest@example.com",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4347699988887777",
            "card_exp_month": "1",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "card_cvc": "555"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country":"US",
            "first_name": "PiX"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
```

Response - 

```
{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "bluesnapsavecard_123",
    "email": "guest@example.com",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4347699988887777",
            "card_exp_month": "1",
            "card_exp_year": "26",
            "card_holder_name": "joseph Doe",
            "card_cvc": "555"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country":"US",
            "first_name": "PiX"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}
```
Cypress Test

<img width="842" alt="Screenshot 2025-01-30 at 13 02 43" src="https://github.com/user-attachments/assets/e81ccafb-1f51-44db-9199-d4b97405050d" />
