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

Code before:
                        state,
                        customer_id.clone(),
                        payment_method_status,
                        payment_method_data.clone(),
                        vault_operation,
                        payment_method_info,
                        platform,
                        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(),
                                    ),
                                })?,
                        ))
                    }

Review comment (suggestion):
Currently API model version of PaymentMethodsData are being stored. Made the domain models match the api models and moved to using domain models here. Many of these API models need to be removed. Will take up in a future PR.

Code after:
                        state,
                        customer_id.clone(),
                        payment_method_status,
                        payment_method_data.clone(),
                        vault_operation,
                        payment_method_info,
                        platform,
                        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(