Issue:
Bug: [REFACTOR] move repeated code to a separate function



address comments given in this pr: https://github.com/juspay/hyperswitch/pull/8616

Pull request description:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement
- [x] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->

this pr addresses the comments which is concerned about reducing repeated code by moving them into a separate function within impl block.

### 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).
-->

address comments that was given in [this](https://github.com/juspay/hyperswitch/pull/8616) pr.

closes https://github.com/juspay/hyperswitch/issues/8771

## 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)?
-->

just a minor refactor. nothing to test here. however:

- ci should pass
- tested mandates by following https://github.com/juspay/hyperswitch/pull/8616

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `just clippy && just clippy_v2`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible


Testing:


just a minor refactor. nothing to test here. however:

- ci should pass
- tested mandates by following https://github.com/juspay/hyperswitch/pull/8616

Patch:
diff --git a/crates/diesel_models/src/mandate.rs b/crates/diesel_models/src/mandate.rs
index 7ed37dc2fd6..f4c507e471d 100644
--- a/crates/diesel_models/src/mandate.rs
+++ b/crates/diesel_models/src/mandate.rs
@@ -78,10 +78,26 @@ pub struct MandateNew {
     pub customer_user_agent_extended: Option<String>,
 }
 
+impl Mandate {
+    /// Returns customer_user_agent_extended with customer_user_agent as fallback
+    pub fn get_user_agent_extended(&self) -> Option<String> {
+        self.customer_user_agent_extended
+            .clone()
+            .or_else(|| self.customer_user_agent.clone())
+    }
+}
+
 impl MandateNew {
     pub fn update_storage_scheme(&mut self, storage_scheme: MerchantStorageScheme) {
         self.updated_by = Some(storage_scheme.to_string());
     }
+
+    /// Returns customer_user_agent_extended with customer_user_agent as fallback
+    pub fn get_customer_user_agent_extended(&self) -> Option<String> {
+        self.customer_user_agent_extended
+            .clone()
+            .or_else(|| self.customer_user_agent.clone())
+    }
 }
 
 #[derive(Debug)]
@@ -238,10 +254,7 @@ impl From<&MandateNew> for Mandate {
             merchant_connector_id: mandate_new.merchant_connector_id.clone(),
             updated_by: mandate_new.updated_by.clone(),
             // Using customer_user_agent as a fallback
-            customer_user_agent_extended: mandate_new
-                .customer_user_agent_extended
-                .clone()
-                .or_else(|| mandate_new.customer_user_agent.clone()),
+            customer_user_agent_extended: mandate_new.get_customer_user_agent_extended(),
         }
     }
 }
diff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rs
index 3bd80407fc2..caae9dec68c 100644
--- a/crates/router/src/db/mandate.rs
+++ b/crates/router/src/db/mandate.rs
@@ -661,6 +661,8 @@ impl MandateInterface for MockDb {
         _storage_scheme: MerchantStorageScheme,
     ) -> CustomResult<storage_types::Mandate, errors::StorageError> {
         let mut mandates = self.mandates.lock().await;
+        let customer_user_agent_extended = mandate_new.get_customer_user_agent_extended();
+
         let mandate = storage_types::Mandate {
             mandate_id: mandate_new.mandate_id.clone(),
             customer_id: mandate_new.customer_id,
@@ -688,10 +690,7 @@ impl MandateInterface for MockDb {
             connector_mandate_ids: mandate_new.connector_mandate_ids,
             merchant_connector_id: mandate_new.merchant_connector_id,
             updated_by: mandate_new.updated_by,
-            // Using customer_user_agent as a fallback
-            customer_user_agent_extended: mandate_new
-                .customer_user_agent_extended
-                .or_else(|| mandate_new.customer_user_agent.clone()),
+            customer_user_agent_extended,
         };
         mandates.push(mandate.clone());
         Ok(mandate)
diff --git a/crates/router/src/types/api/mandates.rs b/crates/router/src/types/api/mandates.rs
index 343d6e196ba..5d39c5e1943 100644
--- a/crates/router/src/types/api/mandates.rs
+++ b/crates/router/src/types/api/mandates.rs
@@ -95,6 +95,7 @@ impl MandateResponseExt for MandateResponse {
         let payment_method_type = payment_method
             .get_payment_method_subtype()
             .map(|pmt| pmt.to_string());
+        let user_agent = mandate.get_user_agent_extended().unwrap_or_default();
         Ok(Self {
             mandate_id: mandate.mandate_id,
             customer_acceptance: Some(api::payments::CustomerAcceptance {
@@ -106,11 +107,7 @@ impl MandateResponseExt for MandateResponse {
                 accepted_at: mandate.customer_accepted_at,
                 online: Some(api::payments::OnlineMandate {
                     ip_address: mandate.customer_ip_address,
-                    // Using customer_user_agent as a fallback
-                    user_agent: mandate
-                        .customer_user_agent_extended
-                        .or(mandate.customer_user_agent)
-                        .unwrap_or_default(),
+                    user_agent,
                 }),
             }),
             card,