text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router storage_scheme: MerchantStorageScheme, ) -> errors::CustomResult<(), errors::VaultError> { let pm_update = payment_method::PaymentMethodUpdate::MetadataUpdateAndLastUsed { metadata: pm_metadata, last_used_at: common_utils::date_time::now(), }; db.update_payment_method(&(state.into()), key_store, pm, pm_update, storage_scheme) .await .change_context(errors::VaultError::UpdateInPaymentMethodDataTableFailed)?; Ok(()) } pub async fn update_payment_method_and_last_used( state: &routes::SessionState, key_store: &domain::MerchantKeyStore, db: &dyn db::StorageInterface, pm: domain::PaymentMethod, payment_method_update: Option<Encryption>, storage_scheme: MerchantStorageScheme, card_scheme: Option<String>, ) -> errors::CustomResult<(), errors::VaultError> { let pm_update = payment_method::PaymentMethodUpdate::UpdatePaymentMethodDataAndLastUsed { payment_method_data: payment_method_update, scheme: card_scheme, last_used_at: common_utils::date_time::now(), pub async fn update_payment_method_and_last_used( state: &routes::SessionState, key_store: &domain::MerchantKeyStore, db: &dyn db::StorageInterface, pm: domain::PaymentMethod, payment_method_update: Option<Encryption>, storage_scheme: MerchantStorageScheme, card_scheme: Option<String>, ) -> errors::CustomResult<(), errors::VaultError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router }); stored_card_resp } else { Err::<T, error_stack::Report<errors::VaultError>>((errors::VaultError::ApiError).into()) .attach_printable_lazy(|| format!("Locker error response: {decrypted_payload:?}")) } } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] pub async fn update_payment_method_metadata_and_last_used( state: &routes::SessionState, key_store: &domain::MerchantKeyStore, db: &dyn db::StorageInterface, pm: domain::PaymentMethod, pm_metadata: Option<serde_json::Value>, storage_scheme: MerchantStorageScheme, ) -> errors::CustomResult<(), errors::VaultError> { let pm_update = payment_method::PaymentMethodUpdate::MetadataUpdateAndLastUsed { metadata: pm_metadata, last_used_at: common_utils::date_time::now(), }; db.update_payment_method(&(state.into()), key_store, pm, pm_update, storage_scheme) pub async fn update_payment_method_metadata_and_last_used( state: &routes::SessionState, key_store: &domain::MerchantKeyStore, db: &dyn db::StorageInterface, pm: domain::PaymentMethod, pm_metadata: Option<serde_json::Value>, storage_scheme: MerchantStorageScheme, ) -> errors::CustomResult<(), errors::VaultError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router ); }) }, &metrics::CARD_DELETE_TIME, &[], ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while deleting card from locker") } #[cfg(all(feature = "v2", feature = "customer_v2"))] pub async fn delete_card_by_locker_id( state: &routes::SessionState, id: &id_type::GlobalCustomerId, merchant_id: &id_type::MerchantId, ) -> errors::RouterResult<payment_methods::DeleteCardResp> { todo!() } #[instrument(skip_all)] pub async fn add_card_hs( state: &routes::SessionState, req: api::PaymentMethodCreate, card: &api::CardDetail, pub async fn delete_card_by_locker_id( state: &routes::SessionState, id: &id_type::GlobalCustomerId, merchant_id: &id_type::MerchantId, ) -> errors::RouterResult<payment_methods::DeleteCardResp> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router || card_updation_obj .nick_name .map(|nick_name| nick_name.expose()) .is_some_and(|new_nick_name| { existing_card_data .nick_name .map(|nick_name| nick_name.expose()) != Some(new_nick_name) }) } #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] pub fn validate_payment_method_update( _card_updation_obj: CardDetailUpdate, _existing_card_data: api::CardDetailFromLocker, ) -> bool { todo!() } // Wrapper function to switch lockers #[cfg(feature = "payouts")] pub async fn add_bank_to_locker( state: &routes::SessionState, req: api::PaymentMethodCreate, pub fn validate_payment_method_update( _card_updation_obj: CardDetailUpdate, _existing_card_data: api::CardDetailFromLocker, ) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router card.card_network .map(|card_network| card_network.to_string()) }), network_token_requestor_reference_id, network_token_locker_id, network_token_payment_method_data, ) .await } #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] #[allow(clippy::too_many_arguments)] pub async fn insert_payment_method( state: &routes::SessionState, resp: &api::PaymentMethodResponse, req: &api::PaymentMethodCreate, key_store: &domain::MerchantKeyStore, merchant_id: &id_type::MerchantId, customer_id: &id_type::CustomerId, pm_metadata: Option<serde_json::Value>, customer_acceptance: Option<serde_json::Value>, locker_id: Option<String>, connector_mandate_details: Option<serde_json::Value>, network_transaction_id: Option<String>, storage_scheme: MerchantStorageScheme, pub async fn insert_payment_method( state: &routes::SessionState, resp: &api::PaymentMethodResponse, req: &api::PaymentMethodCreate, key_store: &domain::MerchantKeyStore, merchant_id: &id_type::MerchantId, customer_id: &id_type::CustomerId, pm_metadata: Option<serde_json::Value>, customer_acceptance: Option<serde_json::Value>, locker_id: Option<String>, connector_mandate_details: Option<serde_json::Value>, network_transaction_id: Option<String>, storage_scheme: MerchantStorageScheme, payment_method_billing_address: Option<Encryption>, ) -> errors::RouterResult<domain::PaymentMethod> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router use std::{ collections::{HashMap, HashSet}, fmt::Debug, str::FromStr, }; pub fn get_card_bin_and_last4_digits_for_masked_card( masked_card_number: &str, ) -> Result<(String, String), cards::CardNumberValidationErr> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router logger::debug!("Network token added to locker failed {:?}", err); Ok(false) } } } // need to discuss regarding the migration APIs for v2 #[cfg(all( feature = "v2", feature = "payment_methods_v2", feature = "customer_v2" ))] pub async fn skip_locker_call_and_migrate_payment_method( _state: routes::SessionState, _req: &api::PaymentMethodMigrate, _merchant_id: id_type::MerchantId, _key_store: &domain::MerchantKeyStore, _merchant_account: &domain::MerchantAccount, _card: api_models::payment_methods::CardDetailFromLocker, ) -> errors::RouterResponse<api::PaymentMethodResponse> { todo!() } pub fn get_card_bin_and_last4_digits_for_masked_card( masked_card_number: &str, pub async fn skip_locker_call_and_migrate_payment_method( _state: routes::SessionState, _req: &api::PaymentMethodMigrate, _merchant_id: id_type::MerchantId, _key_store: &domain::MerchantKeyStore, _merchant_account: &domain::MerchantAccount, _card: api_models::payment_methods::CardDetailFromLocker, ) -> errors::RouterResponse<api::PaymentMethodResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router Ok(services::ApplicationResponse::Json( api::PaymentMethodMigrateResponse { payment_method_response, card_migrated: migrate_status.card_migrated, network_token_migrated: migrate_status.network_token_migrated, connector_mandate_details_migrated: migrate_status.connector_mandate_details_migrated, network_transaction_id_migrated: migrate_status.network_transaction_migrated, }, )) } #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] pub async fn migrate_payment_method( _state: routes::SessionState, _req: api::PaymentMethodMigrate, _merchant_id: &id_type::MerchantId, _merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodMigrateResponse> { todo!() } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") pub async fn migrate_payment_method( _state: routes::SessionState, _req: api::PaymentMethodMigrate, _merchant_id: &id_type::MerchantId, _merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodMigrateResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router .await } else { Err(err) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Error while finding payment method") } } } } #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] #[instrument(skip_all)] pub async fn get_or_insert_payment_method( _state: &routes::SessionState, _req: api::PaymentMethodCreate, _resp: &mut api::PaymentMethodResponse, _merchant_account: &domain::MerchantAccount, _customer_id: &id_type::CustomerId, _key_store: &domain::MerchantKeyStore, ) -> errors::RouterResult<domain::PaymentMethod> { todo!() } #[cfg(all( any(feature = "v1", feature = "v2"), pub async fn get_or_insert_payment_method( _state: &routes::SessionState, _req: api::PaymentMethodCreate, _resp: &mut api::PaymentMethodResponse, _merchant_account: &domain::MerchantAccount, _customer_id: &id_type::CustomerId, _key_store: &domain::MerchantKeyStore, ) -> errors::RouterResult<domain::PaymentMethod> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router created: Some(common_utils::date_time::now()), recurring_enabled: false, //[#219] installment_payment_enabled: false, //[#219] payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]), last_used_at: Some(common_utils::date_time::now()), client_secret: None, }; (payment_method_response, None) } #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] pub fn store_default_payment_method( _req: &api::PaymentMethodCreate, _customer_id: &id_type::CustomerId, _merchant_id: &id_type::MerchantId, ) -> ( api::PaymentMethodResponse, Option<payment_methods::DataDuplicationCheck>, ) { todo!() } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") pub fn store_default_payment_method( _req: &api::PaymentMethodCreate, _customer_id: &id_type::CustomerId, _merchant_id: &id_type::MerchantId, ) -> ( api::PaymentMethodResponse, Option<payment_methods::DataDuplicationCheck>, ) { todo!() }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router created: Some(pm.created_at), recurring_enabled: false, installment_payment_enabled: false, payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]), last_used_at: Some(pm.last_used_at), client_secret: pm.client_secret, }, )) } #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] #[instrument(skip_all)] pub async fn delete_payment_method( state: routes::SessionState, merchant_account: domain::MerchantAccount, pm_id: api::PaymentMethodId, key_store: domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodDeleteResponse> { let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let key = db .find_payment_method( &((&state).into()), &key_store, pm_id.payment_method_id.as_str(), pub async fn delete_payment_method( state: routes::SessionState, merchant_account: domain::MerchantAccount, pm_id: api::PaymentMethodId, key_store: domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodDeleteResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router payment_method: pm, connector_details: connector_details.clone(), }; Ok(Some(token_data)) } }, None => Ok(None), } } #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] pub async fn set_default_payment_method( state: &routes::SessionState, merchant_id: &id_type::MerchantId, key_store: domain::MerchantKeyStore, customer_id: &id_type::CustomerId, payment_method_id: String, storage_scheme: MerchantStorageScheme, ) -> errors::RouterResponse<api_models::payment_methods::CustomerDefaultPaymentMethodResponse> { let db = &*state.store; let key_manager_state = &state.into(); // check for the customer // TODO: customer need not be checked again here, this function can take an optional customer and check for existence of customer based on the optional value let customer = db pub async fn set_default_payment_method( state: &routes::SessionState, merchant_id: &id_type::MerchantId, key_store: domain::MerchantKeyStore, customer_id: &id_type::CustomerId, payment_method_id: String, storage_scheme: MerchantStorageScheme, ) -> errors::RouterResponse<api_models::payment_methods::CustomerDefaultPaymentMethodResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router &mut response, )) .await?; Ok(services::ApplicationResponse::Json(response)) } #[cfg(all( any(feature = "v2", feature = "v1"), not(feature = "payment_methods_v2"), not(feature = "customer_v2") ))] pub async fn get_pm_list_context( state: &routes::SessionState, payment_method: &enums::PaymentMethod, #[cfg(feature = "payouts")] key_store: &domain::MerchantKeyStore, #[cfg(not(feature = "payouts"))] _key_store: &domain::MerchantKeyStore, pm: &domain::PaymentMethod, #[cfg(feature = "payouts")] parent_payment_method_token: Option<String>, #[cfg(not(feature = "payouts"))] _parent_payment_method_token: Option<String>, is_payment_associated: bool, ) -> Result<Option<PaymentMethodListContext>, error_stack::Report<errors::ApiErrorResponse>> { let payment_method_retrieval_context = match payment_method { enums::PaymentMethod::Card => { let card_details = get_card_details_with_locker_fallback(pm, state).await?; pub async fn get_pm_list_context( state: &routes::SessionState, payment_method: &enums::PaymentMethod, #[cfg(feature = "payouts")] key_store: &domain::MerchantKeyStore, #[cfg(not(feature = "payouts"))] _key_store: &domain::MerchantKeyStore, pm: &domain::PaymentMethod, #[cfg(feature = "payouts")] parent_payment_method_token: Option<String>, #[cfg(not(feature = "payouts"))] _parent_payment_method_token: Option<String>, is_payment_associated: bool, ) -> Result<Option<PaymentMethodListContext>, error_stack::Report<errors::ApiErrorResponse>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router Ok(services::api::ApplicationResponse::Json( api::PaymentMethodResponse::foreign_from((None, res)), )) } } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] #[instrument(skip_all)] pub async fn get_client_secret_or_add_payment_method_for_migration( state: &routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, migration_status: &mut migration::RecordMigrationStatusBuilder, ) -> errors::RouterResponse<api::PaymentMethodResponse> { let merchant_id = merchant_account.get_id(); let customer_id = req.customer_id.clone().get_required_value("customer_id")?; #[cfg(not(feature = "payouts"))] let condition = req.card.is_some(); #[cfg(feature = "payouts")] pub async fn get_client_secret_or_add_payment_method_for_migration( state: &routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, migration_status: &mut migration::RecordMigrationStatusBuilder, ) -> errors::RouterResponse<api::PaymentMethodResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router } Ok(services::api::ApplicationResponse::Json( api::PaymentMethodResponse::foreign_from((Some(card), response)), )) } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2"), not(feature = "customer_v2") ))] #[allow(clippy::too_many_arguments)] pub async fn save_network_token_and_update_payment_method( state: &routes::SessionState, req: &api::PaymentMethodMigrate, key_store: &domain::MerchantKeyStore, merchant_account: &domain::MerchantAccount, network_token_data: &api_models::payment_methods::MigrateNetworkTokenData, network_token_requestor_ref_id: String, pm_id: String, ) -> errors::RouterResult<bool> { let payment_method_create_request = api::PaymentMethodCreate::get_payment_method_create_from_payment_method_migrate( network_token_data.network_token_number.clone(), req, pub async fn save_network_token_and_update_payment_method( state: &routes::SessionState, req: &api::PaymentMethodMigrate, key_store: &domain::MerchantKeyStore, merchant_account: &domain::MerchantAccount, network_token_data: &api_models::payment_methods::MigrateNetworkTokenData, network_token_requestor_ref_id: String, pm_id: String, ) -> errors::RouterResult<bool> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router saved_to_locker: false, }) } } } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2"), not(feature = "customer_v2") ))] #[allow(clippy::too_many_arguments)] pub async fn skip_locker_call_and_migrate_payment_method( state: &routes::SessionState, req: &api::PaymentMethodMigrate, merchant_id: id_type::MerchantId, key_store: &domain::MerchantKeyStore, merchant_account: &domain::MerchantAccount, card: api_models::payment_methods::CardDetailFromLocker, should_require_connector_mandate_details: bool, migration_status: &mut migration::RecordMigrationStatusBuilder, ) -> errors::RouterResponse<api::PaymentMethodResponse> { let db = &*state.store; let customer_id = req.customer_id.clone().get_required_value("customer_id")?; pub async fn skip_locker_call_and_migrate_payment_method( state: &routes::SessionState, req: &api::PaymentMethodMigrate, merchant_id: id_type::MerchantId, key_store: &domain::MerchantKeyStore, merchant_account: &domain::MerchantAccount, card: api_models::payment_methods::CardDetailFromLocker, should_require_connector_mandate_details: bool, migration_status: &mut migration::RecordMigrationStatusBuilder, ) -> errors::RouterResponse<api::PaymentMethodResponse> { {let db = &*state.store;<|fim_suffix|> <|fim_middle|> Ok(services::api::ApplicationResponse::Json( api::PaymentMethodResponse::foreign_from((Some(card), response)), ))}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router _resp: &mut api::PaymentMethodResponse, _merchant_account: &domain::MerchantAccount, _customer_id: &id_type::CustomerId, _key_store: &domain::MerchantKeyStore, ) -> errors::RouterResult<domain::PaymentMethod> { todo!() } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] pub async fn migrate_payment_method( state: routes::SessionState, req: api::PaymentMethodMigrate, merchant_id: &id_type::MerchantId, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodMigrateResponse> { let mut req = req; let card_details = &req.card.get_required_value("card")?; let card_number_validation_result = cards::CardNumber::from_str(card_details.card_number.peek()); pub async fn migrate_payment_method( state: routes::SessionState, req: api::PaymentMethodMigrate, merchant_id: &id_type::MerchantId, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodMigrateResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router use crate::{ core::payment_methods as pm_core, headers, types::payment_methods as pm_types, utils::ConnectorResponseExt, }; #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2"), not(feature = "customer_v2") ))] #[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn create_payment_method( state: &routes::SessionState, req: &api::PaymentMethodCreate, customer_id: &id_type::CustomerId, payment_method_id: &str, locker_id: Option<String>, merchant_id: &id_type::MerchantId, pm_metadata: Option<serde_json::Value>, customer_acceptance: Option<serde_json::Value>, payment_method_data: crypto::OptionalEncryptableValue, key_store: &domain::MerchantKeyStore, connector_mandate_details: Option<serde_json::Value>, status: Option<enums::PaymentMethodStatus>, pub async fn create_payment_method( state: &routes::SessionState, req: &api::PaymentMethodCreate, customer_id: &id_type::CustomerId, payment_method_id: &str, locker_id: Option<String>, merchant_id: &id_type::MerchantId, pm_metadata: Option<serde_json::Value>, customer_acceptance: Option<serde_json::Value>, payment_method_data: crypto::OptionalEncryptableValue, key_store: &domain::MerchantKeyStore, connector_mandate_details: Option<serde_json::Value>, status: Option<enums::PaymentMethodStatus>, network_transaction_id: Option<String>, storage_scheme: MerchantStorageScheme, payment_method_billing_address: crypto::OptionalEncryptableValue, card_scheme: Option<String>, network_token_requestor_reference_id: Option<String>, network_token_locker_id: Option<String>, network_token_payment_method_data: crypto::OptionalEncryptableValue, ) -> errors::CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router }; Ok(services::ApplicationResponse::Json(response)) } } } } #[cfg(all( any(feature = "v2", feature = "v1"), not(feature = "payment_methods_v2"), not(feature = "customer_v2") ))] pub async fn list_customer_payment_method( state: &routes::SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, payment_intent: Option<storage::PaymentIntent>, customer_id: &id_type::CustomerId, limit: Option<i64>, ) -> errors::RouterResponse<api::CustomerPaymentMethodsListResponse> { let db = &*state.store; let key_manager_state = &state.into(); let off_session_payment_flag = payment_intent .as_ref() .map(|pi| { pub async fn list_customer_payment_method( state: &routes::SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, payment_intent: Option<storage::PaymentIntent>, customer_id: &id_type::CustomerId, limit: Option<i64>, ) -> errors::RouterResponse<api::CustomerPaymentMethodsListResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Failed to update surcharge_applicable in Payment Intent"); } Ok(()) } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] #[allow(clippy::too_many_arguments)] pub async fn filter_payment_methods( graph: &cgraph::ConstraintGraph<dir::DirValue>, mca_id: id_type::MerchantConnectorAccountId, payment_methods: &[Secret<serde_json::Value>], req: &mut api::PaymentMethodListRequest, resp: &mut Vec<ResponsePaymentMethodIntermediate>, payment_intent: Option<&storage::PaymentIntent>, payment_attempt: Option<&storage::PaymentAttempt>, address: Option<&domain::Address>, connector: String, saved_payment_methods: &settings::EligiblePaymentMethods, ) -> errors::CustomResult<(), errors::ApiErrorResponse> { for payment_method in payment_methods.iter() { pub async fn filter_payment_methods( graph: &cgraph::ConstraintGraph<dir::DirValue>, mca_id: id_type::MerchantConnectorAccountId, payment_methods: &[Secret<serde_json::Value>], req: &mut api::PaymentMethodListRequest, resp: &mut Vec<ResponsePaymentMethodIntermediate>, payment_intent: Option<&storage::PaymentIntent>, payment_attempt: Option<&storage::PaymentAttempt>, address: Option<&domain::Address>, connector: String, saved_payment_methods: &settings::EligiblePaymentMethods, ) -> errors::CustomResult<(), errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router fn get_val(str: String, val: &serde_json::Value) -> Option<String> { str.split('.') .try_fold(val, |acc, x| acc.get(x)) .and_then(|v| v.as_str()) .map(|s| s.to_string()) } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "customer_v2"), not(feature = "payment_methods_v2") ))] pub async fn list_payment_methods( state: routes::SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, mut req: api::PaymentMethodListRequest, ) -> errors::RouterResponse<api::PaymentMethodListResponse> { let db = &*state.store; let pm_config_mapping = &state.conf.pm_filters; let key_manager_state = &(&state).into(); let payment_intent = if let Some(cs) = &req.client_secret { if cs.starts_with("pm_") { validate_payment_method_and_client_secret( &state, pub async fn list_payment_methods( state: routes::SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, mut req: api::PaymentMethodListRequest, ) -> errors::RouterResponse<api::PaymentMethodListResponse> { {let db = &*state.store;let pm_config_mapping = &state.conf.pm_filters;let key_manager_state = &(&state).into();let payment_intent = if let Some(cs) = &req.client_secret { if cs.starts_with("pm_") { validate_payment_method_and_client_secret( &state, cs, db, &merchant_account, &key_store, ) .await?; None } else { helpers::verify_payment_intent_time_and_client_secret( &state, &merchant_account, &key_store, req.client_secret.clone(), ) .await? } } else { None };let shipping_address = payment_intent .as_ref() .async_map(|pi| async { helpers::get_address_by_id( &state, pi.shipping_address_id.clone(), &key_store, &pi.payment_id, merchant_account.get_id(), merchant_account.storage_scheme, ) .await }) .await .transpose()? .flatten();<|fim_suffix|> <|fim_middle|> let merchant_surcharge_configs = if let Some((payment_attempt, payment_intent)) = payment_attempt.as_ref().zip(payment_intent) { Box::pin(call_surcharge_decision_management( state, &merchant_account, &key_store, &business_profile, payment_attempt, payment_intent, billing_address, &mut payment_method_responses, )) .await? } else { api_surcharge_decision_configs::MerchantSurchargeConfigs::default() };let collect_shipping_details_from_wallets = if business_profile .always_collect_shipping_details_from_wallet_connector .unwrap_or(false) { business_profile.always_collect_shipping_details_from_wallet_connector } else { business_profile.collect_shipping_details_from_wallet_connector };let collect_billing_details_from_wallets = if business_profile .always_collect_billing_details_from_wallet_connector .unwrap_or(false) { business_profile.always_collect_billing_details_from_wallet_connector } else { business_profile.collect_billing_details_from_wallet_connector };let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled();Ok(services::ApplicationResponse::Json( api::PaymentMethodListResponse { redirect_url: business_profile.return_url.clone(), merchant_name: merchant_account.merchant_name, payment_type, payment_methods: payment_method_responses, mandate_payment: payment_attempt.and_then(|inner| inner.mandate_details).map( |d| match d { hyperswitch_domain_models::mandates::MandateDataType::SingleUse(i) => { api::MandateType::SingleUse(api::MandateAmountData { amount: i.amount, currency: i.currency, start_date: i.start_date, end_date: i.end_date, metadata: i.metadata, }) } hyperswitch_domain_models::mandates::MandateDataType::MultiUse(Some(i)) => { api::MandateType::MultiUse(Some(api::MandateAmountData { amount: i.amount, currency: i.currency, start_date: i.start_date, end_date: i.end_date, metadata: i.metadata, })) } hyperswitch_domain_models::mandates::MandateDataType::MultiUse(None) => { api::MandateType::MultiUse(None) } }, ), show_surcharge_breakup_screen: merchant_surcharge_configs .show_surcharge_breakup_screen .unwrap_or_default(), currency, request_external_three_ds_authentication, collect_shipping_details_from_wallets, collect_billing_details_from_wallets, is_tax_calculation_enabled: is_tax_connector_enabled && !skip_external_tax_calculation, }, ))}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router network_transaction_id: Option<String>, storage_scheme: MerchantStorageScheme, payment_method_billing_address: Option<Encryption>, ) -> errors::RouterResult<domain::PaymentMethod> { todo!() } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] #[instrument(skip_all)] pub async fn update_customer_payment_method( state: routes::SessionState, merchant_account: domain::MerchantAccount, req: api::PaymentMethodUpdate, payment_method_id: &str, key_store: domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodResponse> { // Currently update is supported only for cards if let Some(card_update) = req.card.clone() { let db = state.store.as_ref(); let pm = db .find_payment_method( pub async fn update_customer_payment_method( state: routes::SessionState, merchant_account: domain::MerchantAccount, req: api::PaymentMethodUpdate, payment_method_id: &str, key_store: domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router resp.client_secret = pm.client_secret; } } Ok(services::ApplicationResponse::Json(resp)) } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] #[instrument(skip_all)] pub async fn save_migration_payment_method( state: &routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, migration_status: &mut migration::RecordMigrationStatusBuilder, ) -> errors::RouterResponse<api::PaymentMethodResponse> { req.validate()?; let db = &*state.store; let merchant_id = merchant_account.get_id(); let customer_id = req.customer_id.clone().get_required_value("customer_id")?; let payment_method = req.payment_method.get_required_value("payment_method")?; let key_manager_state = state.into(); pub async fn save_migration_payment_method( state: &routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, migration_status: &mut migration::RecordMigrationStatusBuilder, ) -> errors::RouterResponse<api::PaymentMethodResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router return Err(e.attach_printable("Failed to add card to locker")); } } } } } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] #[instrument(skip_all)] pub async fn add_payment_method( state: &routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodResponse> { req.validate()?; let db = &*state.store; let merchant_id = merchant_account.get_id(); let customer_id = req.customer_id.clone().get_required_value("customer_id")?; let payment_method = req.payment_method.get_required_value("payment_method")?; let key_manager_state = state.into(); let payment_method_billing_address: Option<Encryptable<Secret<serde_json::Value>>> = req pub async fn add_payment_method( state: &routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, ) -> errors::RouterResponse<api::PaymentMethodResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/cards.rs | crate: router let expired = current_timestamp > session_expiry; Ok(expired) } } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2"), not(feature = "customer_v2") ))] #[instrument(skip_all)] pub async fn add_payment_method_data( state: routes::SessionState, req: api::PaymentMethodCreate, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, pm_id: String, ) -> errors::RouterResponse<api::PaymentMethodResponse> { let db = &*state.store; let pmd = req .payment_method_data .clone() .get_required_value("payment_method_data")?; pub async fn add_payment_method_data( state: routes::SessionState, req: api::PaymentMethodCreate, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, pm_id: String, ) -> errors::RouterResponse<api::PaymentMethodResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use euclid::{ backend, backend::{inputs as dsl_inputs, EuclidBackend}, }; use storage_impl::redis::cache::{self, SURCHARGE_CACHE}; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; pub async fn ensure_algorithm_cached( store: &dyn StorageInterface, merchant_id: &common_utils::id_type::MerchantId, algorithm_id: &str, ) -> ConditionalConfigResult<VirInterpreterBackendCacheWrapper> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; fn get_surcharge_details_from_surcharge_output( surcharge_details: surcharge_decision_configs::SurchargeDetailsOutput, payment_attempt: &storage::PaymentAttempt, ) -> ConditionalConfigResult<types::SurchargeDetails> { { surcharge_decision_configs::SurchargeOutput::Fixed { amount } => amount,<|fim_suffix|> <|fim_middle|> surcharge_decision_configs::SurchargeOutput::Rate(percentage) => percentage .apply_and_ceil_result(payment_attempt.net_amount.get_total_amount()) .change_context(ConfigError::DslExecutionError) .attach_printable("Failed to Calculate surcharge amount by applying percentage")?, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use router_env::{instrument, logger, tracing}; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; pub async fn perform_surcharge_decision_management_for_saved_cards( state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_attempt: &storage::PaymentAttempt, payment_intent: &storage::PaymentIntent, customer_payment_method_list: &mut [api_models::payment_methods::CustomerPaymentMethod], ) -> ConditionalConfigResult<types::SurchargeMetadata> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; pub async fn perform_surcharge_decision_management_for_session_flow( state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_attempt: &storage::PaymentAttempt, payment_intent: &storage::PaymentIntent, billing_address: Option<hyperswitch_domain_models::address::Address>, payment_method_type_list: &Vec<common_enums::PaymentMethodType>, ) -> ConditionalConfigResult<types::SurchargeMetadata> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use error_stack::{self, ResultExt}; use euclid::{ backend, backend::{inputs as dsl_inputs, EuclidBackend}, }; use storage_impl::redis::cache::{self, SURCHARGE_CACHE}; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; pub fn generate_surcharge_details_and_populate_surcharge_metadata( &self, backend_input: &backend::BackendInput, payment_attempt: &storage::PaymentAttempt, surcharge_metadata_and_key: (&mut types::SurchargeMetadata, types::SurchargeKey), ) -> ConditionalConfigResult<Option<types::SurchargeDetails>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router // Ok(surcharge_metadata) // } #[cfg(feature = "v2")] fn get_surcharge_details_from_surcharge_output( _surcharge_details: surcharge_decision_configs::SurchargeDetailsOutput, _payment_attempt: &storage::PaymentAttempt, ) -> ConditionalConfigResult<types::SurchargeDetails> { todo!() } #[cfg(feature = "v1")] fn get_surcharge_details_from_surcharge_output( surcharge_details: surcharge_decision_configs::SurchargeDetailsOutput, payment_attempt: &storage::PaymentAttempt, ) -> ConditionalConfigResult<types::SurchargeDetails> { let surcharge_amount = match surcharge_details.surcharge.clone() { surcharge_decision_configs::SurchargeOutput::Fixed { amount } => amount, surcharge_decision_configs::SurchargeOutput::Rate(percentage) => percentage .apply_and_ceil_result(payment_attempt.net_amount.get_total_amount()) .change_context(ConfigError::DslExecutionError) .attach_printable("Failed to Calculate surcharge amount by applying percentage")?, }; let tax_on_surcharge_amount = surcharge_details .tax_on_surcharge fn get_surcharge_details_from_surcharge_output( surcharge_details: surcharge_decision_configs::SurchargeDetailsOutput, payment_attempt: &storage::PaymentAttempt, ) -> ConditionalConfigResult<types::SurchargeDetails> { { surcharge_decision_configs::SurchargeOutput::Fixed { amount } => { common_utils_types::Surcharge::Fixed(amount) }<|fim_suffix|> <|fim_middle|> surcharge_decision_configs::SurchargeOutput::Rate(percentage) => { common_utils_types::Surcharge::Rate(percentage) } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router None, ), ), )?; } Ok(surcharge_metadata) } #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") ))] pub async fn perform_surcharge_decision_management_for_saved_cards( state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_attempt: &storage::PaymentAttempt, payment_intent: &storage::PaymentIntent, customer_payment_method_list: &mut [api_models::payment_methods::CustomerPaymentMethod], ) -> ConditionalConfigResult<types::SurchargeMetadata> { let mut surcharge_metadata = types::SurchargeMetadata::new(payment_attempt.attempt_id.clone()); let surcharge_source = match ( payment_attempt.get_surcharge_details(), algorithm_ref.surcharge_config_algo_id, ) { (Some(request_surcharge_details), _) => { pub async fn perform_surcharge_decision_management_for_saved_cards( state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_attempt: &storage::PaymentAttempt, payment_intent: &storage::PaymentIntent, customer_payment_method_list: &mut [api_models::payment_methods::CustomerPaymentMethod], ) -> ConditionalConfigResult<types::SurchargeMetadata> { { (Some(request_surcharge_details), _) => { SurchargeSource::Predetermined(request_surcharge_details) }<|fim_suffix|> <|fim_middle|> (None, None) => return Ok(surcharge_metadata), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use euclid::{ backend, backend::{inputs as dsl_inputs, EuclidBackend}, }; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; pub fn execute_dsl_and_get_conditional_config( backend_input: dsl_inputs::BackendInput, interpreter: &backend::VirInterpreterBackend<SurchargeDecisionConfigs>, ) -> ConditionalConfigResult<SurchargeDecisionConfigs> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; fn get_surcharge_details_from_surcharge_output( _surcharge_details: surcharge_decision_configs::SurchargeDetailsOutput, _payment_attempt: &storage::PaymentAttempt, ) -> ConditionalConfigResult<types::SurchargeDetails> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; pub async fn perform_surcharge_decision_management_for_payment_method_list( _state: &SessionState, _algorithm_ref: routing::RoutingAlgorithmRef, _payment_attempt: &storage::PaymentAttempt, _payment_intent: &storage::PaymentIntent, _billing_address: Option<payments::Address>, _response_payment_method_types: &mut [api_models::payment_methods::ResponsePaymentMethodsEnabled], ) -> ConditionalConfigResult<( types::SurchargeMetadata, surcharge_decision_configs::MerchantSurchargeConfigs, )> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use euclid::{ backend, backend::{inputs as dsl_inputs, EuclidBackend}, }; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; fn try_from(value: SurchargeDecisionManagerRecord) -> Result<Self, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/surcharge_decision_configs.rs | crate: router use api_models::{ payment_methods::SurchargeDetailsResponse, payments, routing, surcharge_decision_configs::{self, SurchargeDecisionConfigs, SurchargeDecisionManagerRecord}, }; use common_utils::{ext_traits::StringExt, types as common_utils_types}; use common_utils::{ ext_traits::{OptionExt, StringExt}, types as common_utils_types, }; use router_env::{instrument, logger, tracing}; use crate::{ core::{ errors::{self, ConditionalConfigError as ConfigError}, payments::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, types, }, }, db::StorageInterface, types::{ storage::{self, payment_attempt::PaymentAttemptExt}, transformers::ForeignTryFrom, }, SessionState, }; pub async fn perform_surcharge_decision_management_for_payment_method_list( state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_attempt: &storage::PaymentAttempt, payment_intent: &storage::PaymentIntent, billing_address: Option<hyperswitch_domain_models::address::Address>, response_payment_method_types: &mut [api_models::payment_methods::ResponsePaymentMethodsEnabled], ) -> ConditionalConfigResult<( types::SurchargeMetadata, surcharge_decision_configs::MerchantSurchargeConfigs, )> { { SurchargeSource::Generate(_) => "Surcharge was calculated through surcharge rules",<|fim_suffix|> <|fim_middle|> SurchargeSource::Predetermined(_) => "Surcharge was sent in payment create request", } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use error_stack::ResultExt; use hyperswitch_domain_models::payment_method_data; use josekit::jwe; use router_env::tracing_actix_web::RequestId; use serde::{Deserialize, Serialize}; use crate::types::{payment_methods as pm_types, transformers}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; fn foreign_from( (connector_id, mandate_reference_record): ( id_type::MerchantConnectorAccountId, hyperswitch_domain_models::mandates::ConnectorTokenReferenceRecord, ), ) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use hyperswitch_domain_models::payment_method_data; use crate::types::{payment_methods as pm_types, transformers}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn generate_payment_method_session_response( payment_method_session: hyperswitch_domain_models::payment_methods::PaymentMethodSession, client_secret: Secret<String>, associated_payment: Option<api_models::payments::PaymentsResponse>, ) -> api_models::payment_methods::PaymentMethodSessionResponse { let next_action = associated_payment .as_ref() .and_then(|payment| payment.next_action.clone()); let authentication_details = associated_payment.map( |payment| api_models::payment_methods::AuthenticationDetails { status: payment.status, error: payment.error, }, ); api_models::payment_methods::PaymentMethodSessionResponse { id: payment_method_session.id, customer_id: payment_method_session.customer_id, billing: payment_method_session .billing .map(|address| address.into_inner()) .map(From::from), psp_tokenization: payment_method_session.psp_tokenization, network_tokenization: payment_method_session.network_tokenization, expires_at: payment_method_session.expires_at, client_secret, next_action, return_url: payment_method_session.return_url, associated_payment_methods: payment_method_session.associated_payment_methods, authentication_details, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use router_env::tracing_actix_web::RequestId; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_crud_locker_request( locker: &settings::Locker, path: &str, req: api::TokenizePayloadEncrypted, tenant_id: id_type::TenantId, request_id: Option<RequestId>, ) -> CustomResult<services::Request, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn get_card_detail( pm: &domain::PaymentMethod, response: Card, ) -> CustomResult<api::CardDetailFromLocker, errors::VaultError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use router_env::tracing_actix_web::RequestId; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn mk_delete_card_request_hs_by_id( jwekey: &settings::Jwekey, locker: &settings::Locker, id: &String, merchant_id: &id_type::MerchantId, card_reference: &str, tenant_id: id_type::TenantId, request_id: Option<RequestId>, ) -> CustomResult<services::Request, errors::VaultError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use router_env::tracing_actix_web::RequestId; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn mk_delete_card_request_hs( jwekey: &settings::Jwekey, locker: &settings::Locker, customer_id: &id_type::CustomerId, merchant_id: &id_type::MerchantId, card_reference: &str, tenant_id: id_type::TenantId, request_id: Option<RequestId>, ) -> CustomResult<services::Request, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use router_env::tracing_actix_web::RequestId; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn mk_get_card_request_hs( jwekey: &settings::Jwekey, locker: &settings::Locker, customer_id: &id_type::CustomerId, merchant_id: &id_type::MerchantId, card_reference: &str, locker_choice: Option<api_enums::LockerChoice>, tenant_id: id_type::TenantId, request_id: Option<RequestId>, ) -> CustomResult<services::Request, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use hyperswitch_domain_models::payment_method_data; use crate::types::{payment_methods as pm_types, transformers}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn generate_payment_method_response( payment_method: &domain::PaymentMethod, single_use_token: &Option<payment_method_data::SingleUsePaymentMethodToken>, ) -> errors::RouterResult<api::PaymentMethodResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use router_env::tracing_actix_web::RequestId; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn mk_add_locker_request_hs( jwekey: &settings::Jwekey, locker: &settings::Locker, payload: &StoreLockerReq, locker_choice: api_enums::LockerChoice, tenant_id: id_type::TenantId, request_id: Option<RequestId>, ) -> CustomResult<services::Request, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use josekit::jwe; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn mk_basilisk_req( jwekey: &settings::Jwekey, jws: &str, locker_choice: api_enums::LockerChoice, ) -> CustomResult<encryption::JweBody, errors::VaultError> { let jws_payload: Vec<&str> = jws.split('.').collect(); let generate_jws_body = |payload: Vec<&str>| -> Option<encryption::JwsBody> { Some(encryption::JwsBody { header: payload.first()?.to_string(), payload: payload.get(1)?.to_string(), signature: payload.get(2)?.to_string(), }) }; let jws_body = generate_jws_body(jws_payload).ok_or(errors::VaultError::SaveCardFailed)?; let payload = jws_body .encode_to_vec() .change_context(errors::VaultError::SaveCardFailed)?; let public_key = match locker_choice { api_enums::LockerChoice::HyperswitchCardVault => { jwekey.vault_encryption_key.peek().as_bytes() } }; let jwe_encrypted = encryption::encrypt_jwe(&payload, public_key, EncryptionAlgorithm::A256GCM, None) .await .change_context(errors::VaultError::SaveCardFailed) .attach_printable("Error on jwe encrypt")?; let jwe_payload: Vec<&str> = jwe_encrypted.split('.').collect(); let generate_jwe_body = |payload: Vec<&str>| -> Option<encryption::JweBody> { Some(encryption::JweBody { header: payload.first()?.to_string(), iv: payload.get(2)?.to_string(), encrypted_payload: payload.get(3)?.to_string(), tag: payload.get(4)?.to_string(), encrypted_key: payload.get(1)?.to_string(), }) }; let jwe_body = generate_jwe_body(jwe_payload).ok_or(errors::VaultError::SaveCardFailed)?; Ok(jwe_body) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use josekit::jwe; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn create_jwe_body_for_vault( jwekey: &settings::Jwekey, jws: &str, ) -> CustomResult<encryption::JweBody, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use josekit::jwe; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn get_decrypted_vault_response_payload( jwekey: &settings::Jwekey, jwe_body: encryption::JweBody, decryption_scheme: settings::DecryptionScheme, ) -> CustomResult<String, errors::VaultError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use josekit::jwe; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub async fn get_decrypted_response_payload( jwekey: &settings::Jwekey, jwe_body: encryption::JweBody, locker_choice: Option<api_enums::LockerChoice>, decryption_scheme: settings::DecryptionScheme, ) -> CustomResult<String, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use hyperswitch_domain_models::payment_method_data; use crate::types::{payment_methods as pm_types, transformers}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn generate_payment_method_session_response( payment_method_session: hyperswitch_domain_models::payment_methods::PaymentMethodSession, client_secret: Secret<String>, associated_payment: Option<api_models::payments::PaymentsResponse>, ) -> api_models::payment_methods::PaymentMethodSessionResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use hyperswitch_domain_models::payment_method_data; use crate::types::{payment_methods as pm_types, transformers}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; fn foreign_try_from(item: domain::PaymentMethod) -> Result<Self, Self::Error> { { api_models::payment_methods::PaymentMethodsData::Card( card_details_payment_method, ) => { let card_details = api::CardDetailFromLocker::from(card_details_payment_method); api_models::payment_methods::PaymentMethodListData::Card(card_details) }<|fim_suffix|> <|fim_middle|> api_models::payment_methods::PaymentMethodsData::WalletDetails(..) => { todo!() } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use hyperswitch_domain_models::payment_method_data; fn foreign_from(token: &payment_method_data::SingleUsePaymentMethodToken) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use crate::types::{payment_methods as pm_types, transformers}; fn foreign_from(item: api_models::payment_methods::ConnectorTokenDetails) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_card_value2( card_security_code: Option<String>, card_fingerprint: Option<String>, external_id: Option<String>, customer_id: Option<id_type::CustomerId>, payment_method_id: Option<String>, ) -> CustomResult<String, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_card_value1( card_number: cards::CardNumber, exp_year: String, exp_month: String, name_on_card: Option<String>, nickname: Option<String>, card_last_four: Option<String>, card_token: Option<String>, ) -> CustomResult<String, errors::VaultError> { let value1 = api::TokenizedCardValue1 { card_number: card_number.peek().clone(), exp_year, exp_month, name_on_card, nickname, card_last_four, card_token, }; let value1_req = value1 .encode_to_string_of_json() .change_context(errors::VaultError::FetchCardFailed)?; Ok(value1_req) }
ast_fragments
// file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn get_card_detail( _pm: &domain::PaymentMethod, response: Card, ) -> CustomResult<api::CardDetailFromLocker, errors::VaultError> { let card_number = response.card_number; let last4_digits = card_number.clone().get_last4(); //fetch form card bin let card_detail = api::CardDetailFromLocker { issuer_country: None, last4_digits: Some(last4_digits), card_number: Some(card_number), expiry_month: Some(response.card_exp_month), expiry_year: Some(response.card_exp_year), card_fingerprint: None, card_holder_name: response.name_on_card, nick_name: response.nick_name.map(Secret::new), card_isin: None, card_issuer: None, card_network: None, card_type: None, saved_to_locker: true, }; Ok(card_detail) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_delete_card_response( response: DeleteCardResponse, ) -> errors::RouterResult<DeleteCardResp> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_get_card_response(card: GetCardResponse) -> errors::RouterResult<Card> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_get_card_request( locker: &settings::Locker, locker_id: &'static str, card_id: &'static str, ) -> CustomResult<services::Request, errors::VaultError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn generate_pm_vaulting_req_from_update_request( pm_create: domain::PaymentMethodVaultingData, pm_update: api::PaymentMethodUpdateData, ) -> domain::PaymentMethodVaultingData { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_add_card_response_hs( card: api::CardDetail, card_reference: String, req: api::PaymentMethodCreate, merchant_id: &id_type::MerchantId, ) -> api::PaymentMethodResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_add_bank_response_hs( _bank: api::BankPayout, _bank_reference: String, _req: api::PaymentMethodCreate, _merchant_id: &id_type::MerchantId, ) -> api::PaymentMethodResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use common_utils::{ ext_traits::{Encode, StringExt}, id_type, pii::Email, request::RequestContent, }; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn mk_add_bank_response_hs( bank: api::BankPayout, bank_reference: String, req: api::PaymentMethodCreate, merchant_id: &id_type::MerchantId, ) -> api::PaymentMethodResponse { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn get_dotted_jws(jws: encryption::JwsBody) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use josekit::jwe; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn get_dotted_jwe(jwe: encryption::JweBody) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; pub fn update_requestor_card_reference(&mut self, card_reference: Option<String>) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/transformers.rs | crate: router use api_models::{enums as api_enums, payment_methods::Card}; use hyperswitch_domain_models::payment_method_data; use crate::types::{payment_methods as pm_types, transformers}; use crate::{ configs::settings, core::errors::{self, CustomResult}, headers, pii::{prelude::*, Secret}, services::{api as services, encryption, EncryptionAlgorithm}, types::{api, domain}, utils::OptionExt, }; fn foreign_try_from(item: domain::PaymentMethod) -> Result<Self, Self::Error> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn delete_network_token_from_tokenization_service( state: &routes::SessionState, network_token_requestor_reference_id: String, customer_id: &id_type::CustomerId, tokenization_service: &settings::NetworkTokenizationService, ) -> CustomResult<bool, errors::NetworkTokenizationError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use api_models::payment_methods as api_payment_methods; use cards::{CardNumber, NetworkToken}; use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use super::transformers::DeleteCardResp; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn delete_network_token_from_locker_and_token_service( state: &routes::SessionState, customer_id: &id_type::CustomerId, merchant_id: &id_type::MerchantId, payment_method_id: String, network_token_locker_id: Option<String>, network_token_requestor_reference_id: String, ) -> errors::RouterResult<DeleteCardResp> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use masking::{ExposeInterface, Mask, PeekInterface, Secret}; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn check_token_status_with_tokenization_service( state: &routes::SessionState, customer_id: &id_type::CustomerId, network_token_requestor_reference_id: String, tokenization_service: &settings::NetworkTokenizationService, ) -> CustomResult<(Option<Secret<String>>, Option<Secret<String>>), errors::NetworkTokenizationError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use api_models::payment_methods as api_payment_methods; use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use masking::{ExposeInterface, Mask, PeekInterface, Secret}; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn do_status_check_for_network_token( state: &routes::SessionState, payment_method_info: &domain::PaymentMethod, ) -> CustomResult<(Option<Secret<String>>, Option<Secret<String>>), errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use api_models::payment_methods as api_payment_methods; use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn get_token_from_tokenization_service( state: &routes::SessionState, network_token_requestor_ref_id: String, pm_data: &domain::PaymentMethod, ) -> errors::RouterResult<domain::NetworkTokenData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn get_network_token( state: &routes::SessionState, customer_id: &id_type::GlobalCustomerId, network_token_requestor_ref_id: String, tokenization_service: &settings::NetworkTokenizationService, ) -> CustomResult<pm_types::TokenResponse, errors::NetworkTokenizationError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn get_network_token( state: &routes::SessionState, customer_id: id_type::CustomerId, network_token_requestor_ref_id: String, tokenization_service: &settings::NetworkTokenizationService, ) -> CustomResult<pm_types::TokenResponse, errors::NetworkTokenizationError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use api_models::payment_methods as api_payment_methods; use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use error_stack::{report, ResultExt}; use hyperswitch_domain_models::payment_method_data::NetworkTokenDetails; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn make_card_network_tokenization_request( state: &routes::SessionState, card: &api_payment_methods::CardDetail, customer_id: &id_type::GlobalCustomerId, ) -> CustomResult<(NetworkTokenDetails, String), errors::NetworkTokenizationError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use masking::{ExposeInterface, Mask, PeekInterface, Secret}; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn make_card_network_tokenization_request( state: &routes::SessionState, card: &domain::CardDetail, optional_cvc: Option<Secret<String>>, customer_id: &id_type::CustomerId, ) -> CustomResult< (pm_types::CardNetworkTokenResponsePayload, Option<String>), errors::NetworkTokenizationError, > { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use api_models::payment_methods as api_payment_methods; use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn get_token_from_tokenization_service( state: &routes::SessionState, network_token_requestor_ref_id: String, pm_data: &domain::PaymentMethod, ) -> errors::RouterResult<domain::NetworkTokenData> { { api_payment_methods::PaymentMethodsData::Card(token) => { Some(api::CardDetailFromLocker::from(token)) }<|fim_suffix|> <|fim_middle|> _ => None, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use api_models::payment_methods as api_payment_methods; use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use error_stack::{report, ResultExt}; use hyperswitch_domain_models::payment_method_data::NetworkTokenDetails; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn make_card_network_tokenization_request( state: &routes::SessionState, card: &api_payment_methods::CardDetail, customer_id: &id_type::GlobalCustomerId, ) -> CustomResult<(NetworkTokenDetails, String), errors::NetworkTokenizationError> { { Some(nt_service) => Ok(nt_service.get_inner()),<|fim_suffix|> <|fim_middle|> None => Err(report!( errors::NetworkTokenizationError::NetworkTokenizationServiceNotConfigured )), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use super::transformers::DeleteCardResp; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn delete_network_token_from_locker_and_token_service( _state: &routes::SessionState, _customer_id: &id_type::GlobalCustomerId, _merchant_id: &id_type::MerchantId, _payment_method_id: String, _network_token_locker_id: Option<String>, _network_token_requestor_reference_id: String, ) -> errors::RouterResult<DeleteCardResp> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use masking::{ExposeInterface, Mask, PeekInterface, Secret}; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn check_token_status_with_tokenization_service( _state: &routes::SessionState, _customer_id: &id_type::GlobalCustomerId, _network_token_requestor_reference_id: String, _tokenization_service: &settings::NetworkTokenizationService, ) -> CustomResult<(Option<Secret<String>>, Option<Secret<String>>), errors::NetworkTokenizationError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use josekit::jwe; use masking::{ExposeInterface, Mask, PeekInterface, Secret}; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn generate_network_token( state: &routes::SessionState, payload_bytes: &[u8], customer_id: id_type::GlobalCustomerId, tokenization_service: &settings::NetworkTokenizationService, ) -> CustomResult< (pm_types::GenerateNetworkTokenResponsePayload, String), errors::NetworkTokenizationError, > { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/network_tokenization.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::{BytesExt, Encode}, id_type, metrics::utils::record_operation_time, request::RequestContent, }; use josekit::jwe; use masking::{ExposeInterface, Mask, PeekInterface, Secret}; use crate::{ core::{errors, payment_methods, payments::helpers}, headers, logger, routes::{self, metrics}, services::{self, encryption}, settings, types::{api, domain, payment_methods as pm_types}, }; pub async fn mk_tokenization_req( state: &routes::SessionState, payload_bytes: &[u8], customer_id: id_type::CustomerId, tokenization_service: &settings::NetworkTokenizationService, ) -> CustomResult< (pm_types::CardNetworkTokenResponsePayload, Option<String>), errors::NetworkTokenizationError, > { {let enc_key = tokenization_service.public_key.peek().clone();<|fim_suffix|> <|fim_middle|> Ok((cn_response.clone(), Some(cn_response.card_reference)))}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/validator.rs | crate: router use api_models::{admin, payment_methods::PaymentMethodCollectLinkRequest}; use common_utils::link_utils; use diesel_models::generic_link::PaymentMethodCollectLinkData; use masking::Secret; use crate::{ consts, core::{ errors::{self, RouterResult}, utils as core_utils, }, routes::{app::StorageInterface, SessionState}, types::domain, utils, }; pub async fn validate_request_and_initiate_payment_method_collect_link( state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &PaymentMethodCollectLinkRequest, ) -> RouterResult<PaymentMethodCollectLinkData> { {// Validate customer_id<|fim_suffix|> <|fim_middle|> Ok(PaymentMethodCollectLinkData { pm_collect_link_id: pm_collect_link_id.clone(), customer_id, link, client_secret: Secret::new(client_secret), session_expiry, ui_config: pm_collect_link_config, enabled_payment_methods: Some(enabled_payment_methods), })}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/validator.rs | crate: router use api_models::{admin, payment_methods::PaymentMethodCollectLinkRequest}; use diesel_models::generic_link::PaymentMethodCollectLinkData; use crate::{ consts, core::{ errors::{self, RouterResult}, utils as core_utils, }, routes::{app::StorageInterface, SessionState}, types::domain, utils, }; pub async fn validate_request_and_initiate_payment_method_collect_link( _state: &SessionState, _merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, _req: &PaymentMethodCollectLinkRequest, ) -> RouterResult<PaymentMethodCollectLinkData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/validator.rs | crate: router use api_models::{admin, payment_methods::PaymentMethodCollectLinkRequest}; use common_utils::link_utils; use diesel_models::generic_link::PaymentMethodCollectLinkData; use masking::Secret; use crate::{ consts, core::{ errors::{self, RouterResult}, utils as core_utils, }, routes::{app::StorageInterface, SessionState}, types::domain, utils, }; pub async fn validate_request_and_initiate_payment_method_collect_link( state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &PaymentMethodCollectLinkRequest, ) -> RouterResult<PaymentMethodCollectLinkData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router use masking::PeekInterface; use rdkafka::message::ToBytes; use crate::{ core::{errors, payment_methods::cards::migrate_payment_method}, routes, services, types::{api, domain}, }; pub fn validate_card_expiry( card_exp_month: &masking::Secret<String>, card_exp_year: &masking::Secret<String>, ) -> errors::CustomResult<(), errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router use api_models::payment_methods::{PaymentMethodMigrationResponse, PaymentMethodRecord}; use rdkafka::message::ToBytes; use crate::{ core::{errors, payment_methods::cards::migrate_payment_method}, routes, services, types::{api, domain}, }; pub async fn migrate_payment_methods( state: routes::SessionState, payment_methods: Vec<PaymentMethodRecord>, merchant_id: &common_utils::id_type::MerchantId, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, mca_id: Option<common_utils::id_type::MerchantConnectorAccountId>, ) -> errors::RouterResponse<Vec<PaymentMethodMigrationResponse>> { let mut result = Vec::new(); for record in payment_methods { let req = api::PaymentMethodMigrate::try_from(( record.clone(), merchant_id.clone(), mca_id.clone(), )) .map_err(|err| errors::ApiErrorResponse::InvalidRequestData { message: format!("error: {:?}", err), }) .attach_printable("record deserialization failed"); match req { Ok(_) => (), Err(e) => { result.push(PaymentMethodMigrationResponse::from(( Err(e.to_string()), record, ))); continue; } }; let res = migrate_payment_method( state.clone(), req?, merchant_id, merchant_account, key_store, ) .await; result.push(PaymentMethodMigrationResponse::from(( match res { Ok(services::api::ApplicationResponse::Json(response)) => Ok(response), Err(e) => Err(e.to_string()), _ => Err("Failed to migrate payment method".to_string()), }, record, ))); } Ok(services::api::ApplicationResponse::Json(result)) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router use actix_multipart::form::{bytes::Bytes, text::Text, MultipartForm}; use api_models::payment_methods::{PaymentMethodMigrationResponse, PaymentMethodRecord}; use rdkafka::message::ToBytes; use crate::{ core::{errors, payment_methods::cards::migrate_payment_method}, routes, services, types::{api, domain}, }; pub fn get_payment_method_records( form: PaymentMethodsMigrateForm, ) -> Result< ( common_utils::id_type::MerchantId, Vec<PaymentMethodRecord>, Option<common_utils::id_type::MerchantConnectorAccountId>, ), errors::ApiErrorResponse, > { { Ok(records) => { let merchant_id = form.merchant_id.clone(); let mca_id = form.merchant_connector_id.clone(); Ok((merchant_id.clone(), records, mca_id)) }<|fim_suffix|> <|fim_middle|> Err(e) => Err(errors::ApiErrorResponse::PreconditionFailed { message: e.to_string(), }), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router use api_models::payment_methods::{PaymentMethodMigrationResponse, PaymentMethodRecord}; use rdkafka::message::ToBytes; use crate::{ core::{errors, payment_methods::cards::migrate_payment_method}, routes, services, types::{api, domain}, }; pub async fn migrate_payment_methods( state: routes::SessionState, payment_methods: Vec<PaymentMethodRecord>, merchant_id: &common_utils::id_type::MerchantId, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, mca_id: Option<common_utils::id_type::MerchantConnectorAccountId>, ) -> errors::RouterResponse<Vec<PaymentMethodMigrationResponse>> { { Ok(_) => (),<|fim_suffix|> <|fim_middle|> Err(e) => { result.push(PaymentMethodMigrationResponse::from(( Err(e.to_string()), record, ))); continue; } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router pub fn build(self) -> RecordMigrationStatus { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router pub fn network_transaction_id_migrated(&mut self, network_transaction_migrated: Option<bool>) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router pub fn connector_mandate_details_migrated( &mut self, connector_mandate_details_migrated: Option<bool>, ) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router pub fn network_token_migrated(&mut self, network_token_migrated: Option<bool>) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router pub fn card_migrated(&mut self, card_migrated: bool) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router use rdkafka::message::ToBytes; use crate::{ core::{errors, payment_methods::cards::migrate_payment_method}, routes, services, types::{api, domain}, }; fn validate_card_exp_year(year: String) -> Result<(), errors::ValidationError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router use actix_multipart::form::{bytes::Bytes, text::Text, MultipartForm}; use api_models::payment_methods::{PaymentMethodMigrationResponse, PaymentMethodRecord}; use rdkafka::message::ToBytes; use crate::{ core::{errors, payment_methods::cards::migrate_payment_method}, routes, services, types::{api, domain}, }; pub fn get_payment_method_records( form: PaymentMethodsMigrateForm, ) -> Result< ( common_utils::id_type::MerchantId, Vec<PaymentMethodRecord>, Option<common_utils::id_type::MerchantConnectorAccountId>, ), errors::ApiErrorResponse, > { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/migration.rs | crate: router use api_models::payment_methods::{PaymentMethodMigrationResponse, PaymentMethodRecord}; use csv::Reader; fn parse_csv(data: &[u8]) -> csv::Result<Vec<PaymentMethodRecord>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/vault.rs | crate: router use router_env::{instrument, tracing}; use crate::{ consts, core::errors::{self, CustomResult, RouterResult}, db, logger, routes, routes::metrics, types::{ api, domain, storage::{self, enums}, }, utils::StringExt, }; pub async fn retry_delete_tokenize( db: &dyn db::StorageInterface, pm: enums::PaymentMethod, pt: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/payment_methods/vault.rs | crate: router use scheduler::{types::process_data, utils as process_tracker_utils}; use crate::{ consts, core::errors::{self, CustomResult, RouterResult}, db, logger, routes, routes::metrics, types::{ api, domain, storage::{self, enums}, }, utils::StringExt, }; use crate::{ core::payment_methods::transformers as pm_transforms, headers, services, settings, types::payment_methods as pm_types, utils::ConnectorResponseExt, }; pub async fn start_tokenize_data_workflow( state: &routes::SessionState, tokenize_tracker: &storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { { Ok(()) => { logger::info!("Card From locker deleted Successfully"); //mark task as finished db.as_scheduler() .finish_process_with_business_status( tokenize_tracker.clone(), diesel_models::process_tracker::business_status::COMPLETED_BY_PT, ) .await?; }<|fim_suffix|> <|fim_middle|> Err(err) => { logger::error!("Err: Deleting Card From Locker : {:?}", err); retry_delete_tokenize(db, delete_tokenize_data.pm, tokenize_tracker.to_owned()).await?; metrics::RETRIED_DELETE_DATA_COUNT.add(1, &[]); } } }
ast_fragments