Bug: return missing required filed error when a domain is missing during apple pay session call



Reference issue for the feature https://github.com/juspay/hyperswitch/issues/5354

As described in the above issue the apple pay domain needs to be fetched dynamically by the sdk and to be sent in the session request header. When sdk fails to send which is not expected to happen, we try to get the domain that merchant has configured in the merchant connector account. Now ff merchant has not configured a domain it will result in an `InternalServerError` instead it should be missing required filed.
diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs
index cdd8452fdb3..4a1d57cda34 100644
--- a/crates/router/src/core/payments/flows/session_flow.rs
+++ b/crates/router/src/core/payments/flows/session_flow.rs
@@ -411,10 +411,8 @@ async fn create_applepay_session_token(
                             "Retry apple pay session call with the merchant configured domain {error:?}"
                         );
                         let merchant_configured_domain = merchant_configured_domain_optional
-                            .ok_or(errors::ApiErrorResponse::InternalServerError)
-                            .attach_printable(
-                                "Failed to get initiative_context for apple pay session call retry",
-                            )?;
+                            .get_required_value("apple pay domain")
+                            .attach_printable("Failed to get domain for apple pay session call")?;
                         let apple_pay_retry_session_request =
                             payment_types::ApplepaySessionRequest {
                                 initiative_context: merchant_configured_domain,
@@ -496,15 +494,16 @@ fn get_session_request_for_manual_apple_pay(
     session_token_data: payment_types::SessionTokenInfo,
     merchant_domain: Option<String>,
 ) -> RouterResult<payment_types::ApplepaySessionRequest> {
-    let initiative_context = session_token_data
-        .initiative_context
-        .ok_or(errors::ApiErrorResponse::InternalServerError)
-        .attach_printable("Failed to get initiative_context for apple pay session call")?;
+    let initiative_context = merchant_domain
+        .or_else(|| session_token_data.initiative_context.clone())
+        .get_required_value("apple pay domain")
+        .attach_printable("Failed to get domain for apple pay session call")?;
+
     Ok(payment_types::ApplepaySessionRequest {
         merchant_identifier: session_token_data.merchant_identifier.clone(),
         display_name: session_token_data.display_name.clone(),
         initiative: session_token_data.initiative.to_string(),
-        initiative_context: merchant_domain.unwrap_or(initiative_context),
+        initiative_context,
     })
 }
 


## 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 -->
Reference issue for the feature https://github.com/juspay/hyperswitch/issues/5354

As described in the above issue the apple pay domain needs to be fetched dynamically by the sdk and to be sent in the session request header. When sdk fails to send which is not expected to happen, we try to get the domain that merchant has configured in the merchant connector account. Now ff merchant has not configured a domain it will result in an `InternalServerError` instead it should be missing required filed.

### 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)?
-->
-> Create mca with apple pay enabled and metadata not containing apple pay domain
-> Create a payment with confirm false
-> Make a session call

- session call without passing domain in header
```
curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_baf0b480b51a492cb3aa58c7fae2dcc4' \
--data '{
    "payment_id": "pay_XjjNQMVggZqOVVE58zZ1",
    "wallets": [],
    "client_secret": "pay_XjjNQMVggZqOVVE58zZ1_secret_2qs22xiuLcUIyW6jHrTc"
}'
```
```
{
    "payment_id": "pay_XjjNQMVggZqOVVE58zZ1",
    "client_secret": "pay_XjjNQMVggZqOVVE58zZ1_secret_2qs22xiuLcUIyW6jHrTc",
    "session_token": [
        {
            "wallet_name": "google_pay",
            "merchant_info": {
                "merchant_name": "Stripe"
            },
            "shipping_address_required": false,
            "email_required": false,
            "shipping_address_parameters": {
                "phone_number_required": false
            },
            "allowed_payment_methods": [
                {
                    "type": "CARD",
                    "parameters": {
                        "allowed_auth_methods": [
                            "PAN_ONLY",
                            "CRYPTOGRAM_3DS"
                        ],
                        "allowed_card_networks": [
                            "AMEX",
                            "DISCOVER",
                            "INTERAC",
                            "JCB",
                            "MASTERCARD",
                            "VISA"
                        ],
                        "billing_address_required": false
                    },
                    "tokenization_specification": {
                        "type": "PAYMENT_GATEWAY",
                        "parameters": {
                            "gateway": "stripe",
                            "stripe:version": "2018-10-31",
                            "stripe:publishableKey": "pk_test_51Msk2GAGHc77EJXX78h549SX2uaOnEkUYqBfjcoD05PIpAnDkYxMn8nQ4d19im85NQuX4Z6WDyHaUw2fFTPBWsIY00Wa7oNerO"
                        }
                    }
                }
            ],
            "transaction_info": {
                "country_code": "US",
                "currency_code": "USD",
                "total_price_status": "Final",
                "total_price": "1000.00"
            },
            "delayed_session_token": false,
            "connector": "stripe",
            "sdk_next_action": {
                "next_action": "confirm"
            },
            "secrets": null
        }
    ]
}
```
<img width="1648" alt="image" src="https://github.com/user-attachments/assets/7b154ce7-b1e2-4a4f-ad29-673ee853b376">

- session call when domain is passed in the header
```
curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'x-merchant-domain: sdk-test-app.netlify.app' \
--header 'api-key: pk_dev_baf0b480b51a492cb3aa58c7fae2dcc4' \
--data '{
    "payment_id": "pay_XjjNQMVggZqOVVE58zZ1",
    "wallets": [],
    "client_secret": "pay_XjjNQMVggZqOVVE58zZ1_secret_2qs22xiuLcUIyW6jHrTc"
}'
```
```
{
    "payment_id": "pay_XjjNQMVggZqOVVE58zZ1",
    "client_secret": "pay_XjjNQMVggZqOVVE58zZ1_secret_2qs22xiuLcUIyW6jHrTc",
    "session_token": [
        {
            "wallet_name": "apple_pay",
            "session_token_data": {
                "epoch_timestamp": 1723470817764,
                "expires_at": 1723474417764,
                "merchant_session_identifier": "SSHED1FA8C99F8947C7A69F2729CF38BEAD_2101F68F6980DFE07DEFE987B1CAF2961766C119C8FDCBB33566B1A97F33C9C3",
                "nonce": "704365e7",
                "merchant_identifier": "76B79A8E91F4D365B0B636C8F75CB207D52532E82C2C085DE79D6D8135EF3813",
                "domain_name": "sdk-test-app.netlify.app",
                "display_name": "applepay",
                "signature": "308006092a864886f70d010702a0803080020101310d300b0609608648016503040201308006092a864886f70d0107010000a080308203e330820388a003020102020816634c8b0e305717300a06082a8648ce3d040302307a312e302c06035504030c254170706c65204170706c69636174696f6e20496e746567726174696f6e204341202d20473331263024060355040b0c1d4170706c652043657274696669636174696f6e20417574686f7269747931133011060355040a0c0a4170706c6520496e632e310b3009060355040613025553301e170d3234303432393137343732375a170d3239303432383137343732365a305f3125302306035504030c1c6563632d736d702d62726f6b65722d7369676e5f5543342d50524f4431143012060355040b0c0b694f532053797374656d7331133011060355040a0c0a4170706c6520496e632e310b30090603550406130255533059301306072a8648ce3d020106082a8648ce3d03010703420004c21577edebd6c7b2218f68dd7090a1218dc7b0bd6f2c283d846095d94af4a5411b83420ed811f3407e83331f1c54c3f7eb3220d6bad5d4eff49289893e7c0f13a38202113082020d300c0603551d130101ff04023000301f0603551d2304183016801423f249c44f93e4ef27e6c4f6286c3fa2bbfd2e4b304506082b0601050507010104393037303506082b060105050730018629687474703a2f2f6f6373702e6170706c652e636f6d2f6f63737030342d6170706c65616963613330323082011d0603551d2004820114308201103082010c06092a864886f7636405013081fe3081c306082b060105050702023081b60c81b352656c69616e6365206f6e207468697320636572746966696361746520627920616e7920706172747920617373756d657320616363657074616e6365206f6620746865207468656e206170706c696361626c65207374616e64617264207465726d7320616e6420636f6e646974696f6e73206f66207573652c20636572746966696361746520706f6c69637920616e642063657274696669636174696f6e2070726163746963652073746174656d656e74732e303606082b06010505070201162a687474703a2f2f7777772e6170706c652e636f6d2f6365727469666963617465617574686f726974792f30340603551d1f042d302b3029a027a0258623687474703a2f2f63726c2e6170706c652e636f6d2f6170706c6561696361332e63726c301d0603551d0e041604149457db6fd57481868989762f7e578507e79b5824300e0603551d0f0101ff040403020780300f06092a864886f76364061d04020500300a06082a8648ce3d0403020349003046022100c6f023cb2614bb303888a162983e1a93f1056f50fa78cdb9ba4ca241cc14e25e022100be3cd0dfd16247f6494475380e9d44c228a10890a3a1dc724b8b4cb8889818bc308202ee30820275a0030201020208496d2fbf3a98da97300a06082a8648ce3d0403023067311b301906035504030c124170706c6520526f6f74204341202d20473331263024060355040b0c1d4170706c652043657274696669636174696f6e20410b06092a864886f70d010701301c06092a864886f70d010905310f170d3234303831323133353333375a302806092a864886f70d010934311b3019300b0609608648016503040201a10a06082a8648ce3d040302302f06092a864886f70d0109043122042061fcb394a5ae46559a4ebd948019bddadd3f0bd590f66a3fc0ba4e90e8bb2532300a06082a8648ce3d0403020447304502200565aaf04f5fbb7da8d58fba8fd66a8d1f19f1227160d256b75e5d2c3a0e162f022100b17d0fac6b40c05f1bff0dce8b2079eb2cfb0eacfef56d2d31bbf23ffcf2a58d000000000000",
                "operational_analytics_identifier": "applepay:76B79A8E91F4D365B0B636C8F75CB207D52532E82C2C085DE79D6D8135EF3813",
                "retries": 0,
                "psp_id": "76B79A8E91F4D365B0B636C8F75CB207D52532E82C2C085DE79D6D8135EF3813"
            },
            "payment_request_data": {
                "country_code": "US",
                "currency_code": "USD",
                "total": {
                    "label": "applepay",
                    "type": "final",
                    "amount": "1000.00"
                },
                "merchant_capabilities": [
                    "supports3DS"
                ],
                "supported_networks": [
                    "visa",
                    "masterCard",
                    "amex",
                    "discover"
                ],
                "merchant_identifier": "m.checkout"
            },
            "connector": "stripe",
            "delayed_session_token": false,
            "sdk_next_action": {
                "next_action": "confirm"
            },
            "connector_reference_id": null,
            "connector_sdk_public_key": null,
            "connector_merchant_id": null
        },
        {
            "wallet_name": "google_pay",
            "merchant_info": {
                "merchant_name": "Stripe"
            },
            "shipping_address_required": false,
            "email_required": false,
            "shipping_address_parameters": {
                "phone_number_required": false
            },
            "allowed_payment_methods": [
                {
                    "type": "CARD",
                    "parameters": {
                        "allowed_auth_methods": [
                            "PAN_ONLY",
                            "CRYPTOGRAM_3DS"
                        ],
                        "allowed_card_networks": [
                            "AMEX",
                            "DISCOVER",
                            "INTERAC",
                            "JCB",
                            "MASTERCARD",
                            "VISA"
                        ],
                        "billing_address_required": false
                    },
                    "tokenization_specification": {
                        "type": "PAYMENT_GATEWAY",
                        "parameters": {
                            "gateway": "stripe",
                            "stripe:version": "2018-10-31",
                            "stripe:publishableKey": "pk_test_51MskkYxMn8nQ4d19im85NQuX4Z6WDyHaUw2fFTPBWsIY00Wa7oNerO"
                        }
                    }
                }
            ],
            "transaction_info": {
                "country_code": "US",
                "currency_code": "USD",
                "total_price_status": "Final",
                "total_price": "1000.00"
            },
            "delayed_session_token": false,
            "connector": "stripe",
            "sdk_next_action": {
                "next_action": "confirm"
            },
            "secrets": 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
