Repository: juspay/hyperswitch
File: crates/router/src/core/payments/tokenization.rs (Rust)

Code before:
                        payment_method_create_request.clone(),
                        is_network_tokenization_enabled,
                        business_profile,
                    )
                    .await?
                };
                let network_token_locker_id = match network_token_resp {
                    Some(ref token_resp) => {
                        if network_token_requestor_ref_id.is_some() {
                            Some(token_resp.payment_method_id.clone())
                        } else {
                            None
                        }
                    }
                    None => None,
                };

                let optional_pm_details = match (resp.card.as_ref(), payment_method_data) {
                    (Some(card), _) => Some(domain::PaymentMethodsData::Card(
                        domain::CardDetailsPaymentMethod::from((card.clone(), co_badged_card_data)),
                    )),
                    (
                        _,
                        domain::PaymentMethodData::Wallet(domain::WalletData::ApplePay(applepay)),
                    ) => Some(domain::PaymentMethodsData::WalletDetails(
                        get_applepay_wallet_info(applepay, payment_method_token.clone()),
                    )),
                    (
                        _,
                        domain::PaymentMethodData::Wallet(domain::WalletData::GooglePay(googlepay)),
                    ) => Some(domain::PaymentMethodsData::WalletDetails(
                        get_googlepay_wallet_info(googlepay, payment_method_token),
                    )),
                    (_, domain::PaymentMethodData::BankDebit(bank_debit_data)) => {
                        Some(domain::PaymentMethodsData::BankDebit(
                            domain::AdditionalBankDebitData::try_from(bank_debit_data)
                                .change_context(errors::ApiErrorResponse::NotImplemented {
                                    message: errors::NotImplementedMessage::Reason(
                                        "payment_method_data storage is only supported for ACH"
                                            .to_string(),
                                    ),
                                })?,
                        ))
                    }
                    _ => None,
                };

                let key_manager_state = state.into();
                let pm_data_encrypted: Option<Encryptable<Secret<serde_json::Value>>> =
                    optional_pm_details
                        .async_map(|pm| {

Review comment (suggestion):
Since we are using the domain models for `WalletDetails` even the `PaymentMethodDataWalletInfo` which is the return type of `get_applepay_wallet_info`

Code after:
                        payment_method_create_request.clone(),
                        is_network_tokenization_enabled,
                        business_profile,
                    )
                    .await?
                };
                let network_token_locker_id = match network_token_resp {
                    Some(ref token_resp) => {
                        if network_token_requestor_ref_id.is_some() {
                            Some(token_resp.payment_method_id.clone())
                        } else {
                            None
                        }
                    }
                    None => None,
                };

                let optional_pm_details = match (resp.card.as_ref(), payment_method_data) {
                    (Some(card), _) => Some(domain::PaymentMethodsData::Card(
                        domain::CardDetailsPaymentMethod::from((card.clone(), co_badged_card_data)),
                    )),
                    (
                        _,
                        domain::PaymentMethodData::Wallet(domain::WalletData::ApplePay(applepay)),
                    ) => Some(domain::PaymentMethodsData::WalletDetails(
                        get_applepay_wallet_info(applepay, payment_method_token.clone()),
                    )),
                    (
                        _,
                        domain::PaymentMethodData::Wallet(domain::WalletData::GooglePay(googlepay)),
                    ) => Some(domain::PaymentMethodsData::WalletDetails(
                        get_googlepay_wallet_info(googlepay, payment_method_token),
                    )),
                    (_, domain::PaymentMethodData::BankDebit(bank_debit_data)) => bank_debit_data
                        .get_bank_debit_details()
                        .map(domain::PaymentMethodsData::BankDebit),
                    _ => None,
                };

                let key_manager_state = state.into();
                let pm_data_encrypted: Option<Encryptable<Secret<serde_json::Value>>> =
                    optional_pm_details
                        .async_map(|pm| {
                            create_encrypted_data(
                                &key_manager_state,
                                platform.get_processor().get_key_store(),
                                pm,
                            )
                        })
                        .await
                        .transpose()