Bug: Nexixpay MIT fix



Nexixpay MITs are failing when created a CIT for already existing customer for which normal payment was made.
diff --git a/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs
index 2cf30de8edf..e1a5f783ffd 100644
--- a/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nexixpay/transformers.rs
@@ -39,7 +39,7 @@ use crate::{
         get_unimplemented_payment_method_error_message, to_connector_meta,
         to_connector_meta_from_secret, CardData, PaymentsAuthorizeRequestData,
         PaymentsCompleteAuthorizeRequestData, PaymentsPreProcessingRequestData,
-        PaymentsSetupMandateRequestData, RouterData as _,
+        PaymentsSetupMandateRequestData, PaymentsSyncRequestData, RouterData as _,
     },
 };
 
@@ -1081,6 +1081,19 @@ impl<F>
                     },
                     psync_flow: NexixpayPaymentIntent::Authorize
                 }));
+                let mandate_reference = if item.data.request.is_mandate_payment() {
+                    Box::new(Some(MandateReference {
+                        connector_mandate_id: item
+                            .data
+                            .connector_mandate_request_reference_id
+                            .clone(),
+                        payment_method_id: None,
+                        mandate_metadata: None,
+                        connector_mandate_request_reference_id: None,
+                    }))
+                } else {
+                    Box::new(None)
+                };
                 let status = AttemptStatus::from(response_body.operation.operation_result.clone());
                 match status {
                     AttemptStatus::Failure => {
@@ -1100,15 +1113,7 @@ impl<F>
                                 response_body.operation.order_id.clone(),
                             ),
                             redirection_data: Box::new(Some(redirection_form.clone())),
-                            mandate_reference: Box::new(Some(MandateReference {
-                                connector_mandate_id: item
-                                    .data
-                                    .connector_mandate_request_reference_id
-                                    .clone(),
-                                payment_method_id: None,
-                                mandate_metadata: None,
-                                connector_mandate_request_reference_id: None,
-                            })),
+                            mandate_reference,
                             connector_metadata,
                             network_txn_id: None,
                             connector_response_reference_id: Some(
@@ -1257,6 +1262,16 @@ impl<F>
             meta_data,
             is_auto_capture,
         })?);
+        let mandate_reference = if item.data.request.is_mandate_payment() {
+            Box::new(Some(MandateReference {
+                connector_mandate_id: item.data.connector_mandate_request_reference_id.clone(),
+                payment_method_id: None,
+                mandate_metadata: None,
+                connector_mandate_request_reference_id: None,
+            }))
+        } else {
+            Box::new(None)
+        };
         let status = if item.data.request.amount == 0
             && item.response.operation.operation_result == NexixpayPaymentStatus::Authorized
         {
@@ -1282,15 +1297,7 @@ impl<F>
                         item.response.operation.order_id.clone(),
                     ),
                     redirection_data: Box::new(None),
-                    mandate_reference: Box::new(Some(MandateReference {
-                        connector_mandate_id: item
-                            .data
-                            .connector_mandate_request_reference_id
-                            .clone(),
-                        payment_method_id: None,
-                        mandate_metadata: None,
-                        connector_mandate_request_reference_id: None,
-                    })),
+                    mandate_reference,
                     connector_metadata,
                     network_txn_id: None,
                     connector_response_reference_id: Some(item.response.operation.order_id),
@@ -1466,6 +1473,16 @@ impl<F>
         >,
     ) -> Result<Self, Self::Error> {
         let status = AttemptStatus::from(item.response.operation_result.clone());
+        let mandate_reference = if item.data.request.is_mandate_payment() {
+            Box::new(Some(MandateReference {
+                connector_mandate_id: item.data.connector_mandate_request_reference_id.clone(),
+                payment_method_id: None,
+                mandate_metadata: None,
+                connector_mandate_request_reference_id: None,
+            }))
+        } else {
+            Box::new(None)
+        };
         match status {
             AttemptStatus::Failure => {
                 let response = Err(get_error_response(
@@ -1482,15 +1499,7 @@ impl<F>
                 response: Ok(PaymentsResponseData::TransactionResponse {
                     resource_id: ResponseId::ConnectorTransactionId(item.response.order_id.clone()),
                     redirection_data: Box::new(None),
-                    mandate_reference: Box::new(Some(MandateReference {
-                        connector_mandate_id: item
-                            .data
-                            .connector_mandate_request_reference_id
-                            .clone(),
-                        payment_method_id: None,
-                        mandate_metadata: None,
-                        connector_mandate_request_reference_id: None,
-                    })),
+                    mandate_reference,
                     connector_metadata: item.data.request.connector_meta.clone(),
                     network_txn_id: None,
                     connector_response_reference_id: Some(item.response.order_id.clone()),

## 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 -->

Stop sending back mandate reference from connector response in case of non-CIT payments to avoid making connector mandate details entry in payment_methods table. This should only be done in case of CIT payments to store correct PSP token which will be used in MIT payments.

### 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).
-->

## 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)?
-->

**Step 1:** Do an on_session payment with certain customer and card details with customer acceptance.

**Step 2:** Use same customer and card details and do an off_session payment (CIT creation).

**Step 3:** Do a MIT payment.

In this case MIT should not fail.

<details>
<summary>1. Do an on_session payment with certain customer and card details with customer acceptance</summary>

### cURL Request

```bash
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh' \
--data-raw '{
    "amount": 545,
    "currency": "EUR",
    "profile_id": "pro_QEwjCvFhpcLC2azRNZEf",
    "return_url": "https://google.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": { 
        "card": {
            "card_number": "4111 1111 1111 1111",
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_cvc": "737"
        }
    },
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "setup_future_usage": "on_session", 
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "country": "BR",
            "zip": "94122",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "BR",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "order_details": [
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 3545,
            "account_name": "transaction_processing"
        }
    ],
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "128.0.0.1"
    },
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "127.0.0.1",
            "user_agent": "amet irure esse"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    },
    "payment_link": false,
    "payment_link_config": { 
        "theme": "",
        "logo": "",
        "seller_name": "",
        "sdk_layout": "",
        "display_sdk_only": false,
        "enabled_saved_payment_method": false
    },
    "payment_type": "normal", 
    "request_incremental_authorization": false,
    "merchant_order_reference_id": "test_ord",
    "session_expiry": 900    
}'
```

### Response

```json
{
    "payment_id": "pay_UJeFlJM9WMIeBvNEVd0O",
    "merchant_id": "merchant_1759144749",
    "status": "requires_customer_action",
    "amount": 545,
    "net_amount": 545,
    "shipping_cost": null,
    "amount_capturable": 545,
    "amount_received": null,
    "connector": "nexixpay",
    "client_secret": "pay_UJeFlJM9WMIeBvNEVd0O_secret_xWU3ewN9pUcuqFAMbm9Q",
    "created": "2025-09-30T09:53:19.420Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1111",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411111",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_holder_name": null,
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_EJFI1EooKy0qnkpjqk05",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_UJeFlJM9WMIeBvNEVd0O/merchant_1759144749/pay_UJeFlJM9WMIeBvNEVd0O_1"
    }
}
```

Open and complete 3DS payment

### cURL (Payments Retrieve)

```bash
curl --location 'http://localhost:8080/payments/pay_UJeFlJM9WMIeBvNEVd0O?force_sync=true&expand_captures=true&expand_attempts=true' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh'
```

### Response

```json
{
    "payment_id": "pay_UJeFlJM9WMIeBvNEVd0O",
    "merchant_id": "merchant_1759144749",
    "status": "succeeded",
    "amount": 545,
    "net_amount": 545,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 545,
    "connector": "nexixpay",
    "client_secret": "pay_UJeFlJM9WMIeBvNEVd0O_secret_xWU3ewN9pUcuqFAMbm9Q",
    "created": "2025-09-30T09:53:19.420Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "attempts": [
        {
            "attempt_id": "pay_UJeFlJM9WMIeBvNEVd0O_1",
            "status": "charged",
            "amount": 545,
            "order_tax_amount": null,
            "currency": "EUR",
            "connector": "nexixpay",
            "error_message": null,
            "payment_method": "card",
            "connector_transaction_id": "Sk6LXorxafrWXJ4eyr",
            "capture_method": "automatic",
            "authentication_type": "three_ds",
            "created_at": "2025-09-30T09:53:19.420Z",
            "modified_at": "2025-09-30T09:57:43.778Z",
            "cancellation_reason": null,
            "mandate_id": null,
            "error_code": null,
            "payment_token": "token_EJFI1EooKy0qnkpjqk05",
            "connector_metadata": {
                "psyncFlow": "Authorize",
                "cancelOperationId": null,
                "threeDSAuthResult": {
                    "authenticationValue": "AJkBAiFGcAAAAAIhl4JzdQAAAAA="
                },
                "captureOperationId": "622504582202352739",
                "threeDSAuthResponse": "notneeded",
                "authorizationOperationId": "622504582202352739"
            },
            "payment_experience": null,
            "payment_method_type": "credit",
            "reference_id": "Sk6LXorxafrWXJ4eyr",
            "unified_code": null,
            "unified_message": null,
            "client_source": null,
            "client_version": null
        }
    ],
    "payment_method_id": "pm_QfbMOx8yXdpxfniJwh53"
}
```

### Database Query

Do a DB query:

```sql
SELECT * FROM payment_methods WHERE payment_method_id = 'pm_QfbMOx8yXdpxfniJwh53';
```

**Expected Result:** `connector_mandate_details` should be null in this case.

</details>

<details>
<summary>2. Use same customer and card details and do an off_session payment (CIT creation)</summary>

### cURL Request

```bash
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh' \
--data-raw '{
    "amount": 545,
    "currency": "EUR",
    "profile_id": "pro_QEwjCvFhpcLC2azRNZEf",
    "return_url": "https://google.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": { 
        "card": {
            "card_number": "4111 1111 1111 1111",
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_cvc": "737"
        }
    },
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "setup_future_usage": "off_session", 
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "country": "BR",
            "zip": "94122",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "BR",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "order_details": [
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 3545,
            "account_name": "transaction_processing"
        }
    ],
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "128.0.0.1"
    },
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "127.0.0.1",
            "user_agent": "amet irure esse"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    },
    "payment_link": false,
    "payment_link_config": { 
        "theme": "",
        "logo": "",
        "seller_name": "",
        "sdk_layout": "",
        "display_sdk_only": false,
        "enabled_saved_payment_method": false
    },
    "payment_type": "normal", 
    "request_incremental_authorization": false,
    "merchant_order_reference_id": "test_ord",
    "session_expiry": 900   
}'
```

### Response (Payments - Retrieve)

```json
{
    "payment_id": "pay_13wFZiDN7ZUJtSx87U8Z",
    "merchant_id": "merchant_1759144749",
    "status": "succeeded",
    "amount": 545,
    "net_amount": 545,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 545,
    "connector": "nexixpay",
    "client_secret": "pay_13wFZiDN7ZUJtSx87U8Z_secret_JyWk0LkWu6tOa7mnLXUG",
    "created": "2025-09-30T10:01:01.076Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "attempts": [
        {
            "attempt_id": "pay_13wFZiDN7ZUJtSx87U8Z_1",
            "status": "charged",
            "amount": 545,
            "order_tax_amount": null,
            "currency": "EUR",
            "connector": "nexixpay",
            "error_message": null,
            "payment_method": "card",
            "connector_transaction_id": "9dHJb42gtTkDntQ7xY",
            "capture_method": "automatic",
            "authentication_type": "three_ds",
            "created_at": "2025-09-30T10:01:01.077Z",
            "modified_at": "2025-09-30T10:01:29.144Z",
            "cancellation_reason": null,
            "mandate_id": null,
            "error_code": null,
            "payment_token": "token_Ro6vBjhJSWBxtCDUjDTw",
            "connector_metadata": {
                "psyncFlow": "Authorize",
                "cancelOperationId": null,
                "threeDSAuthResult": {
                    "authenticationValue": "AAkBBgmCIQAAAAIhl4JzdQAAAAA="
                },
                "captureOperationId": "501653294486252739",
                "threeDSAuthResponse": "notneeded",
                "authorizationOperationId": "501653294486252739"
            },
            "payment_experience": null,
            "payment_method_type": "credit",
            "reference_id": "9dHJb42gtTkDntQ7xY",
            "unified_code": null,
            "unified_message": null,
            "client_source": null,
            "client_version": null
        }
    ],
    "payment_method_id": "pm_ZNF2NslDvKAFvlUG5HwO"
}
```

</details>

<details>
<summary>3. Do a MIT payment</summary>

### cURL Request

```bash
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh' \
--data '{
    "amount": 3545,
    "currency": "EUR",
    "confirm": true,
    "customer_id": "customerssh",
    "recurring_details": {
        "type": "payment_method_id",
        "data": "pm_ZNF2NslDvKAFvlUG5HwO"
    },
    "off_session": true
}'
```

### Response

```json
{
    "payment_id": "pay_ZmNL5MZQmRC6YpbLcXWk",
    "merchant_id": "merchant_1759144749",
    "status": "succeeded",
    "amount": 3545,
    "net_amount": 3545,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 3545,
    "connector": "nexixpay",
    "client_secret": "pay_ZmNL5MZQmRC6YpbLcXWk_secret_24nJQzb7Fls1clDFoMyv",
    "created": "2025-09-30T10:02:54.008Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": true,
    "capture_on": null,
    "capture_method": null,
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1111",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411111",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "customerssh@gmail.com",
    "name": "John Doe",
    "phone": "9999999999",
    "return_url": null,
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "customerssh",
        "created_at": 1759226573,
        "expires": 1759230173,
        "secret": "epk_4296651e27474ad2b0a0c3cd27f2748b"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": "mhgsAykYdVmEKMSzIL",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": null,
        "apple_pay_recurring_details": null,
        "gateway_system": "direct"
    },
    "reference_id": "mhgsAykYdVmEKMSzIL",
    "payment_link": null,
    "profile_id": "pro_QEwjCvFhpcLC2azRNZEf",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_lJPT4aN2CbXmgSAFDmCT",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-09-30T10:17:54.008Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_channel": null,
    "payment_method_id": "pm_ZNF2NslDvKAFvlUG5HwO",
    "network_transaction_id": null,
    "payment_method_status": "active",
    "updated": "2025-09-30T10:02:56.107Z",
    "split_payments": null,
    "frm_metadata": null,
    "extended_authorization_applied": null,
    "request_extended_authorization": null,
    "capture_before": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": "yjYPw5r6T7d2VgSbRf",
    "card_discovery": "manual",
    "force_3ds_challenge": false,
    "force_3ds_challenge_trigger": false,
    "issuer_error_code": null,
    "issuer_error_message": null,
    "is_iframe_redirection_enabled": null,
    "whole_connector_response": null,
    "enable_partial_authorization": null,
    "enable_overcapture": null,
    "is_overcapture_enabled": null,
    "network_details": null
}
```

</details>

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

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



**Step 1:** Do an on_session payment with certain customer and card details with customer acceptance.

**Step 2:** Use same customer and card details and do an off_session payment (CIT creation).

**Step 3:** Do a MIT payment.

In this case MIT should not fail.

<details>
<summary>1. Do an on_session payment with certain customer and card details with customer acceptance</summary>

### cURL Request

```bash
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh' \
--data-raw '{
    "amount": 545,
    "currency": "EUR",
    "profile_id": "pro_QEwjCvFhpcLC2azRNZEf",
    "return_url": "https://google.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": { 
        "card": {
            "card_number": "4111 1111 1111 1111",
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_cvc": "737"
        }
    },
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "setup_future_usage": "on_session", 
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "country": "BR",
            "zip": "94122",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "BR",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "order_details": [
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 3545,
            "account_name": "transaction_processing"
        }
    ],
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "128.0.0.1"
    },
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "127.0.0.1",
            "user_agent": "amet irure esse"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    },
    "payment_link": false,
    "payment_link_config": { 
        "theme": "",
        "logo": "",
        "seller_name": "",
        "sdk_layout": "",
        "display_sdk_only": false,
        "enabled_saved_payment_method": false
    },
    "payment_type": "normal", 
    "request_incremental_authorization": false,
    "merchant_order_reference_id": "test_ord",
    "session_expiry": 900    
}'
```

### Response

```json
{
    "payment_id": "pay_UJeFlJM9WMIeBvNEVd0O",
    "merchant_id": "merchant_1759144749",
    "status": "requires_customer_action",
    "amount": 545,
    "net_amount": 545,
    "shipping_cost": null,
    "amount_capturable": 545,
    "amount_received": null,
    "connector": "nexixpay",
    "client_secret": "pay_UJeFlJM9WMIeBvNEVd0O_secret_xWU3ewN9pUcuqFAMbm9Q",
    "created": "2025-09-30T09:53:19.420Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1111",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411111",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_holder_name": null,
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_EJFI1EooKy0qnkpjqk05",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_UJeFlJM9WMIeBvNEVd0O/merchant_1759144749/pay_UJeFlJM9WMIeBvNEVd0O_1"
    }
}
```

Open and complete 3DS payment

### cURL (Payments Retrieve)

```bash
curl --location 'http://localhost:8080/payments/pay_UJeFlJM9WMIeBvNEVd0O?force_sync=true&expand_captures=true&expand_attempts=true' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh'
```

### Response

```json
{
    "payment_id": "pay_UJeFlJM9WMIeBvNEVd0O",
    "merchant_id": "merchant_1759144749",
    "status": "succeeded",
    "amount": 545,
    "net_amount": 545,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 545,
    "connector": "nexixpay",
    "client_secret": "pay_UJeFlJM9WMIeBvNEVd0O_secret_xWU3ewN9pUcuqFAMbm9Q",
    "created": "2025-09-30T09:53:19.420Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "attempts": [
        {
            "attempt_id": "pay_UJeFlJM9WMIeBvNEVd0O_1",
            "status": "charged",
            "amount": 545,
            "order_tax_amount": null,
            "currency": "EUR",
            "connector": "nexixpay",
            "error_message": null,
            "payment_method": "card",
            "connector_transaction_id": "Sk6LXorxafrWXJ4eyr",
            "capture_method": "automatic",
            "authentication_type": "three_ds",
            "created_at": "2025-09-30T09:53:19.420Z",
            "modified_at": "2025-09-30T09:57:43.778Z",
            "cancellation_reason": null,
            "mandate_id": null,
            "error_code": null,
            "payment_token": "token_EJFI1EooKy0qnkpjqk05",
            "connector_metadata": {
                "psyncFlow": "Authorize",
                "cancelOperationId": null,
                "threeDSAuthResult": {
                    "authenticationValue": "AJkBAiFGcAAAAAIhl4JzdQAAAAA="
                },
                "captureOperationId": "622504582202352739",
                "threeDSAuthResponse": "notneeded",
                "authorizationOperationId": "622504582202352739"
            },
            "payment_experience": null,
            "payment_method_type": "credit",
            "reference_id": "Sk6LXorxafrWXJ4eyr",
            "unified_code": null,
            "unified_message": null,
            "client_source": null,
            "client_version": null
        }
    ],
    "payment_method_id": "pm_QfbMOx8yXdpxfniJwh53"
}
```

### Database Query

Do a DB query:

```sql
SELECT * FROM payment_methods WHERE payment_method_id = 'pm_QfbMOx8yXdpxfniJwh53';
```

**Expected Result:** `connector_mandate_details` should be null in this case.

</details>

<details>
<summary>2. Use same customer and card details and do an off_session payment (CIT creation)</summary>

### cURL Request

```bash
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh' \
--data-raw '{
    "amount": 545,
    "currency": "EUR",
    "profile_id": "pro_QEwjCvFhpcLC2azRNZEf",
    "return_url": "https://google.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": { 
        "card": {
            "card_number": "4111 1111 1111 1111",
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_cvc": "737"
        }
    },
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "setup_future_usage": "off_session", 
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "country": "BR",
            "zip": "94122",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "BR",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "order_details": [
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 3545,
            "account_name": "transaction_processing"
        }
    ],
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "128.0.0.1"
    },
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "127.0.0.1",
            "user_agent": "amet irure esse"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    },
    "payment_link": false,
    "payment_link_config": { 
        "theme": "",
        "logo": "",
        "seller_name": "",
        "sdk_layout": "",
        "display_sdk_only": false,
        "enabled_saved_payment_method": false
    },
    "payment_type": "normal", 
    "request_incremental_authorization": false,
    "merchant_order_reference_id": "test_ord",
    "session_expiry": 900   
}'
```

### Response (Payments - Retrieve)

```json
{
    "payment_id": "pay_13wFZiDN7ZUJtSx87U8Z",
    "merchant_id": "merchant_1759144749",
    "status": "succeeded",
    "amount": 545,
    "net_amount": 545,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 545,
    "connector": "nexixpay",
    "client_secret": "pay_13wFZiDN7ZUJtSx87U8Z_secret_JyWk0LkWu6tOa7mnLXUG",
    "created": "2025-09-30T10:01:01.076Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "attempts": [
        {
            "attempt_id": "pay_13wFZiDN7ZUJtSx87U8Z_1",
            "status": "charged",
            "amount": 545,
            "order_tax_amount": null,
            "currency": "EUR",
            "connector": "nexixpay",
            "error_message": null,
            "payment_method": "card",
            "connector_transaction_id": "9dHJb42gtTkDntQ7xY",
            "capture_method": "automatic",
            "authentication_type": "three_ds",
            "created_at": "2025-09-30T10:01:01.077Z",
            "modified_at": "2025-09-30T10:01:29.144Z",
            "cancellation_reason": null,
            "mandate_id": null,
            "error_code": null,
            "payment_token": "token_Ro6vBjhJSWBxtCDUjDTw",
            "connector_metadata": {
                "psyncFlow": "Authorize",
                "cancelOperationId": null,
                "threeDSAuthResult": {
                    "authenticationValue": "AAkBBgmCIQAAAAIhl4JzdQAAAAA="
                },
                "captureOperationId": "501653294486252739",
                "threeDSAuthResponse": "notneeded",
                "authorizationOperationId": "501653294486252739"
            },
            "payment_experience": null,
            "payment_method_type": "credit",
            "reference_id": "9dHJb42gtTkDntQ7xY",
            "unified_code": null,
            "unified_message": null,
            "client_source": null,
            "client_version": null
        }
    ],
    "payment_method_id": "pm_ZNF2NslDvKAFvlUG5HwO"
}
```

</details>

<details>
<summary>3. Do a MIT payment</summary>

### cURL Request

```bash
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_n5vnntb0V5gRjNMdwTnPXweumExJV6vYon3lVNzW2BoA3F4S4V0PXDHK3lW7gWHh' \
--data '{
    "amount": 3545,
    "currency": "EUR",
    "confirm": true,
    "customer_id": "customerssh",
    "recurring_details": {
        "type": "payment_method_id",
        "data": "pm_ZNF2NslDvKAFvlUG5HwO"
    },
    "off_session": true
}'
```

### Response

```json
{
    "payment_id": "pay_ZmNL5MZQmRC6YpbLcXWk",
    "merchant_id": "merchant_1759144749",
    "status": "succeeded",
    "amount": 3545,
    "net_amount": 3545,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 3545,
    "connector": "nexixpay",
    "client_secret": "pay_ZmNL5MZQmRC6YpbLcXWk_secret_24nJQzb7Fls1clDFoMyv",
    "created": "2025-09-30T10:02:54.008Z",
    "currency": "EUR",
    "customer_id": "customerssh",
    "customer": {
        "id": "customerssh",
        "name": "John Doe",
        "email": "customerssh@gmail.com",
        "phone": "9999999999",
        "phone_country_code": "+1"
    },
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": true,
    "capture_on": null,
    "capture_method": null,
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1111",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411111",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "customerssh@gmail.com",
    "name": "John Doe",
    "phone": "9999999999",
    "return_url": null,
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "customerssh",
        "created_at": 1759226573,
        "expires": 1759230173,
        "secret": "epk_4296651e27474ad2b0a0c3cd27f2748b"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": "mhgsAykYdVmEKMSzIL",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": {
        "redirect_response": null,
        "search_tags": null,
        "apple_pay_recurring_details": null,
        "gateway_system": "direct"
    },
    "reference_id": "mhgsAykYdVmEKMSzIL",
    "payment_link": null,
    "profile_id": "pro_QEwjCvFhpcLC2azRNZEf",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_lJPT4aN2CbXmgSAFDmCT",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-09-30T10:17:54.008Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_channel": null,
    "payment_method_id": "pm_ZNF2NslDvKAFvlUG5HwO",
    "network_transaction_id": null,
    "payment_method_status": "active",
    "updated": "2025-09-30T10:02:56.107Z",
    "split_payments": null,
    "frm_metadata": null,
    "extended_authorization_applied": null,
    "request_extended_authorization": null,
    "capture_before": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": "yjYPw5r6T7d2VgSbRf",
    "card_discovery": "manual",
    "force_3ds_challenge": false,
    "force_3ds_challenge_trigger": false,
    "issuer_error_code": null,
    "issuer_error_message": null,
    "is_iframe_redirection_enabled": null,
    "whole_connector_response": null,
    "enable_partial_authorization": null,
    "enable_overcapture": null,
    "is_overcapture_enabled": null,
    "network_details": null
}
```

</details>
