Bug: refactor: Add customer_details, billing and shipping address in Payment LIst



Add decrypted customer_details, shipping and billling address in Payment list response for Dashboard usages
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 45a6bb46385..04cf4cd5da3 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -206,7 +206,9 @@ pub struct CustomerDetails {
 }
 
 /// Details of customer attached to this payment
-#[derive(Debug, Default, serde::Serialize, Clone, ToSchema, PartialEq, Setter)]
+#[derive(
+    Debug, Default, serde::Serialize, serde::Deserialize, Clone, ToSchema, PartialEq, Setter,
+)]
 pub struct CustomerDetailsResponse {
     /// The identifier for the customer.
     #[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 9b0fee274ee..4df48806530 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -1,8 +1,8 @@
 use std::{fmt::Debug, marker::PhantomData, str::FromStr};
 
 use api_models::payments::{
-    CustomerDetailsResponse, FrmMessage, GetAddressFromPaymentMethodData, PaymentChargeRequest,
-    PaymentChargeResponse, RequestSurchargeDetails,
+    Address, CustomerDetailsResponse, FrmMessage, GetAddressFromPaymentMethodData,
+    PaymentChargeRequest, PaymentChargeResponse, RequestSurchargeDetails,
 };
 #[cfg(feature = "payouts")]
 use api_models::payouts::PayoutAttemptResponse;
@@ -1036,7 +1036,7 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay
             description: pi.description,
             metadata: pi.metadata,
             order_details: pi.order_details,
-            customer_id: pi.customer_id,
+            customer_id: pi.customer_id.clone(),
             connector: pa.connector,
             payment_method: pa.payment_method,
             payment_method_type: pa.payment_method_type,
@@ -1060,6 +1060,40 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay
                 }
             }),
             merchant_order_reference_id: pi.merchant_order_reference_id,
+            customer: pi.customer_details.and_then(|customer_details|
+                match customer_details.into_inner().expose().parse_value::<CustomerData>("CustomerData"){
+                    Ok(parsed_data) => Some(
+                        CustomerDetailsResponse {
+                            id: pi.customer_id,
+                            name: parsed_data.name,
+                            phone: parsed_data.phone,
+                            email: parsed_data.email,
+                            phone_country_code:parsed_data.phone_country_code
+                    }),
+                    Err(e) => {
+                        router_env::logger::error!("Failed to parse 'CustomerDetailsResponse' from payment method data. Error: {e:?}");
+                        None
+                    }
+                }
+            ),
+            billing: pi.billing_details.and_then(|billing_details|
+                match billing_details.into_inner().expose().parse_value::<Address>("Address") {
+                    Ok(parsed_data) => Some(parsed_data),
+                    Err(e) => {
+                        router_env::logger::error!("Failed to parse 'BillingAddress' from payment method data. Error: {e:?}");
+                        None
+                    }
+                }
+            ),
+            shipping: pi.shipping_details.and_then(|shipping_details|
+                match shipping_details.into_inner().expose().parse_value::<Address>("Address") {
+                    Ok(parsed_data) => Some(parsed_data),
+                    Err(e) => {
+                        router_env::logger::error!("Failed to parse 'ShippingAddress' from payment method data. Error: {e:?}");
+                        None
+                    }
+                }
+            ),
             ..Default::default()
         }
     }

## 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 adds the decrypted customer_details, shipping and billling address in Payment list response.

### 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).
-->
Required for our Dashboard

## 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)?
-->
We need to make a payment with shipping, billing and customer details and then hit the Payment list api:
```
curl --location --request GET 'http://127.0.0.1:8080/payments/list' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'api-key:xxxxxxx' \
--data '{
}'
```

The response should contain the below fields:
```
   "customer_id": "uiuiuiui",
    "customer": {
        "id": "uiuiuiui",
        "name": null,
        "email": "guest@ehjhjxample.com",
        "phone": null,
        "phone_country_code": null
    },
 "shipping": {
        "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": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "NL",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "example@example.com"
    },
```

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