Bug: [BUG] [AUTHORIZEDOTNET] REF_ID should only allow strings which have less than 20 charcaters



### Bug Description

The ref_id field being passed in connector contains connector_request_reference_id. The max number of characters allowed in ref_id is 20 while the current implementation allows it to be more than 20 characters which results in the payment getting failed at the connector end.

### Expected Behavior

REF_ID should not be passed if `connector_request_reference_id` is greater than 20 characters.

### Actual Behavior

REF_ID is passed even if `connector_request_reference_id` is greater than 20 characters.

### Steps To Reproduce

Provide an unambiguous set of steps to reproduce this bug. Include code or configuration to reproduce, if relevant.
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'


### Context For The Bug

_No response_

### Environment

Are you using hyperswitch hosted version? Yes/No
If yes, please provide the value of the `x-request-id` response header to help us debug your issue.

If not (or if building/running locally), please provide the following details:
1. Operating System or Linux distribution:
2. Rust version (output of `rustc --version`): ``
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/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rs
index ba232c01bbf..0aba48fa5e5 100644
--- a/crates/router/src/connector/authorizedotnet.rs
+++ b/crates/router/src/connector/authorizedotnet.rs
@@ -9,7 +9,10 @@ use transformers as authorizedotnet;
 
 use crate::{
     configs::settings,
-    connector::utils as connector_utils,
+    connector::{
+        utils as connector_utils,
+        utils::{PaymentsAuthorizeRequestData, PaymentsCompleteAuthorizeRequestData},
+    },
     consts,
     core::{
         errors::{self, CustomResult},
@@ -216,11 +219,14 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
         event_builder.map(|i| i.set_response_body(&response));
         router_env::logger::info!(connector_response=?response);
 
-        types::RouterData::try_from(types::ResponseRouterData {
-            response,
-            data: data.clone(),
-            http_code: res.status_code,
-        })
+        types::RouterData::try_from((
+            types::ResponseRouterData {
+                response,
+                data: data.clone(),
+                http_code: res.status_code,
+            },
+            true,
+        ))
     }
 
     fn get_error_response(
@@ -405,11 +411,14 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
         event_builder.map(|i| i.set_response_body(&response));
         router_env::logger::info!(connector_response=?response);
 
-        types::RouterData::try_from(types::ResponseRouterData {
-            response,
-            data: data.clone(),
-            http_code: res.status_code,
-        })
+        types::RouterData::try_from((
+            types::ResponseRouterData {
+                response,
+                data: data.clone(),
+                http_code: res.status_code,
+            },
+            data.request.is_auto_capture()?,
+        ))
     }
 
     fn get_error_response(
@@ -783,11 +792,14 @@ impl
             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
         event_builder.map(|i| i.set_response_body(&response));
         router_env::logger::info!(connector_response=?response);
-        types::RouterData::try_from(types::ResponseRouterData {
-            response,
-            data: data.clone(),
-            http_code: res.status_code,
-        })
+        types::RouterData::try_from((
+            types::ResponseRouterData {
+                response,
+                data: data.clone(),
+                http_code: res.status_code,
+            },
+            data.request.is_auto_capture()?,
+        ))
     }
 
     fn get_error_response(
diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs
index eb5f13881fb..e2718d1ac91 100644
--- a/crates/router/src/connector/authorizedotnet/transformers.rs
+++ b/crates/router/src/connector/authorizedotnet/transformers.rs
@@ -10,7 +10,7 @@ use crate::{
     connector::utils::{self, CardData, PaymentsSyncRequestData, RefundsRequestData, WalletData},
     core::errors,
     services,
-    types::{self, api, storage::enums},
+    types::{self, api, storage::enums, transformers::ForeignFrom},
     utils::OptionExt,
 };
 
@@ -258,8 +258,8 @@ struct TransactionVoidOrCaptureRequest {
 #[serde(rename_all = "camelCase")]
 pub struct AuthorizedotnetPaymentsRequest {
     merchant_authentication: AuthorizedotnetAuthType,
+    ref_id: Option<String>,
     transaction_request: TransactionRequest,
-    ref_id: String,
 }
 
 #[derive(Debug, Serialize)]
@@ -326,12 +326,16 @@ impl TryFrom<&AuthorizedotnetRouterData<&types::PaymentsAuthorizeRouterData>>
 
         let merchant_authentication =
             AuthorizedotnetAuthType::try_from(&item.router_data.connector_auth_type)?;
-
+        let ref_id = if item.router_data.connector_request_reference_id.len() <= 20 {
+            Some(item.router_data.connector_request_reference_id.clone())
+        } else {
+            None
+        };
         Ok(Self {
             create_transaction_request: AuthorizedotnetPaymentsRequest {
                 merchant_authentication,
+                ref_id,
                 transaction_request,
-                ref_id: item.router_data.connector_request_reference_id.clone(),
             },
         })
     }
@@ -413,10 +417,16 @@ pub enum AuthorizedotnetRefundStatus {
     HeldForReview,
 }
 
-impl From<AuthorizedotnetPaymentStatus> for enums::AttemptStatus {
-    fn from(item: AuthorizedotnetPaymentStatus) -> Self {
+impl ForeignFrom<(AuthorizedotnetPaymentStatus, bool)> for enums::AttemptStatus {
+    fn foreign_from((item, auto_capture): (AuthorizedotnetPaymentStatus, bool)) -> Self {
         match item {
-            AuthorizedotnetPaymentStatus::Approved => Self::Pending,
+            AuthorizedotnetPaymentStatus::Approved => {
+                if auto_capture {
+                    Self::Charged
+                } else {
+                    Self::Authorized
+                }
+            }
             AuthorizedotnetPaymentStatus::Declined | AuthorizedotnetPaymentStatus::Error => {
                 Self::Failure
             }
@@ -536,35 +546,44 @@ pub enum AuthorizedotnetVoidStatus {
 impl From<AuthorizedotnetVoidStatus> for enums::AttemptStatus {
     fn from(item: AuthorizedotnetVoidStatus) -> Self {
         match item {
-            AuthorizedotnetVoidStatus::Approved => Self::VoidInitiated,
-            AuthorizedotnetVoidStatus::Declined | AuthorizedotnetVoidStatus::Error => Self::Failure,
-            AuthorizedotnetVoidStatus::HeldForReview => Self::Pending,
+            AuthorizedotnetVoidStatus::Approved => Self::Voided,
+            AuthorizedotnetVoidStatus::Declined | AuthorizedotnetVoidStatus::Error => {
+                Self::VoidFailed
+            }
+            AuthorizedotnetVoidStatus::HeldForReview => Self::VoidInitiated,
         }
     }
 }
 
 impl<F, T>
-    TryFrom<
+    TryFrom<(
         types::ResponseRouterData<
             F,
             AuthorizedotnetPaymentsResponse,
             T,
             types::PaymentsResponseData,
         >,
-    > for types::RouterData<F, T, types::PaymentsResponseData>
+        bool,
+    )> for types::RouterData<F, T, types::PaymentsResponseData>
 {
     type Error = error_stack::Report<errors::ConnectorError>;
     fn try_from(
-        item: types::ResponseRouterData<
-            F,
-            AuthorizedotnetPaymentsResponse,
-            T,
-            types::PaymentsResponseData,
-        >,
+        (item, is_auto_capture): (
+            types::ResponseRouterData<
+                F,
+                AuthorizedotnetPaymentsResponse,
+                T,
+                types::PaymentsResponseData,
+            >,
+            bool,
+        ),
     ) -> Result<Self, Self::Error> {
         match &item.response.transaction_response {
             Some(TransactionResponse::AuthorizedotnetTransactionResponse(transaction_response)) => {
-                let status = enums::AttemptStatus::from(transaction_response.response_code.clone());
+                let status = enums::AttemptStatus::foreign_from((
+                    transaction_response.response_code.clone(),
+                    is_auto_capture,
+                ));
                 let error = transaction_response.errors.as_ref().and_then(|errors| {
                     errors.iter().next().map(|error| types::ErrorResponse {
                         code: error.error_code.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 -->

- The status mapping for connector `Authorizdotnet` is fixed.
- The `ref_id` field being passed in connector contains `connector_request_reference_id`. The max number of characters allowed in ref_id is 20 and hence a check has been added to only pass ref_id if connector_request_reference_id contains `less than or equal to` 20 characters.

### 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).
-->
https://github.com/juspay/hyperswitch/issues/3846
https://github.com/juspay/hyperswitch/issues/3847

## 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)?
-->
Following flows should be tested for connector Authorizdotnet:

1. Authorization(Auto Capture):
```
{
    "payment_id": "abcd1",
    "amount": 800,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "StripeCustomer",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    }
}
```
NOTE: Try passing the above curl without payment_id also.
Response: 
```
{
    "payment_id": "abcd1",
    "merchant_id": "merchant_1708944265",
    "status": "succeeded",
    "amount": 800,
    "net_amount": 800,
    "amount_capturable": 0,
    "amount_received": 800,
    "connector": "authorizedotnet",
    "client_secret": "abcd1_secret_eiryjwdDZgV6IFO8TeEu",
    "created": "2024-02-27T13:19:55.615Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "description": null,
    "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": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": "42424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe"
        }
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "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": "StripeCustomer",
        "created_at": 1709039995,
        "expires": 1709043595,
        "secret": "epk_d639baf128604e01adc764d9d48437c6"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "80015300949",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "80015300949",
    "payment_link": null,
    "profile_id": "pro_9LdgkmKiHJ2dR3oUn5Ow",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_HDQdFPQctm5R737tT7qf",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "expires_on": "2024-02-27T13:34:55.615Z",
    "fingerprint": null
}
```

2. Authorization(Manual Capture):
```
{
    "payment_id": "1ss",
    "amount": 800,
    "currency": "USD",
    "confirm": true,
    "capture_method": "manual",
    "customer_id": "StripeCustomer",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    }
}
```
NOTE: Try passing the above curl without payment_id also.
Response: 
```
{
    "payment_id": "1ss",
    "merchant_id": "merchant_1708944265",
    "status": "requires_capture",
    "amount": 1200,
    "net_amount": 1200,
    "amount_capturable": 1200,
    "amount_received": null,
    "connector": "authorizedotnet",
    "client_secret": "1ss_secret_4DnENIEpIUKKKnoKKElP",
    "created": "2024-02-27T13:20:40.683Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "manual",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": "42424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe"
        }
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "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": "StripeCustomer",
        "created_at": 1709040040,
        "expires": 1709043640,
        "secret": "epk_a94c6c4d1e594998a168081802130610"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "80015300969",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "80015300969",
    "payment_link": null,
    "profile_id": "pro_9LdgkmKiHJ2dR3oUn5Ow",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_HDQdFPQctm5R737tT7qf",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "expires_on": "2024-02-27T13:35:40.683Z",
    "fingerprint": null
}
```

3. Capture:
```
curl --location 'http://localhost:8080/payments/1ss/capture' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: API_KEY_HERE' \
--data '{}'
```
Response:  
```
{
    "payment_id": "1ss",
    "merchant_id": "merchant_1708944265",
    "status": "succeeded",
    "amount": 1200,
    "net_amount": 1200,
    "amount_capturable": 0,
    "amount_received": 1200,
    "connector": "authorizedotnet",
    "client_secret": "1ss_secret_4DnENIEpIUKKKnoKKElP",
    "created": "2024-02-27T13:20:40.683Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "manual",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": "42424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe"
        }
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "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": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "80015300969",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "80015300969",
    "payment_link": null,
    "profile_id": "pro_9LdgkmKiHJ2dR3oUn5Ow",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_HDQdFPQctm5R737tT7qf",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "expires_on": "2024-02-27T13:35:40.683Z",
    "fingerprint": null
}
```
4. Void:
```
curl --location 'http://localhost:8080/payments/1s2/cancel' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: API_KEY_HERE' \
--data '{}'
```
Response: 
```
{
    "payment_id": "1s2",
    "merchant_id": "merchant_1708944265",
    "status": "cancelled",
    "amount": 120,
    "net_amount": 120,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": "authorizedotnet",
    "client_secret": "1s2_secret_f0Q0ROMla0buxvBmaqR9",
    "created": "2024-02-27T13:22:23.892Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "manual",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": "42424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe"
        }
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "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": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "80015301006",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "80015301006",
    "payment_link": null,
    "profile_id": "pro_9LdgkmKiHJ2dR3oUn5Ow",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_HDQdFPQctm5R737tT7qf",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "expires_on": "2024-02-27T13:37:23.892Z",
    "fingerprint": null
}
```

## 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
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
