id
stringlengths
11
116
type
stringclasses
1 value
granularity
stringclasses
4 values
content
stringlengths
16
477k
metadata
dict
fn_clm_router_validate_request_419988890593240561
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_status // Implementation of PaymentStatus for ValidateRequest<F, api::PaymentsRetrieveRequest, PaymentData<F>> fn validate_request<'b>( &'b self, request: &api::PaymentsRetrieveRequest, merchant_context: &domain::MerchantContext, ) -> RouterResult<( PaymentStatusOperation<'b, F, api::PaymentsRetrieveRequest>, operations::ValidateResult, )> { let request_merchant_id = request.merchant_id.as_ref(); helpers::validate_merchant_id( merchant_context.get_merchant_account().get_id(), request_merchant_id, ) .change_context(errors::ApiErrorResponse::InvalidDataFormat { field_name: "merchant_id".to_string(), expected_format: "merchant_id from merchant account".to_string(), })?; Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: request.resource_id.clone(), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 58, "total_crates": null }
fn_clm_router_to_update_tracker_419988890593240561
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_status // Implementation of None for Operation<F, api::PaymentsRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> + Send + Sync)> { Ok(*self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_get_trackers_3155168946632181718
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/tax_calculation // Implementation of PaymentSessionUpdate for GetTracker<F, PaymentData<F>, api::PaymentsDynamicTaxCalculationRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsDynamicTaxCalculationRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse< 'a, F, api::PaymentsDynamicTaxCalculationRequest, PaymentData<F>, >, > { let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; let db = &*state.store; let key_manager_state: &KeyManagerState = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_payment_id_merchant_id( &state.into(), &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // TODO (#7195): Add platform merchant account validation once publishable key auth is solved helpers::validate_payment_status_against_not_allowed_statuses( payment_intent.status, &[ storage_enums::IntentStatus::Failed, storage_enums::IntentStatus::Succeeded, ], "create a session update for", )?; helpers::authenticate_client_secret(Some(request.client_secret.peek()), &payment_intent)?; let mut payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, payment_intent.active_attempt.get_id().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let currency = payment_intent.currency.get_required_value("currency")?; let amount = payment_attempt.get_total_amount().into(); payment_attempt.payment_method_type = Some(request.payment_method_type); let shipping_address = helpers::get_address_by_id( state, payment_intent.shipping_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let tax_data = payments::TaxData { shipping_details: request.shipping.clone().into(), payment_method_type: request.payment_method_type, }; let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: None, mandate_id: None, mandate_connector: None, customer_acceptance: None, token: None, token_data: None, setup_mandate: None, address: payments::PaymentAddress::new( shipping_address.as_ref().map(From::from), None, None, business_profile.use_billing_as_payment_method_billing, ), confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: Some(tax_data), session_id: request.session_id.clone(), service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: None, payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 121, "total_crates": null }
fn_clm_router_update_trackers_3155168946632181718
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/tax_calculation // Implementation of PaymentSessionUpdate for UpdateTracker<F, PaymentData<F>, api::PaymentsDynamicTaxCalculationRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData<F>, _customer: Option<domain::Customer>, storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentSessionUpdateOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { // For Google Pay and Apple Pay, we don’t need to call the connector again; we can directly confirm the payment after tax_calculation. So, we update the required fields in the database during the update_tracker call. if payment_data.should_update_in_update_tracker() { let shipping_address = payment_data .tax_data .clone() .map(|tax_data| tax_data.shipping_details); let key_manager_state = state.into(); let shipping_details = shipping_address .clone() .async_map(|shipping_details| { create_encrypted_data(&key_manager_state, key_store, shipping_details) }) .await .transpose() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Unable to encrypt shipping details")?; let shipping_address = helpers::create_or_update_address_for_payment_by_request( state, shipping_address.map(From::from).as_ref(), payment_data.payment_intent.shipping_address_id.as_deref(), &payment_data.payment_intent.merchant_id, payment_data.payment_intent.customer_id.as_ref(), key_store, &payment_data.payment_intent.payment_id, storage_scheme, ) .await?; let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::SessionResponseUpdate { tax_details: payment_data.payment_intent.tax_details.clone().ok_or(errors::ApiErrorResponse::InternalServerError).attach_printable("payment_intent.tax_details not found")?, shipping_address_id: shipping_address.map(|address| address.address_id), updated_by: payment_data.payment_intent.updated_by.clone(), shipping_details, }; let db = &*state.store; let payment_intent = payment_data.payment_intent.clone(); let updated_payment_intent = db .update_payment_intent( &state.into(), payment_intent, payment_intent_update, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; payment_data.payment_intent = updated_payment_intent; Ok((Box::new(self), payment_data)) } else { Ok((Box::new(self), payment_data)) } } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 115, "total_crates": null }
fn_clm_router_payments_dynamic_tax_calculation_3155168946632181718
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/tax_calculation // Implementation of PaymentSessionUpdate for Domain<F, api::PaymentsDynamicTaxCalculationRequest, PaymentData<F>> async fn payments_dynamic_tax_calculation<'a>( &'a self, state: &SessionState, payment_data: &mut PaymentData<F>, _connector_call_type: &ConnectorCallType, business_profile: &domain::Profile, merchant_context: &domain::MerchantContext, ) -> errors::CustomResult<(), errors::ApiErrorResponse> { let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled(); let skip_external_tax_calculation = payment_data .payment_intent .skip_external_tax_calculation .unwrap_or(false); if is_tax_connector_enabled && !skip_external_tax_calculation { let db = state.store.as_ref(); let key_manager_state: &KeyManagerState = &state.into(); let merchant_connector_id = business_profile .tax_connector_id .as_ref() .get_required_value("business_profile.tax_connector_id")?; #[cfg(feature = "v1")] let mca = db .find_by_merchant_connector_account_merchant_id_merchant_connector_id( key_manager_state, &business_profile.merchant_id, merchant_connector_id, merchant_context.get_merchant_key_store(), ) .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { id: merchant_connector_id.get_string_repr().to_string(), }, )?; #[cfg(feature = "v2")] let mca = db .find_merchant_connector_account_by_id( key_manager_state, merchant_connector_id, key_store, ) .await .to_not_found_response( errors::ApiErrorResponse::MerchantConnectorAccountNotFound { id: merchant_connector_id.get_string_repr().to_string(), }, )?; let connector_data = api::TaxCalculateConnectorData::get_connector_by_name(&mca.connector_name)?; let router_data = core_utils::construct_payments_dynamic_tax_calculation_router_data( state, merchant_context, payment_data, &mca, ) .await?; let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::CalculateTax, types::PaymentsTaxCalculationData, types::TaxCalculationResponseData, > = connector_data.connector.get_connector_integration(); let response = services::execute_connector_processing_step( state, connector_integration, &router_data, payments::CallConnectorAction::Trigger, None, None, ) .await .to_payment_failed_response() .attach_printable("Tax connector Response Failed")?; let tax_response = response.response.map_err(|err| { errors::ApiErrorResponse::ExternalConnectorError { code: err.code, message: err.message, connector: connector_data.connector_name.clone().to_string(), status_code: err.status_code, reason: err.reason, } })?; let payment_method_type = payment_data .tax_data .clone() .map(|tax_data| tax_data.payment_method_type) .ok_or(errors::ApiErrorResponse::InternalServerError) .attach_printable("missing tax_data.payment_method_type")?; payment_data.payment_intent.tax_details = Some(diesel_models::TaxDetails { payment_method_type: Some(diesel_models::PaymentMethodTypeTax { order_tax_amount: tax_response.order_tax_amount, pmt: payment_method_type, }), default: None, }); Ok(()) } else { Ok(()) } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 67, "total_crates": null }
fn_clm_router_make_pm_data_3155168946632181718
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/tax_calculation // Implementation of PaymentSessionUpdate for Domain<F, api::PaymentsDynamicTaxCalculationRequest, PaymentData<F>> async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, _payment_data: &mut PaymentData<F>, _storage_scheme: storage_enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, _customer: &Option<domain::Customer>, _business_profile: &domain::Profile, _should_retry_with_pan: bool, ) -> RouterResult<( PaymentSessionUpdateOperation<'a, F>, Option<domain::PaymentMethodData>, Option<String>, )> { Ok((Box::new(self), None, None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 25, "total_crates": null }
fn_clm_router_lidate_request<'_3155168946632181718
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/tax_calculation // Implementation of ymentSessionUpdate { for lidateRequest<F, api::PaymentsDynamicTaxCalculationRequest, PaymentData<F>> validate_request<'a, 'b>( &'b self, request: &api::PaymentsDynamicTaxCalculationRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<( PaymentSessionUpdateOperation<'b, F>, operations::ValidateResult, )> { //paymentid is already generated and should be sent in the request let given_payment_id = request.payment_id.clone(); Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(given_payment_id), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 24, "total_crates": null }
fn_clm_router_get_trackers_4086057823791424010
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get // Implementation of PaymentGet for GetTracker<F, PaymentStatusData<F>, PaymentsRetrieveRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &common_utils::id_type::GlobalPaymentId, request: &PaymentsRetrieveRequest, merchant_context: &domain::MerchantContext, _profile: &domain::Profile, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<PaymentStatusData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; self.validate_status_for_operation(payment_intent.status)?; let active_attempt_id = payment_intent.active_attempt_id.as_ref().ok_or_else(|| { errors::ApiErrorResponse::MissingRequiredField { field_name: ("active_attempt_id"), } })?; let mut payment_attempt = db .find_payment_attempt_by_id( key_manager_state, merchant_context.get_merchant_key_store(), active_attempt_id, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not find payment attempt given the attempt id")?; payment_attempt.encoded_data = request .param .as_ref() .map(|val| masking::Secret::new(val.clone())); let should_sync_with_connector = request.force_sync && payment_intent.status.should_force_sync_with_connector(); // We need the address here to send it in the response let payment_address = hyperswitch_domain_models::payment_address::PaymentAddress::new( payment_intent .shipping_address .clone() .map(|address| address.into_inner()), payment_intent .billing_address .clone() .map(|address| address.into_inner()), payment_attempt .payment_method_billing_address .clone() .map(|address| address.into_inner()), Some(true), ); let attempts = match request.expand_attempts { true => payment_intent .active_attempt_id .as_ref() .async_map(|active_attempt| async { db.find_payment_attempts_by_payment_intent_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not find payment attempts for the given the intent id") }) .await .transpose()?, false => None, }; let merchant_connector_details = request.merchant_connector_details.clone(); let payment_data = PaymentStatusData { flow: std::marker::PhantomData, payment_intent, payment_attempt, payment_address, attempts, should_sync_with_connector, merchant_connector_details, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 111, "total_crates": null }
fn_clm_router_to_domain_4086057823791424010
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get // Implementation of PaymentGet for Operation<F, PaymentsRetrieveRequest> fn to_domain(&self) -> RouterResult<&dyn Domain<F, PaymentsRetrieveRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_update_trackers_4086057823791424010
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get // Implementation of PaymentGet for UpdateTracker<F, PaymentStatusData<F>, PaymentsRetrieveRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentStatusData<F>, _customer: Option<domain::Customer>, _storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(BoxedConfirmOperation<'b, F>, PaymentStatusData<F>)> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_to_update_tracker_4086057823791424010
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get // Implementation of PaymentGet for Operation<F, PaymentsRetrieveRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, PaymentsRetrieveRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_validate_status_for_operation_4086057823791424010
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get // Implementation of PaymentGet for ValidateStatusForOperation /// Validate if the current operation can be performed on the current status of the payment intent fn validate_status_for_operation( &self, intent_status: common_enums::IntentStatus, ) -> Result<(), errors::ApiErrorResponse> { match intent_status { common_enums::IntentStatus::RequiresCapture | common_enums::IntentStatus::PartiallyAuthorizedAndRequiresCapture | common_enums::IntentStatus::RequiresCustomerAction | common_enums::IntentStatus::RequiresMerchantAction | common_enums::IntentStatus::Processing | common_enums::IntentStatus::Succeeded | common_enums::IntentStatus::Failed | common_enums::IntentStatus::PartiallyCapturedAndCapturable | common_enums::IntentStatus::PartiallyCaptured | common_enums::IntentStatus::Cancelled | common_enums::IntentStatus::CancelledPostCapture | common_enums::IntentStatus::Conflicted | common_enums::IntentStatus::Expired => Ok(()), // These statuses are not valid for this operation common_enums::IntentStatus::RequiresConfirmation | common_enums::IntentStatus::RequiresPaymentMethod => { Err(errors::ApiErrorResponse::PaymentUnexpectedState { current_flow: format!("{self:?}"), field_name: "status".to_string(), current_value: intent_status.to_string(), states: [ common_enums::IntentStatus::RequiresCapture, common_enums::IntentStatus::PartiallyAuthorizedAndRequiresCapture, common_enums::IntentStatus::RequiresCustomerAction, common_enums::IntentStatus::RequiresMerchantAction, common_enums::IntentStatus::Processing, common_enums::IntentStatus::Succeeded, common_enums::IntentStatus::Failed, common_enums::IntentStatus::PartiallyCapturedAndCapturable, common_enums::IntentStatus::PartiallyCaptured, common_enums::IntentStatus::Cancelled, ] .map(|enum_value| enum_value.to_string()) .join(", "), }) } } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 45, "total_crates": null }
fn_clm_router_get_trackers_-3812842530210335458
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_confirm_intent // Implementation of PaymentIntentConfirm for GetTracker<F, PaymentConfirmData<F>, PaymentsConfirmIntentRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &id_type::GlobalPaymentId, request: &PaymentsConfirmIntentRequest, merchant_context: &domain::MerchantContext, profile: &domain::Profile, header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<PaymentConfirmData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // TODO (#7195): Add platform merchant account validation once publishable key auth is solved self.validate_status_for_operation(payment_intent.status)?; let cell_id = state.conf.cell_information.id.clone(); let batch_encrypted_data = domain_types::crypto_operation( key_manager_state, common_utils::type_name!(hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt), domain_types::CryptoOperation::BatchEncrypt( hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt::to_encryptable( hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt { payment_method_billing_address: request.payment_method_data.billing.as_ref().map(|address| address.clone().encode_to_value()).transpose().change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to encode payment_method_billing address")?.map(masking::Secret::new), }, ), ), common_utils::types::keymanager::Identifier::Merchant(merchant_context.get_merchant_account().get_id().to_owned()), merchant_context.get_merchant_key_store().key.peek(), ) .await .and_then(|val| val.try_into_batchoperation()) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details".to_string())?; let encrypted_data = hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt::from_encryptable(batch_encrypted_data) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details")?; let payment_attempt_domain_model = hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt::create_domain_model( &payment_intent, cell_id, storage_scheme, request, encrypted_data ) .await?; let payment_attempt: hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt = db.insert_payment_attempt( key_manager_state, merchant_context.get_merchant_key_store(), payment_attempt_domain_model, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not insert payment attempt")?; let payment_method_data = request .payment_method_data .payment_method_data .clone() .map(hyperswitch_domain_models::payment_method_data::PaymentMethodData::from); if request.payment_token.is_some() { when( !matches!( payment_method_data, Some(domain::payment_method_data::PaymentMethodData::CardToken(_)) ), || { Err(errors::ApiErrorResponse::InvalidDataValue { field_name: "payment_method_data", }) .attach_printable( "payment_method_data should be card_token when a token is passed", ) }, )?; }; let payment_address = hyperswitch_domain_models::payment_address::PaymentAddress::new( payment_intent .shipping_address .clone() .map(|address| address.into_inner()), payment_intent .billing_address .clone() .map(|address| address.into_inner()), payment_attempt .payment_method_billing_address .clone() .map(|address| address.into_inner()), Some(true), ); let merchant_connector_details = request.merchant_connector_details.clone(); let payment_data = PaymentConfirmData { flow: std::marker::PhantomData, payment_intent, payment_attempt, payment_method_data, payment_address, mandate_data: None, payment_method: None, merchant_connector_details, external_vault_pmd: None, webhook_url: request .webhook_url .as_ref() .map(|url| url.get_string_repr().to_string()), }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 155, "total_crates": null }
fn_clm_router_update_trackers_-3812842530210335458
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_confirm_intent // Implementation of PaymentIntentConfirm for UpdateTracker<F, PaymentConfirmData<F>, PaymentsConfirmIntentRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, req_state: ReqState, mut payment_data: PaymentConfirmData<F>, customer: Option<domain::Customer>, storage_scheme: storage_enums::MerchantStorageScheme, updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, frm_suggestion: Option<FrmSuggestion>, header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(BoxedConfirmOperation<'b, F>, PaymentConfirmData<F>)> where F: 'b + Send, { let db = &*state.store; let key_manager_state = &state.into(); let intent_status = common_enums::IntentStatus::Processing; let attempt_status = common_enums::AttemptStatus::Pending; let connector = payment_data .payment_attempt .connector .clone() .get_required_value("connector") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Connector is none when constructing response")?; // If `merchant_connector_details` are present in the payment request, `merchant_connector_id` will not be populated. let merchant_connector_id = match &payment_data.merchant_connector_details { Some(_details) => None, None => Some( payment_data .payment_attempt .merchant_connector_id .clone() .get_required_value("merchant_connector_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Merchant connector id is none when constructing response")?, ), }; let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::ConfirmIntent { status: intent_status, updated_by: storage_scheme.to_string(), active_attempt_id: Some(payment_data.payment_attempt.id.clone()), }; let authentication_type = payment_data.payment_attempt.authentication_type; let connector_request_reference_id = payment_data .payment_attempt .connector_request_reference_id .clone(); // Updates payment_attempt for cases where authorize flow is not performed. let connector_response_reference_id = payment_data .payment_attempt .connector_response_reference_id .clone(); let payment_attempt_update = match &payment_data.payment_method { // In the case of a tokenized payment method, we update the payment attempt with the tokenized payment method details. Some(payment_method) => { hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ConfirmIntentTokenized { status: attempt_status, updated_by: storage_scheme.to_string(), connector, merchant_connector_id: merchant_connector_id.ok_or_else( || { error_stack::report!(errors::ApiErrorResponse::InternalServerError) .attach_printable("Merchant connector id is none when constructing response") })?, authentication_type, connector_request_reference_id, payment_method_id : payment_method.get_id().clone() } } None => { hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ConfirmIntent { status: attempt_status, updated_by: storage_scheme.to_string(), connector, merchant_connector_id, authentication_type, connector_request_reference_id, connector_response_reference_id, } } }; let updated_payment_intent = db .update_payment_intent( key_manager_state, payment_data.payment_intent.clone(), payment_intent_update, key_store, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Unable to update payment intent")?; payment_data.payment_intent = updated_payment_intent; let updated_payment_attempt = db .update_payment_attempt( key_manager_state, key_store, payment_data.payment_attempt.clone(), payment_attempt_update, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Unable to update payment attempt")?; payment_data.payment_attempt = updated_payment_attempt; if let Some((customer, updated_customer)) = customer.zip(updated_customer) { let customer_id = customer.get_id().clone(); let customer_merchant_id = customer.merchant_id.clone(); let _updated_customer = db .update_customer_by_global_id( key_manager_state, &customer_id, customer, updated_customer, key_store, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to update customer during `update_trackers`")?; } Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 129, "total_crates": null }
fn_clm_router_to_domain_-3812842530210335458
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_confirm_intent // Implementation of PaymentIntentConfirm for Operation<F, PaymentsConfirmIntentRequest> fn to_domain(&self) -> RouterResult<&dyn Domain<F, PaymentsConfirmIntentRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_create_or_fetch_payment_method_-3812842530210335458
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_confirm_intent // Implementation of PaymentIntentConfirm for Domain<F, PaymentsConfirmIntentRequest, PaymentConfirmData<F>> async fn create_or_fetch_payment_method<'a>( &'a self, state: &SessionState, merchant_context: &domain::MerchantContext, business_profile: &domain::Profile, payment_data: &mut PaymentConfirmData<F>, ) -> CustomResult<(), errors::ApiErrorResponse> { let (payment_method, payment_method_data) = match ( &payment_data.payment_attempt.payment_token, &payment_data.payment_method_data, &payment_data.payment_attempt.customer_acceptance, ) { ( Some(payment_token), Some(domain::payment_method_data::PaymentMethodData::CardToken(card_token)), None, ) => { let (card_cvc, card_holder_name) = { ( card_token .card_cvc .clone() .ok_or(errors::ApiErrorResponse::InvalidDataValue { field_name: "card_cvc", }) .or( payment_methods::vault::retrieve_and_delete_cvc_from_payment_token( state, payment_token, payment_data.payment_attempt.payment_method_type, merchant_context.get_merchant_key_store().key.get_inner(), ) .await, ) .attach_printable("card_cvc not provided")?, card_token.card_holder_name.clone(), ) }; let (payment_method, vault_data) = payment_methods::vault::retrieve_payment_method_from_vault_using_payment_token( state, merchant_context, business_profile, payment_token, &payment_data.payment_attempt.payment_method_type, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to retrieve payment method from vault")?; match vault_data { domain::vault::PaymentMethodVaultingData::Card(card_detail) => { let pm_data_from_vault = domain::payment_method_data::PaymentMethodData::Card( domain::payment_method_data::Card::from(( card_detail, card_cvc, card_holder_name, )), ); (Some(payment_method), Some(pm_data_from_vault)) } _ => Err(errors::ApiErrorResponse::NotImplemented { message: errors::NotImplementedMessage::Reason( "Non-card Tokenization not implemented".to_string(), ), })?, } } (Some(_payment_token), _, _) => Err(errors::ApiErrorResponse::InvalidDataValue { field_name: "payment_method_data", }) .attach_printable("payment_method_data should be card_token when a token is passed")?, (None, Some(domain::PaymentMethodData::Card(card)), Some(_customer_acceptance)) => { let customer_id = match &payment_data.payment_intent.customer_id { Some(customer_id) => customer_id.clone(), None => { return Err(errors::ApiErrorResponse::InvalidDataValue { field_name: "customer_id", }) .attach_printable("customer_id not provided"); } }; let pm_create_data = api::PaymentMethodCreateData::Card(api::CardDetail::from(card.clone())); let req = api::PaymentMethodCreate { payment_method_type: payment_data.payment_attempt.payment_method_type, payment_method_subtype: payment_data.payment_attempt.payment_method_subtype, metadata: None, customer_id, payment_method_data: pm_create_data, billing: None, psp_tokenization: None, network_tokenization: None, }; let (_pm_response, payment_method) = Box::pin(payment_methods::create_payment_method_core( state, &state.get_req_state(), req, merchant_context, business_profile, )) .await?; // Don't modify payment_method_data in this case, only the payment_method and payment_method_id (Some(payment_method), None) } _ => (None, None), // Pass payment_data unmodified for any other case }; if let Some(pm_data) = payment_method_data { payment_data.update_payment_method_data(pm_data); } if let Some(pm) = payment_method { payment_data.update_payment_method_and_pm_id(pm.get_id().clone(), pm); } Ok(()) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 67, "total_crates": null }
fn_clm_router_to_update_tracker_-3812842530210335458
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_confirm_intent // Implementation of PaymentIntentConfirm for Operation<F, PaymentsConfirmIntentRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, PaymentsConfirmIntentRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_get_trackers_-3050795105359382054
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payments_incremental_authorization // Implementation of PaymentIncrementalAuthorization for GetTracker<F, payments::PaymentData<F>, PaymentsIncrementalAuthorizationRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, request: &PaymentsIncrementalAuthorizationRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse< 'a, F, PaymentsIncrementalAuthorizationRequest, payments::PaymentData<F>, >, > { let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; let payment_intent = db .find_payment_intent_by_payment_id_merchant_id( &state.into(), &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; helpers::validate_payment_status_against_allowed_statuses( payment_intent.status, &[enums::IntentStatus::RequiresCapture], "increment authorization", )?; if payment_intent.incremental_authorization_allowed != Some(true) { Err(errors::ApiErrorResponse::PreconditionFailed { message: "You cannot increment authorization this payment because it is not allowed for incremental_authorization".to_owned(), })? } let attempt_id = payment_intent.active_attempt.get_id().clone(); let payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, attempt_id.clone().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // Incremental authorization should be performed on an amount greater than the original authorized amount (in this case, greater than the net_amount which is sent for authorization) // request.amount is the total amount that should be authorized in incremental authorization which should be greater than the original authorized amount if payment_attempt.get_total_amount() >= request.amount { Err(errors::ApiErrorResponse::PreconditionFailed { message: "Amount should be greater than original authorized amount".to_owned(), })? } let currency = payment_attempt.currency.get_required_value("currency")?; let amount = payment_attempt.get_total_amount(); let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = state .store .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let payment_data = payments::PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount: amount.into(), email: None, mandate_id: None, mandate_connector: None, setup_mandate: None, customer_acceptance: None, token: None, token_data: None, address: PaymentAddress::new(None, None, None, None), confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: Some(IncrementalAuthorizationDetails { additional_amount: request.amount - amount, total_amount: request.amount, reason: request.reason.clone(), authorization_id: None, }), authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: None, payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 111, "total_crates": null }
fn_clm_router_update_trackers_-3050795105359382054
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payments_incremental_authorization // Implementation of PaymentIncrementalAuthorization for UpdateTracker<F, payments::PaymentData<F>, PaymentsIncrementalAuthorizationRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, _req_state: ReqState, mut payment_data: payments::PaymentData<F>, _customer: Option<domain::Customer>, storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<( PaymentIncrementalAuthorizationOperation<'b, F>, payments::PaymentData<F>, )> where F: 'b + Send, { let new_authorization_count = payment_data .payment_intent .authorization_count .map(|count| count + 1) .unwrap_or(1); // Create new authorization record let authorization_new = AuthorizationNew { authorization_id: format!( "{}_{}", common_utils::generate_id_with_default_len("auth"), new_authorization_count ), merchant_id: payment_data.payment_intent.merchant_id.clone(), payment_id: payment_data.payment_intent.payment_id.clone(), amount: payment_data .incremental_authorization_details .clone() .map(|details| details.total_amount) .ok_or( report!(errors::ApiErrorResponse::InternalServerError).attach_printable( "missing incremental_authorization_details in payment_data", ), )?, status: common_enums::AuthorizationStatus::Processing, error_code: None, error_message: None, connector_authorization_id: None, previously_authorized_amount: payment_data.payment_attempt.get_total_amount(), }; let authorization = state .store .insert_authorization(authorization_new.clone()) .await .to_duplicate_response(errors::ApiErrorResponse::GenericDuplicateError { message: format!( "Authorization with authorization_id {} already exists", authorization_new.authorization_id ), }) .attach_printable("failed while inserting new authorization")?; // Update authorization_count in payment_intent payment_data.payment_intent = state .store .update_payment_intent( &state.into(), payment_data.payment_intent.clone(), storage::PaymentIntentUpdate::AuthorizationCountUpdate { authorization_count: new_authorization_count, }, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Failed to update authorization_count in Payment Intent")?; match &payment_data.incremental_authorization_details { Some(details) => { payment_data.incremental_authorization_details = Some(IncrementalAuthorizationDetails { authorization_id: Some(authorization.authorization_id), ..details.clone() }); } None => Err(errors::ApiErrorResponse::InternalServerError) .attach_printable("missing incremental_authorization_details in payment_data")?, } Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 101, "total_crates": null }
fn_clm_router_validate_request_-3050795105359382054
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payments_incremental_authorization // Implementation of PaymentIncrementalAuthorization for ValidateRequest<F, PaymentsIncrementalAuthorizationRequest, payments::PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &PaymentsIncrementalAuthorizationRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<( PaymentIncrementalAuthorizationOperation<'b, F>, operations::ValidateResult, )> { Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(request.payment_id.to_owned()), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 46, "total_crates": null }
fn_clm_router_make_pm_data_-3050795105359382054
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payments_incremental_authorization // Implementation of PaymentIncrementalAuthorization for Domain<F, PaymentsIncrementalAuthorizationRequest, payments::PaymentData<F>> async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, _payment_data: &mut payments::PaymentData<F>, _storage_scheme: enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, _customer: &Option<domain::Customer>, _business_profile: &domain::Profile, _should_retry_with_pan: bool, ) -> RouterResult<( PaymentIncrementalAuthorizationOperation<'a, F>, Option<domain::PaymentMethodData>, Option<String>, )> { Ok((Box::new(self), None, None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 25, "total_crates": null }
fn_clm_router_get_or_create_customer_details_-3050795105359382054
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payments_incremental_authorization // Implementation of PaymentIncrementalAuthorization for Domain<F, PaymentsIncrementalAuthorizationRequest, payments::PaymentData<F>> async fn get_or_create_customer_details<'a>( &'a self, _state: &SessionState, _payment_data: &mut payments::PaymentData<F>, _request: Option<CustomerDetails>, _merchant_key_store: &domain::MerchantKeyStore, _storage_scheme: enums::MerchantStorageScheme, ) -> CustomResult< ( BoxedOperation< 'a, F, PaymentsIncrementalAuthorizationRequest, payments::PaymentData<F>, >, Option<domain::Customer>, ), errors::StorageError, > { Ok((Box::new(self), None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 19, "total_crates": null }
fn_clm_router_get_trackers_739667837067299240
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_reject // Implementation of PaymentReject for GetTracker<F, PaymentData<F>, PaymentsCancelRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, _request: &PaymentsCancelRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<'a, F, PaymentsCancelRequest, PaymentData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; let payment_intent = db .find_payment_intent_by_payment_id_merchant_id( key_manager_state, &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; helpers::validate_payment_status_against_not_allowed_statuses( payment_intent.status, &[ enums::IntentStatus::Cancelled, enums::IntentStatus::Failed, enums::IntentStatus::Succeeded, enums::IntentStatus::Processing, ], "reject", )?; let attempt_id = payment_intent.active_attempt.get_id().clone(); let payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, attempt_id.clone().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let shipping_address = helpers::get_address_by_id( state, payment_intent.shipping_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let billing_address = helpers::get_address_by_id( state, payment_intent.billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let payment_method_billing = helpers::get_address_by_id( state, payment_attempt.payment_method_billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let currency = payment_attempt.currency.get_required_value("currency")?; let amount = payment_attempt.get_total_amount().into(); let frm_response = if cfg!(feature = "frm") { db.find_fraud_check_by_payment_id(payment_intent.payment_id.clone(), merchant_context.get_merchant_account().get_id().clone()) .await .change_context(errors::ApiErrorResponse::PaymentNotFound) .attach_printable_lazy(|| { format!("Error while retrieving frm_response, merchant_id: {:?}, payment_id: {attempt_id}", merchant_context.get_merchant_account().get_id()) }) .ok() } else { None }; let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = state .store .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: None, mandate_id: None, mandate_connector: None, setup_mandate: None, customer_acceptance: None, token: None, address: PaymentAddress::new( shipping_address.as_ref().map(From::from), billing_address.as_ref().map(From::from), payment_method_billing.as_ref().map(From::from), business_profile.use_billing_as_payment_method_billing, ), token_data: None, confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: frm_response, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: None, payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 153, "total_crates": null }
fn_clm_router_update_trackers_739667837067299240
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_reject // Implementation of PaymentReject for UpdateTracker<F, PaymentData<F>, PaymentsCancelRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, req_state: ReqState, mut payment_data: PaymentData<F>, _customer: Option<domain::Customer>, storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _should_decline_transaction: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentRejectOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { let intent_status_update = storage::PaymentIntentUpdate::RejectUpdate { status: enums::IntentStatus::Failed, merchant_decision: Some(enums::MerchantDecision::Rejected.to_string()), updated_by: storage_scheme.to_string(), }; let (error_code, error_message) = payment_data .frm_message .clone() .map_or((None, None), |fraud_check| { ( Some(Some(fraud_check.frm_status.to_string())), Some(fraud_check.frm_reason.map(|reason| reason.to_string())), ) }); let attempt_status_update = storage::PaymentAttemptUpdate::RejectUpdate { status: enums::AttemptStatus::Failure, error_code, error_message, updated_by: storage_scheme.to_string(), }; payment_data.payment_intent = state .store .update_payment_intent( &state.into(), payment_data.payment_intent, intent_status_update, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; payment_data.payment_attempt = state .store .update_payment_attempt_with_attempt_id( payment_data.payment_attempt.clone(), attempt_status_update, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let error_code = payment_data.payment_attempt.error_code.clone(); let error_message = payment_data.payment_attempt.error_message.clone(); req_state .event_context .event(AuditEvent::new(AuditEventType::PaymentReject { error_code, error_message, })) .with(payment_data.to_event()) .emit(); Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 103, "total_crates": null }
fn_clm_router_validate_request_739667837067299240
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_reject // Implementation of PaymentReject for ValidateRequest<F, PaymentsCancelRequest, PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &PaymentsCancelRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<(PaymentRejectOperation<'b, F>, operations::ValidateResult)> { Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(request.payment_id.to_owned()), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 46, "total_crates": null }
fn_clm_router_to_domain_7048386052616597257
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_capture_v2 // Implementation of PaymentsCapture for Operation<F, PaymentsCaptureRequest> fn to_domain(&self) -> RouterResult<&dyn Domain<F, PaymentsCaptureRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_get_trackers_7048386052616597257
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_capture_v2 // Implementation of PaymentsCapture for GetTracker<F, PaymentCaptureData<F>, PaymentsCaptureRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &common_utils::id_type::GlobalPaymentId, request: &PaymentsCaptureRequest, merchant_context: &domain::MerchantContext, _profile: &domain::Profile, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<PaymentCaptureData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; self.validate_status_for_operation(payment_intent.status)?; let active_attempt_id = payment_intent .active_attempt_id .as_ref() .get_required_value("active_attempt_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Active attempt id is none when capturing the payment")?; let mut payment_attempt = db .find_payment_attempt_by_id( key_manager_state, merchant_context.get_merchant_key_store(), active_attempt_id, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not find payment attempt given the attempt id")?; if let Some(amount_to_capture) = request.amount_to_capture { payment_attempt .amount_details .validate_amount_to_capture(amount_to_capture) .change_context(errors::ApiErrorResponse::PreconditionFailed { message: format!( "`amount_to_capture` is greater than the net amount {}", payment_attempt.amount_details.get_net_amount() ), })?; payment_attempt .amount_details .set_amount_to_capture(amount_to_capture); } let payment_data = PaymentCaptureData { flow: std::marker::PhantomData, payment_intent, payment_attempt, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 75, "total_crates": null }
fn_clm_router_update_trackers_7048386052616597257
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_capture_v2 // Implementation of PaymentsCapture for UpdateTracker<F, PaymentCaptureData<F>, PaymentsCaptureRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentCaptureData<F>, _customer: Option<domain::Customer>, storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(BoxedConfirmOperation<'b, F>, PaymentCaptureData<F>)> where F: 'b + Send, { let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::PreCaptureUpdate { amount_to_capture: payment_data.payment_attempt.amount_details.get_amount_to_capture(), updated_by: storage_scheme.to_string() }; let payment_attempt = state .store .update_payment_attempt( &state.into(), key_store, payment_data.payment_attempt.clone(), payment_attempt_update, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not update payment attempt")?; payment_data.payment_attempt = payment_attempt; Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 75, "total_crates": null }
fn_clm_router_to_update_tracker_7048386052616597257
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_capture_v2 // Implementation of PaymentsCapture for Operation<F, PaymentsCaptureRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, PaymentsCaptureRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_validate_status_for_operation_7048386052616597257
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_capture_v2 // Implementation of PaymentsCapture for ValidateStatusForOperation /// Validate if the current operation can be performed on the current status of the payment intent fn validate_status_for_operation( &self, intent_status: common_enums::IntentStatus, ) -> Result<(), errors::ApiErrorResponse> { match intent_status { common_enums::IntentStatus::RequiresCapture | common_enums::IntentStatus::PartiallyAuthorizedAndRequiresCapture | common_enums::IntentStatus::PartiallyCapturedAndCapturable => Ok(()), common_enums::IntentStatus::Succeeded | common_enums::IntentStatus::Conflicted | common_enums::IntentStatus::Failed | common_enums::IntentStatus::Cancelled | common_enums::IntentStatus::CancelledPostCapture | common_enums::IntentStatus::Processing | common_enums::IntentStatus::RequiresCustomerAction | common_enums::IntentStatus::RequiresMerchantAction | common_enums::IntentStatus::RequiresPaymentMethod | common_enums::IntentStatus::PartiallyCaptured | common_enums::IntentStatus::RequiresConfirmation | common_enums::IntentStatus::Expired => { Err(errors::ApiErrorResponse::PaymentUnexpectedState { current_flow: format!("{self:?}"), field_name: "status".to_string(), current_value: intent_status.to_string(), states: [ common_enums::IntentStatus::RequiresCapture, common_enums::IntentStatus::PartiallyCapturedAndCapturable, ] .map(|enum_value| enum_value.to_string()) .join(", "), }) } } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 45, "total_crates": null }
fn_clm_router_get_trackers_7930712674608423291
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_update_metadata // Implementation of PaymentUpdateMetadata for GetTracker<F, PaymentData<F>, api::PaymentsUpdateMetadataRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsUpdateMetadataRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse<'a, F, api::PaymentsUpdateMetadataRequest, PaymentData<F>>, > { let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; let db = &*state.store; let key_manager_state: &KeyManagerState = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let mut payment_intent = db .find_payment_intent_by_payment_id_merchant_id( &state.into(), &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; helpers::validate_payment_status_against_allowed_statuses( payment_intent.status, &[ storage_enums::IntentStatus::Succeeded, storage_enums::IntentStatus::Failed, storage_enums::IntentStatus::PartiallyCaptured, storage_enums::IntentStatus::PartiallyCapturedAndCapturable, storage_enums::IntentStatus::RequiresCapture, ], "update_metadata", )?; let payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, payment_intent.active_attempt.get_id().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let currency = payment_intent.currency.get_required_value("currency")?; let amount = payment_attempt.get_total_amount().into(); let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let merged_metadata = payment_intent .merge_metadata(request.metadata.clone().expose()) .change_context(errors::ApiErrorResponse::InvalidRequestData { message: "Metadata should be an object and contain at least 1 key".to_owned(), })?; payment_intent.metadata = Some(merged_metadata); let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: None, mandate_id: None, mandate_connector: None, customer_acceptance: None, token: None, token_data: None, setup_mandate: None, address: payments::PaymentAddress::new(None, None, None, None), confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: None, payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 109, "total_crates": null }
fn_clm_router_update_trackers_7930712674608423291
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_update_metadata // Implementation of PaymentUpdateMetadata for UpdateTracker<F, PaymentData<F>, api::PaymentsUpdateMetadataRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData<F>, _customer: Option<domain::Customer>, _storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentUpdateMetadataOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_validate_request_7930712674608423291
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_update_metadata // Implementation of PaymentUpdateMetadata for ValidateRequest<F, api::PaymentsUpdateMetadataRequest, PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsUpdateMetadataRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<( PaymentUpdateMetadataOperation<'b, F>, operations::ValidateResult, )> { //payment id is already generated and should be sent in the request let given_payment_id = request.payment_id.clone(); Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(given_payment_id), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 46, "total_crates": null }
fn_clm_router_make_pm_data_7930712674608423291
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_update_metadata // Implementation of PaymentUpdateMetadata for Domain<F, api::PaymentsUpdateMetadataRequest, PaymentData<F>> async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, _payment_data: &mut PaymentData<F>, _storage_scheme: storage_enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, _customer: &Option<domain::Customer>, _business_profile: &domain::Profile, _should_retry_with_pan: bool, ) -> RouterResult<( PaymentUpdateMetadataOperation<'a, F>, Option<domain::PaymentMethodData>, Option<String>, )> { Ok((Box::new(self), None, None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 25, "total_crates": null }
fn_clm_router_get_or_create_customer_details_7930712674608423291
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_update_metadata // Implementation of PaymentUpdateMetadata for Domain<F, api::PaymentsUpdateMetadataRequest, PaymentData<F>> async fn get_or_create_customer_details<'a>( &'a self, _state: &SessionState, _payment_data: &mut PaymentData<F>, _request: Option<payments::CustomerDetails>, _merchant_key_store: &domain::MerchantKeyStore, _storage_scheme: storage_enums::MerchantStorageScheme, ) -> errors::CustomResult< ( PaymentUpdateMetadataOperation<'a, F>, Option<domain::Customer>, ), errors::StorageError, > { Ok((Box::new(self), None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 19, "total_crates": null }
fn_clm_router_get_trackers_-7312896986440792183
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_approve // Implementation of PaymentApprove for GetTracker<F, PaymentData<F>, api::PaymentsCaptureRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, _request: &api::PaymentsCaptureRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse<'a, F, api::PaymentsCaptureRequest, PaymentData<F>>, > { let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let (mut payment_intent, payment_attempt, currency, amount); let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; payment_intent = db .find_payment_intent_by_payment_id_merchant_id( key_manager_state, &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; helpers::validate_payment_status_against_not_allowed_statuses( payment_intent.status, &[IntentStatus::Failed, IntentStatus::Succeeded], "approve", )?; let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = state .store .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let attempt_id = payment_intent.active_attempt.get_id().clone(); payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, &attempt_id.clone(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; currency = payment_attempt.currency.get_required_value("currency")?; amount = payment_attempt.get_total_amount().into(); let shipping_address = helpers::get_address_by_id( state, payment_intent.shipping_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let billing_address = helpers::get_address_by_id( state, payment_intent.billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let payment_method_billing = helpers::get_address_by_id( state, payment_attempt.payment_method_billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; payment_intent.shipping_address_id = shipping_address.clone().map(|i| i.address_id); payment_intent.billing_address_id = billing_address.clone().map(|i| i.address_id); let frm_response = if cfg!(feature = "frm") { db.find_fraud_check_by_payment_id(payment_intent.payment_id.clone(), merchant_context.get_merchant_account().get_id().clone()) .await .change_context(errors::ApiErrorResponse::PaymentNotFound) .attach_printable_lazy(|| { format!("Error while retrieving frm_response, merchant_id: {}, payment_id: {attempt_id}", merchant_context.get_merchant_account().get_id().get_string_repr()) }) .ok() } else { None }; let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: None, mandate_id: None, mandate_connector: None, setup_mandate: None, customer_acceptance: None, token: None, token_data: None, address: PaymentAddress::new( shipping_address.as_ref().map(From::from), billing_address.as_ref().map(From::from), payment_method_billing.as_ref().map(From::from), business_profile.use_billing_as_payment_method_billing, ), confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: frm_response, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: None, payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 159, "total_crates": null }
fn_clm_router_update_trackers_-7312896986440792183
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_approve // Implementation of PaymentApprove for UpdateTracker<F, PaymentData<F>, api::PaymentsCaptureRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, req_state: ReqState, mut payment_data: PaymentData<F>, _customer: Option<domain::Customer>, storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentApproveOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { if matches!(frm_suggestion, Some(FrmSuggestion::FrmAuthorizeTransaction)) { payment_data.payment_intent.status = IntentStatus::RequiresCapture; // In Approve flow, payment which has payment_capture_method "manual" and attempt status as "Unresolved", payment_data.payment_attempt.status = AttemptStatus::Authorized; // We shouldn't call the connector instead we need to update the payment attempt and payment intent. } let intent_status_update = storage::PaymentIntentUpdate::ApproveUpdate { status: payment_data.payment_intent.status, merchant_decision: Some(api_models::enums::MerchantDecision::Approved.to_string()), updated_by: storage_scheme.to_string(), }; payment_data.payment_intent = state .store .update_payment_intent( &state.into(), payment_data.payment_intent, intent_status_update, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; state .store .update_payment_attempt_with_attempt_id( payment_data.payment_attempt.clone(), storage::PaymentAttemptUpdate::StatusUpdate { status: payment_data.payment_attempt.status, updated_by: storage_scheme.to_string(), }, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; req_state .event_context .event(AuditEvent::new(AuditEventType::PaymentApprove)) .with(payment_data.to_event()) .emit(); Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 89, "total_crates": null }
fn_clm_router_validate_request_-7312896986440792183
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_approve // Implementation of PaymentApprove for ValidateRequest<F, api::PaymentsCaptureRequest, PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCaptureRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<(PaymentApproveOperation<'b, F>, operations::ValidateResult)> { let request_merchant_id = request.merchant_id.as_ref(); helpers::validate_merchant_id( merchant_context.get_merchant_account().get_id(), request_merchant_id, ) .change_context(errors::ApiErrorResponse::InvalidDataFormat { field_name: "merchant_id".to_string(), expected_format: "merchant_id from merchant account".to_string(), })?; Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(request.payment_id.clone()), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 60, "total_crates": null }
fn_clm_router_payment_response_update_tracker_-5816298866945945616
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_response async fn payment_response_update_tracker<F: Clone, T: types::Capturable>( state: &SessionState, mut payment_data: PaymentData<F>, router_data: types::RouterData<F, T, types::PaymentsResponseData>, key_store: &domain::MerchantKeyStore, storage_scheme: enums::MerchantStorageScheme, locale: &Option<String>, #[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connectors: Vec< RoutableConnectorChoice, >, #[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile, ) -> RouterResult<PaymentData<F>> { // Update additional payment data with the payment method response that we received from connector // This is for details like whether 3ds was upgraded and which version of 3ds was used // also some connectors might send card network details in the response, which is captured and stored let additional_payment_data = payment_data.payment_attempt.get_payment_method_data(); let additional_payment_method_data = match payment_data.payment_method_data.clone() { Some(hyperswitch_domain_models::payment_method_data::PaymentMethodData::NetworkToken(_)) | Some(hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardDetailsForNetworkTransactionId(_)) => { payment_data.payment_attempt.payment_method_data.clone() } _ => { additional_payment_data .map(|_| { update_additional_payment_data_with_connector_response_pm_data( payment_data.payment_attempt.payment_method_data.clone(), router_data .connector_response .as_ref() .and_then(|connector_response| { connector_response.additional_payment_method_data.clone() }), ) }) .transpose()? .flatten() } }; router_data.payment_method_status.and_then(|status| { payment_data .payment_method_info .as_mut() .map(|info| info.status = status) }); payment_data.whole_connector_response = router_data.raw_connector_response.clone(); // TODO: refactor of gsm_error_category with respective feature flag #[allow(unused_variables)] let (capture_update, mut payment_attempt_update, gsm_error_category) = match router_data .response .clone() { Err(err) => { let auth_update = if Some(router_data.auth_type) != payment_data.payment_attempt.authentication_type { Some(router_data.auth_type) } else { None }; let (capture_update, attempt_update, gsm_error_category) = match payment_data.multiple_capture_data { Some(multiple_capture_data) => { let capture_update = storage::CaptureUpdate::ErrorUpdate { status: match err.status_code { 500..=511 => enums::CaptureStatus::Pending, _ => enums::CaptureStatus::Failed, }, error_code: Some(err.code), error_message: Some(err.message), error_reason: err.reason, }; let capture_update_list = vec![( multiple_capture_data.get_latest_capture().clone(), capture_update, )]; ( Some((multiple_capture_data, capture_update_list)), auth_update.map(|auth_type| { storage::PaymentAttemptUpdate::AuthenticationTypeUpdate { authentication_type: auth_type, updated_by: storage_scheme.to_string(), } }), None, ) } None => { let connector_name = router_data.connector.to_string(); let flow_name = core_utils::get_flow_name::<F>()?; let option_gsm = payments_helpers::get_gsm_record( state, Some(err.code.clone()), Some(err.message.clone()), connector_name, flow_name.clone(), ) .await; let gsm_unified_code = option_gsm.as_ref().and_then(|gsm| gsm.unified_code.clone()); let gsm_unified_message = option_gsm.clone().and_then(|gsm| gsm.unified_message); let (unified_code, unified_message) = if let Some((code, message)) = gsm_unified_code.as_ref().zip(gsm_unified_message.as_ref()) { (code.to_owned(), message.to_owned()) } else { ( consts::DEFAULT_UNIFIED_ERROR_CODE.to_owned(), consts::DEFAULT_UNIFIED_ERROR_MESSAGE.to_owned(), ) }; let unified_translated_message = locale .as_ref() .async_and_then(|locale_str| async { payments_helpers::get_unified_translation( state, unified_code.to_owned(), unified_message.to_owned(), locale_str.to_owned(), ) .await }) .await .or(Some(unified_message)); let status = match err.attempt_status { // Use the status sent by connector in error_response if it's present Some(status) => status, None => // mark previous attempt status for technical failures in PSync and ExtendAuthorization flow { if flow_name == "PSync" || flow_name == "ExtendAuthorization" { match err.status_code { // marking failure for 2xx because this is genuine payment failure 200..=299 => enums::AttemptStatus::Failure, _ => router_data.status, } } else if flow_name == "Capture" { match err.status_code { 500..=511 => enums::AttemptStatus::Pending, // don't update the status for 429 error status 429 => router_data.status, _ => enums::AttemptStatus::Failure, } } else { match err.status_code { 500..=511 => enums::AttemptStatus::Pending, _ => enums::AttemptStatus::Failure, } } } }; ( None, Some(storage::PaymentAttemptUpdate::ErrorUpdate { connector: None, status, error_message: Some(Some(err.message.clone())), error_code: Some(Some(err.code.clone())), error_reason: Some(err.reason.clone()), amount_capturable: router_data .request .get_amount_capturable( &payment_data, router_data .minor_amount_capturable .map(MinorUnit::get_amount_as_i64), status, ) .map(MinorUnit::new), updated_by: storage_scheme.to_string(), unified_code: Some(Some(unified_code)), unified_message: Some(unified_translated_message), connector_transaction_id: err.connector_transaction_id.clone(), payment_method_data: additional_payment_method_data, authentication_type: auth_update, issuer_error_code: err.network_decline_code.clone(), issuer_error_message: err.network_error_message.clone(), network_details: Some(ForeignFrom::foreign_from(&err)), }), option_gsm.and_then(|option_gsm| option_gsm.error_category), ) } }; (capture_update, attempt_update, gsm_error_category) } Ok(payments_response) => { // match on connector integrity check match router_data.integrity_check.clone() { Err(err) => { let auth_update = if Some(router_data.auth_type) != payment_data.payment_attempt.authentication_type { Some(router_data.auth_type) } else { None }; let field_name = err.field_names; let connector_transaction_id = err.connector_transaction_id; ( None, Some(storage::PaymentAttemptUpdate::ErrorUpdate { connector: None, status: enums::AttemptStatus::IntegrityFailure, error_message: Some(Some("Integrity Check Failed!".to_string())), error_code: Some(Some("IE".to_string())), error_reason: Some(Some(format!( "Integrity Check Failed! Value mismatched for fields {field_name}" ))), amount_capturable: None, updated_by: storage_scheme.to_string(), unified_code: None, unified_message: None, connector_transaction_id, payment_method_data: None, authentication_type: auth_update, issuer_error_code: None, issuer_error_message: None, network_details: None, }), None, ) } Ok(()) => { let attempt_status = payment_data.payment_attempt.status.to_owned(); let connector_status = router_data.status.to_owned(); let updated_attempt_status = match ( connector_status, attempt_status, payment_data.frm_message.to_owned(), ) { ( enums::AttemptStatus::Authorized, enums::AttemptStatus::Unresolved, Some(frm_message), ) => match frm_message.frm_status { enums::FraudCheckStatus::Fraud | enums::FraudCheckStatus::ManualReview => attempt_status, _ => router_data.get_attempt_status_for_db_update( &payment_data, router_data.amount_captured, router_data .minor_amount_capturable .map(MinorUnit::get_amount_as_i64), )?, }, _ => router_data.get_attempt_status_for_db_update( &payment_data, router_data.amount_captured, router_data .minor_amount_capturable .map(MinorUnit::get_amount_as_i64), )?, }; match payments_response { types::PaymentsResponseData::PreProcessingResponse { pre_processing_id, connector_metadata, connector_response_reference_id, .. } => { let connector_transaction_id = match pre_processing_id.to_owned() { types::PreprocessingResponseId::PreProcessingId(_) => None, types::PreprocessingResponseId::ConnectorTransactionId( connector_txn_id, ) => Some(connector_txn_id), }; let preprocessing_step_id = match pre_processing_id { types::PreprocessingResponseId::PreProcessingId( pre_processing_id, ) => Some(pre_processing_id), types::PreprocessingResponseId::ConnectorTransactionId(_) => None, }; let payment_attempt_update = storage::PaymentAttemptUpdate::PreprocessingUpdate { status: updated_attempt_status, payment_method_id: payment_data .payment_attempt .payment_method_id .clone(), connector_metadata, preprocessing_step_id, connector_transaction_id, connector_response_reference_id, updated_by: storage_scheme.to_string(), }; (None, Some(payment_attempt_update), None) } types::PaymentsResponseData::TransactionResponse { resource_id, redirection_data, connector_metadata, connector_response_reference_id, incremental_authorization_allowed, charges, .. } => { payment_data .payment_intent .incremental_authorization_allowed = core_utils::get_incremental_authorization_allowed_value( incremental_authorization_allowed, payment_data .payment_intent .request_incremental_authorization, ); let connector_transaction_id = match resource_id { types::ResponseId::NoResponseId => None, types::ResponseId::ConnectorTransactionId(ref id) | types::ResponseId::EncodedData(ref id) => Some(id), }; let resp_network_transaction_id = router_data.response.as_ref() .map_err(|err| { logger::error!(error = ?err, "Failed to obtain the network_transaction_id from payment response"); }) .ok() .and_then(|resp| resp.get_network_transaction_id()); let encoded_data = payment_data.payment_attempt.encoded_data.clone(); let authentication_data = (*redirection_data) .as_ref() .map(Encode::encode_to_value) .transpose() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not parse the connector response")?; let auth_update = if Some(router_data.auth_type) != payment_data.payment_attempt.authentication_type { Some(router_data.auth_type) } else { None }; // incase of success, update error code and error message let error_status = if router_data.status == enums::AttemptStatus::Charged { Some(None) } else { None }; // update connector_mandate_details in case of Authorized/Charged Payment Status if matches!( router_data.status, enums::AttemptStatus::Charged | enums::AttemptStatus::Authorized | enums::AttemptStatus::PartiallyAuthorized ) { payment_data .payment_intent .fingerprint_id .clone_from(&payment_data.payment_attempt.fingerprint_id); if let Some(payment_method) = payment_data.payment_method_info.clone() { // Parse value to check for mandates' existence let mandate_details = payment_method .get_common_mandate_reference() .change_context( errors::ApiErrorResponse::InternalServerError, ) .attach_printable( "Failed to deserialize to Payment Mandate Reference ", )?; if let Some(mca_id) = payment_data.payment_attempt.merchant_connector_id.clone() { // check if the mandate has not already been set to active if !mandate_details.payments .as_ref() .and_then(|payments| payments.0.get(&mca_id)) .map(|payment_mandate_reference_record| payment_mandate_reference_record.connector_mandate_status == Some(common_enums::ConnectorMandateStatus::Active)) .unwrap_or(false) { let (connector_mandate_id, mandate_metadata,connector_mandate_request_reference_id) = payment_data.payment_attempt.connector_mandate_detail.clone() .map(|cmr| (cmr.connector_mandate_id, cmr.mandate_metadata,cmr.connector_mandate_request_reference_id)) .unwrap_or((None, None,None)); // Update the connector mandate details with the payment attempt connector mandate id let connector_mandate_details = tokenization::update_connector_mandate_details( Some(mandate_details), payment_data.payment_attempt.payment_method_type, Some( payment_data .payment_attempt .net_amount .get_total_amount() .get_amount_as_i64(), ), payment_data.payment_attempt.currency, payment_data.payment_attempt.merchant_connector_id.clone(), connector_mandate_id, mandate_metadata, connector_mandate_request_reference_id )?; // Update the payment method table with the active mandate record payment_methods::cards::update_payment_method_connector_mandate_details( state, key_store, &*state.store, payment_method, connector_mandate_details, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to update payment method in db")?; } } } metrics::SUCCESSFUL_PAYMENT.add(1, &[]); } let payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); let debit_routing_savings = payment_data.payment_method_data.as_ref().and_then(|data| { payments_helpers::get_debit_routing_savings_amount( data, &payment_data.payment_attempt, ) }); utils::add_apple_pay_payment_status_metrics( router_data.status, router_data.apple_pay_flow.clone(), payment_data.payment_attempt.connector.clone(), payment_data.payment_attempt.merchant_id.clone(), ); let is_overcapture_enabled = router_data .connector_response .as_ref() .and_then(|connector_response| { connector_response.is_overcapture_enabled() }).or_else(|| { payment_data.payment_intent .enable_overcapture .as_ref() .map(|enable_overcapture| common_types::primitive_wrappers::OvercaptureEnabledBool::new(*enable_overcapture.deref())) }); let (capture_before, extended_authorization_applied) = router_data .connector_response .as_ref() .and_then(|connector_response| { connector_response.get_extended_authorization_response_data() }) .map(|extended_auth_resp| { ( extended_auth_resp.capture_before, extended_auth_resp.extended_authentication_applied, ) }) .unwrap_or((None, None)); let (capture_updates, payment_attempt_update) = match payment_data .multiple_capture_data { Some(multiple_capture_data) => { let (connector_capture_id, processor_capture_data) = match resource_id { types::ResponseId::NoResponseId => (None, None), types::ResponseId::ConnectorTransactionId(id) | types::ResponseId::EncodedData(id) => { let (txn_id, txn_data) = ConnectorTransactionId::form_id_and_data(id); (Some(txn_id), txn_data) } }; let capture_update = storage::CaptureUpdate::ResponseUpdate { status: enums::CaptureStatus::foreign_try_from( router_data.status, )?, connector_capture_id: connector_capture_id.clone(), connector_response_reference_id, processor_capture_data: processor_capture_data.clone(), }; let capture_update_list = vec![( multiple_capture_data.get_latest_capture().clone(), capture_update, )]; (Some((multiple_capture_data, capture_update_list)), auth_update.map(|auth_type| { storage::PaymentAttemptUpdate::AuthenticationTypeUpdate { authentication_type: auth_type, updated_by: storage_scheme.to_string(), } })) } None => ( None, Some(storage::PaymentAttemptUpdate::ResponseUpdate { status: updated_attempt_status, connector: None, connector_transaction_id: connector_transaction_id.cloned(), authentication_type: auth_update, amount_capturable: router_data .request .get_amount_capturable( &payment_data, router_data .minor_amount_capturable .map(MinorUnit::get_amount_as_i64), updated_attempt_status, ) .map(MinorUnit::new), payment_method_id, mandate_id: payment_data.payment_attempt.mandate_id.clone(), connector_metadata, payment_token: None, error_code: error_status.clone(), error_message: error_status.clone(), error_reason: error_status.clone(), unified_code: error_status.clone(), unified_message: error_status, connector_response_reference_id, updated_by: storage_scheme.to_string(), authentication_data, encoded_data, payment_method_data: additional_payment_method_data, capture_before, extended_authorization_applied, connector_mandate_detail: payment_data .payment_attempt .connector_mandate_detail .clone(), charges, setup_future_usage_applied: payment_data .payment_attempt .setup_future_usage_applied, debit_routing_savings, network_transaction_id: resp_network_transaction_id, is_overcapture_enabled, authorized_amount: router_data.authorized_amount, }), ), }; (capture_updates, payment_attempt_update, None) } types::PaymentsResponseData::TransactionUnresolvedResponse { resource_id, reason, connector_response_reference_id, } => { let connector_transaction_id = match resource_id { types::ResponseId::NoResponseId => None, types::ResponseId::ConnectorTransactionId(id) | types::ResponseId::EncodedData(id) => Some(id), }; ( None, Some(storage::PaymentAttemptUpdate::UnresolvedResponseUpdate { status: updated_attempt_status, connector: None, connector_transaction_id, payment_method_id: payment_data .payment_attempt .payment_method_id .clone(), error_code: Some(reason.clone().map(|cd| cd.code)), error_message: Some(reason.clone().map(|cd| cd.message)), error_reason: Some(reason.map(|cd| cd.message)), connector_response_reference_id, updated_by: storage_scheme.to_string(), }), None, ) } types::PaymentsResponseData::SessionResponse { .. } => (None, None, None), types::PaymentsResponseData::SessionTokenResponse { .. } => { (None, None, None) } types::PaymentsResponseData::TokenizationResponse { .. } => { (None, None, None) } types::PaymentsResponseData::ConnectorCustomerResponse(..) => { (None, None, None) } types::PaymentsResponseData::ThreeDSEnrollmentResponse { .. } => { (None, None, None) } types::PaymentsResponseData::PostProcessingResponse { .. } => { (None, None, None) } types::PaymentsResponseData::IncrementalAuthorizationResponse { .. } => (None, None, None), types::PaymentsResponseData::PaymentResourceUpdateResponse { .. } => { (None, None, None) } types::PaymentsResponseData::MultipleCaptureResponse { capture_sync_response_list, } => match payment_data.multiple_capture_data { Some(multiple_capture_data) => { let capture_update_list = response_to_capture_update( &multiple_capture_data, capture_sync_response_list, )?; ( Some((multiple_capture_data, capture_update_list)), None, None, ) } None => (None, None, None), }, types::PaymentsResponseData::PaymentsCreateOrderResponse { .. } => { (None, None, None) } } } } } }; payment_data.multiple_capture_data = match capture_update { Some((mut multiple_capture_data, capture_updates)) => { for (capture, capture_update) in capture_updates { let updated_capture = state .store .update_capture_with_capture_id(capture, capture_update, storage_scheme) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; multiple_capture_data.update_capture(updated_capture); } let authorized_amount = payment_data .payment_attempt .authorized_amount .unwrap_or_else(|| payment_data.payment_attempt.get_total_amount()); payment_attempt_update = Some(storage::PaymentAttemptUpdate::AmountToCaptureUpdate { status: multiple_capture_data.get_attempt_status(authorized_amount), amount_capturable: authorized_amount - multiple_capture_data.get_total_blocked_amount(), updated_by: storage_scheme.to_string(), }); Some(multiple_capture_data) } None => None, }; // Stage 1 let payment_attempt = payment_data.payment_attempt.clone(); let m_db = state.clone().store; let m_payment_attempt_update = payment_attempt_update.clone(); let m_payment_attempt = payment_attempt.clone(); let payment_attempt = payment_attempt_update .map(|payment_attempt_update| { PaymentAttempt::from_storage_model( payment_attempt_update .to_storage_model() .apply_changeset(payment_attempt.clone().to_storage_model()), ) }) .unwrap_or_else(|| payment_attempt); let payment_attempt_fut = tokio::spawn( async move { Box::pin(async move { Ok::<_, error_stack::Report<errors::ApiErrorResponse>>( match m_payment_attempt_update { Some(payment_attempt_update) => m_db .update_payment_attempt_with_attempt_id( m_payment_attempt, payment_attempt_update, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?, None => m_payment_attempt, }, ) }) .await } .in_current_span(), ); payment_data.payment_attempt = payment_attempt; payment_data.authentication = match payment_data.authentication { Some(mut authentication_store) => { let authentication_update = storage::AuthenticationUpdate::PostAuthorizationUpdate { authentication_lifecycle_status: enums::AuthenticationLifecycleStatus::Used, }; let updated_authentication = state .store .update_authentication_by_merchant_id_authentication_id( authentication_store.authentication, authentication_update, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; authentication_store.authentication = updated_authentication; Some(authentication_store) } None => None, }; let amount_captured = get_total_amount_captured( &router_data.request, router_data.amount_captured.map(MinorUnit::new), router_data.status, &payment_data, ); let payment_intent_update = match &router_data.response { Err(_) => storage::PaymentIntentUpdate::PGStatusUpdate { status: api_models::enums::IntentStatus::foreign_from( payment_data.payment_attempt.status, ), updated_by: storage_scheme.to_string(), // make this false only if initial payment fails, if incremental authorization call fails don't make it false incremental_authorization_allowed: Some(false), feature_metadata: payment_data .payment_intent .feature_metadata .clone() .map(masking::Secret::new), }, Ok(_) => storage::PaymentIntentUpdate::ResponseUpdate { status: api_models::enums::IntentStatus::foreign_from( payment_data.payment_attempt.status, ), amount_captured, updated_by: storage_scheme.to_string(), fingerprint_id: payment_data.payment_attempt.fingerprint_id.clone(), incremental_authorization_allowed: payment_data .payment_intent .incremental_authorization_allowed, feature_metadata: payment_data .payment_intent .feature_metadata .clone() .map(masking::Secret::new), }, }; let m_db = state.clone().store; let m_key_store = key_store.clone(); let m_payment_data_payment_intent = payment_data.payment_intent.clone(); let m_payment_intent_update = payment_intent_update.clone(); let key_manager_state: KeyManagerState = state.into(); let payment_intent_fut = tokio::spawn( async move { m_db.update_payment_intent( &key_manager_state, m_payment_data_payment_intent, m_payment_intent_update, &m_key_store, storage_scheme, ) .map(|x| x.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)) .await } .in_current_span(), ); // When connector requires redirection for mandate creation it can update the connector mandate_id during Psync and CompleteAuthorize let m_db = state.clone().store; let m_router_data_merchant_id = router_data.merchant_id.clone(); let m_payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); let m_payment_data_mandate_id = payment_data .payment_attempt .mandate_id .clone() .or(payment_data .mandate_id .clone() .and_then(|mandate_ids| mandate_ids.mandate_id)); let m_router_data_response = router_data.response.clone(); let mandate_update_fut = tokio::spawn( async move { mandate::update_connector_mandate_id( m_db.as_ref(), &m_router_data_merchant_id, m_payment_data_mandate_id, m_payment_method_id, m_router_data_response, storage_scheme, ) .await } .in_current_span(), ); let (payment_intent, _, payment_attempt) = futures::try_join!( utils::flatten_join_error(payment_intent_fut), utils::flatten_join_error(mandate_update_fut), utils::flatten_join_error(payment_attempt_fut) )?; #[cfg(all(feature = "v1", feature = "dynamic_routing"))] { if payment_intent.status.is_in_terminal_state() && business_profile.dynamic_routing_algorithm.is_some() { let dynamic_routing_algo_ref: api_models::routing::DynamicRoutingAlgorithmRef = business_profile .dynamic_routing_algorithm .clone() .map(|val| val.parse_value("DynamicRoutingAlgorithmRef")) .transpose() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("unable to deserialize DynamicRoutingAlgorithmRef from JSON")? .ok_or(errors::ApiErrorResponse::InternalServerError) .attach_printable("DynamicRoutingAlgorithmRef not found in profile")?; let state = state.clone(); let profile_id = business_profile.get_id().to_owned(); let payment_attempt = payment_attempt.clone(); let dynamic_routing_config_params_interpolator = routing_helpers::DynamicRoutingConfigParamsInterpolator::new( payment_attempt.payment_method, payment_attempt.payment_method_type, payment_attempt.authentication_type, payment_attempt.currency, payment_data .address .get_payment_billing() .and_then(|address| address.clone().address) .and_then(|address| address.country), payment_attempt .payment_method_data .as_ref() .and_then(|data| data.as_object()) .and_then(|card| card.get("card")) .and_then(|data| data.as_object()) .and_then(|card| card.get("card_network")) .and_then(|network| network.as_str()) .map(|network| network.to_string()), payment_attempt .payment_method_data .as_ref() .and_then(|data| data.as_object()) .and_then(|card| card.get("card")) .and_then(|data| data.as_object()) .and_then(|card| card.get("card_isin")) .and_then(|card_isin| card_isin.as_str()) .map(|card_isin| card_isin.to_string()), ); tokio::spawn( async move { let should_route_to_open_router = state.conf.open_router.dynamic_routing_enabled; let is_success_rate_based = matches!( payment_attempt.routing_approach, Some(enums::RoutingApproach::SuccessRateExploitation) | Some(enums::RoutingApproach::SuccessRateExploration) ); if should_route_to_open_router && is_success_rate_based { routing_helpers::update_gateway_score_helper_with_open_router( &state, &payment_attempt, &profile_id, dynamic_routing_algo_ref.clone(), ) .await .map_err(|e| logger::error!(open_router_update_gateway_score_err=?e)) .ok(); } else { routing_helpers::push_metrics_with_update_window_for_success_based_routing( &state, &payment_attempt, routable_connectors.clone(), &profile_id, dynamic_routing_algo_ref.clone(), dynamic_routing_config_params_interpolator.clone(), ) .await .map_err(|e| logger::error!(success_based_routing_metrics_error=?e)) .ok(); if let Some(gsm_error_category) = gsm_error_category { if gsm_error_category.should_perform_elimination_routing() { logger::info!("Performing update window for elimination routing"); routing_helpers::update_window_for_elimination_routing( &state, &payment_attempt, &profile_id, dynamic_routing_algo_ref.clone(), dynamic_routing_config_params_interpolator.clone(), gsm_error_category, ) .await .map_err(|e| logger::error!(dynamic_routing_metrics_error=?e)) .ok(); }; }; routing_helpers::push_metrics_with_update_window_for_contract_based_routing( &state, &payment_attempt, routable_connectors, &profile_id, dynamic_routing_algo_ref, dynamic_routing_config_params_interpolator, ) .await .map_err(|e| logger::error!(contract_based_routing_metrics_error=?e)) .ok(); } } .in_current_span(), ); } } payment_data.payment_intent = payment_intent; payment_data.payment_attempt = payment_attempt; router_data.payment_method_status.and_then(|status| { payment_data .payment_method_info .as_mut() .map(|info| info.status = status) }); if payment_data.payment_attempt.status == enums::AttemptStatus::Failure { let _ = card_testing_guard_utils::increment_blocked_count_in_cache( state, payment_data.card_testing_guard_data.clone(), ) .await; } match router_data.integrity_check { Ok(()) => Ok(payment_data), Err(err) => { metrics::INTEGRITY_CHECK_FAILED.add( 1, router_env::metric_attributes!( ( "connector", payment_data .payment_attempt .connector .clone() .unwrap_or_default(), ), ( "merchant_id", payment_data.payment_attempt.merchant_id.clone(), ) ), ); Err(error_stack::Report::new( errors::ApiErrorResponse::IntegrityCheckFailed { connector_transaction_id: payment_data .payment_attempt .get_connector_payment_id() .map(ToString::to_string), reason: payment_data .payment_attempt .error_message .unwrap_or_default(), field_names: err.field_names, }, )) } } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 566, "total_crates": null }
fn_clm_router_update_tracker_-5816298866945945616
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_response // Implementation of PaymentResponse for PostUpdateTracker< F, hyperswitch_domain_models::payments::PaymentCancelData<F>, types::PaymentsCancelData, > async fn update_tracker<'b>( &'b self, state: &'b SessionState, mut payment_data: hyperswitch_domain_models::payments::PaymentCancelData<F>, router_data: types::RouterData<F, types::PaymentsCancelData, types::PaymentsResponseData>, key_store: &domain::MerchantKeyStore, storage_scheme: enums::MerchantStorageScheme, ) -> RouterResult<hyperswitch_domain_models::payments::PaymentCancelData<F>> where F: 'b + Send + Sync, types::RouterData<F, types::PaymentsCancelData, types::PaymentsResponseData>: hyperswitch_domain_models::router_data::TrackerPostUpdateObjects< F, types::PaymentsCancelData, hyperswitch_domain_models::payments::PaymentCancelData<F>, >, { let db = &*state.store; let key_manager_state = &state.into(); use hyperswitch_domain_models::router_data::TrackerPostUpdateObjects; let payment_intent_update = router_data.get_payment_intent_update(&payment_data, storage_scheme); let updated_payment_intent = db .update_payment_intent( key_manager_state, payment_data.payment_intent.clone(), payment_intent_update, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Error while updating the payment_intent")?; let payment_attempt_update = router_data.get_payment_attempt_update(&payment_data, storage_scheme); let updated_payment_attempt = db .update_payment_attempt( key_manager_state, key_store, payment_data.payment_attempt.clone(), payment_attempt_update, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Error while updating the payment_attempt")?; payment_data.set_payment_intent(updated_payment_intent); payment_data.set_payment_attempt(updated_payment_attempt); Ok(payment_data) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 58, "total_crates": null }
fn_clm_router_save_pm_and_mandate_-5816298866945945616
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_response // Implementation of PaymentResponse for PostUpdateTracker<F, PaymentConfirmData<F>, types::SetupMandateRequestData> async fn save_pm_and_mandate<'b>( &self, state: &SessionState, router_data: &types::RouterData< F, types::SetupMandateRequestData, types::PaymentsResponseData, >, merchant_context: &domain::MerchantContext, payment_data: &mut PaymentConfirmData<F>, business_profile: &domain::Profile, ) -> CustomResult<(), errors::ApiErrorResponse> where F: 'b + Clone + Send + Sync, { // If we received a payment_method_id from connector in the router data response // Then we either update the payment method or create a new payment method // The case for updating the payment method is when the payment is created from the payment method service let Ok(payments_response) = &router_data.response else { // In case there was an error response from the connector // We do not take any action related to the payment method return Ok(()); }; let connector_request_reference_id = payment_data .payment_attempt .connector_token_details .as_ref() .and_then(|token_details| token_details.get_connector_token_request_reference_id()); let connector_token = payments_response.get_updated_connector_token_details(connector_request_reference_id); let payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); // TODO: check what all conditions we will need to see if card need to be saved match ( connector_token .as_ref() .and_then(|connector_token| connector_token.connector_mandate_id.clone()), payment_method_id, ) { (Some(token), Some(payment_method_id)) => { if !matches!( router_data.status, enums::AttemptStatus::Charged | enums::AttemptStatus::Authorized ) { return Ok(()); } let connector_id = payment_data .payment_attempt .merchant_connector_id .clone() .get_required_value("merchant_connector_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("missing connector id")?; let net_amount = payment_data.payment_attempt.amount_details.get_net_amount(); let currency = payment_data.payment_intent.amount_details.currency; let connector_token_details_for_payment_method_update = api_models::payment_methods::ConnectorTokenDetails { connector_id, status: common_enums::ConnectorTokenStatus::Active, connector_token_request_reference_id: connector_token .and_then(|details| details.connector_token_request_reference_id), original_payment_authorized_amount: Some(net_amount), original_payment_authorized_currency: Some(currency), metadata: None, token: masking::Secret::new(token), token_type: common_enums::TokenizationType::MultiUse, }; let payment_method_update_request = api_models::payment_methods::PaymentMethodUpdate { payment_method_data: None, connector_token_details: Some( connector_token_details_for_payment_method_update, ), }; payment_methods::update_payment_method_core( state, merchant_context, business_profile, payment_method_update_request, &payment_method_id, ) .await .attach_printable("Failed to update payment method")?; } (Some(_), None) => { // TODO: create a new payment method } (None, Some(_)) | (None, None) => {} } Ok(()) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 48, "total_crates": null }
fn_clm_router_update_payment_method_status_and_ntid_-5816298866945945616
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_response async fn update_payment_method_status_and_ntid<F: Clone>( state: &SessionState, key_store: &domain::MerchantKeyStore, payment_data: &mut PaymentData<F>, attempt_status: common_enums::AttemptStatus, payment_response: Result<types::PaymentsResponseData, ErrorResponse>, storage_scheme: enums::MerchantStorageScheme, ) -> RouterResult<()> { // If the payment_method is deleted then ignore the error related to retrieving payment method // This should be handled when the payment method is soft deleted if let Some(id) = &payment_data.payment_attempt.payment_method_id { let payment_method = match state .store .find_payment_method(&(state.into()), key_store, id, storage_scheme) .await { Ok(payment_method) => payment_method, Err(error) => { if error.current_context().is_db_not_found() { logger::info!( "Payment Method not found in db and skipping payment method update {:?}", error ); return Ok(()); } else { Err(error) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Error retrieving payment method from db in update_payment_method_status_and_ntid")? } } }; let pm_resp_network_transaction_id = payment_response .map(|resp| if let types::PaymentsResponseData::TransactionResponse { network_txn_id: network_transaction_id, .. } = resp { network_transaction_id } else {None}) .map_err(|err| { logger::error!(error=?err, "Failed to obtain the network_transaction_id from payment response"); }) .ok() .flatten(); let network_transaction_id = if payment_data.payment_intent.setup_future_usage == Some(diesel_models::enums::FutureUsage::OffSession) { if pm_resp_network_transaction_id.is_some() { pm_resp_network_transaction_id } else { logger::info!("Skip storing network transaction id"); None } } else { None }; let pm_update = if payment_method.status != common_enums::PaymentMethodStatus::Active && payment_method.status != attempt_status.into() { let updated_pm_status = common_enums::PaymentMethodStatus::from(attempt_status); payment_data .payment_method_info .as_mut() .map(|info| info.status = updated_pm_status); storage::PaymentMethodUpdate::NetworkTransactionIdAndStatusUpdate { network_transaction_id, status: Some(updated_pm_status), } } else { storage::PaymentMethodUpdate::NetworkTransactionIdAndStatusUpdate { network_transaction_id, status: None, } }; state .store .update_payment_method( &(state.into()), key_store, payment_method, pm_update, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to update payment method in db")?; }; Ok(()) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 38, "total_crates": null }
fn_clm_router_to_post_update_tracker_-5816298866945945616
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_response // Implementation of PaymentResponse for Operation<F, types::PaymentsCancelData> fn to_post_update_tracker( &self, ) -> RouterResult< &(dyn PostUpdateTracker<F, Self::Data, types::PaymentsCancelData> + Send + Sync), > { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 29, "total_crates": null }
fn_clm_router_to_domain_-851885505216540177
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get_intent // Implementation of PaymentGetIntent for Operation<F, PaymentsGetIntentRequest> fn to_domain(&self) -> RouterResult<&dyn Domain<F, PaymentsGetIntentRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_update_trackers_-851885505216540177
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get_intent // Implementation of PaymentGetIntent for UpdateTracker<F, payments::PaymentIntentData<F>, PaymentsGetIntentRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: payments::PaymentIntentData<F>, _customer: Option<domain::Customer>, _storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<( PaymentsGetIntentOperation<'b, F>, payments::PaymentIntentData<F>, )> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_to_update_tracker_-851885505216540177
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get_intent // Implementation of PaymentGetIntent for Operation<F, PaymentsGetIntentRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, PaymentsGetIntentRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_get_trackers_-851885505216540177
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get_intent // Implementation of PaymentGetIntent for GetTracker<F, payments::PaymentIntentData<F>, PaymentsGetIntentRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, _payment_id: &common_utils::id_type::GlobalPaymentId, request: &PaymentsGetIntentRequest, merchant_context: &domain::MerchantContext, _profile: &domain::Profile, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<payments::PaymentIntentData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, &request.id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let payment_data = payments::PaymentIntentData { flow: PhantomData, payment_intent, // todo : add a way to fetch client secret if required client_secret: None, sessions_token: vec![], vault_session_details: None, connector_customer_id: None, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 51, "total_crates": null }
fn_clm_router_to_get_tracker_-851885505216540177
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_get_intent // Implementation of PaymentGetIntent for Operation<F, PaymentsGetIntentRequest> fn to_get_tracker( &self, ) -> RouterResult<&(dyn GetTracker<F, Self::Data, PaymentsGetIntentRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 44, "total_crates": null }
fn_clm_router_get_trackers_-4819489415947706670
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session // Implementation of PaymentSession for GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsSessionRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse<'a, F, api::PaymentsSessionRequest, PaymentData<F>>, > { let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let mut payment_intent = db .find_payment_intent_by_payment_id_merchant_id( &state.into(), &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // TODO (#7195): Add platform merchant account validation once publishable key auth is solved helpers::validate_payment_status_against_not_allowed_statuses( payment_intent.status, &[ storage_enums::IntentStatus::Failed, storage_enums::IntentStatus::Succeeded, ], "create a session token for", )?; helpers::authenticate_client_secret(Some(&request.client_secret), &payment_intent)?; let mut payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, payment_intent.active_attempt.get_id().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let currency = payment_intent.currency.get_required_value("currency")?; payment_attempt.payment_method = Some(storage_enums::PaymentMethod::Wallet); let amount = payment_attempt.get_total_amount().into(); let shipping_address = helpers::get_address_by_id( state, payment_intent.shipping_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let billing_address = helpers::get_address_by_id( state, payment_intent.billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let payment_method_billing = helpers::get_address_by_id( state, payment_attempt.payment_method_billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; payment_intent.shipping_address_id = shipping_address.clone().map(|x| x.address_id); payment_intent.billing_address_id = billing_address.clone().map(|x| x.address_id); let customer_details = payments::CustomerDetails { customer_id: payment_intent.customer_id.clone(), name: None, email: None, phone: None, phone_country_code: None, tax_registration_id: None, }; let creds_identifier = request .merchant_connector_details .as_ref() .map(|mcd| mcd.creds_identifier.to_owned()); request .merchant_connector_details .to_owned() .async_map(|mcd| async { helpers::insert_merchant_connector_creds_to_config( db, merchant_context.get_merchant_account().get_id(), mcd, ) .await }) .await .transpose()?; let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: None, mandate_id: None, mandate_connector: None, customer_acceptance: None, token: None, token_data: None, setup_mandate: None, address: payments::PaymentAddress::new( shipping_address.as_ref().map(From::from), billing_address.as_ref().map(From::from), payment_method_billing.as_ref().map(From::from), business_profile.use_billing_as_payment_method_billing, ), confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: Some(customer_details), payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 165, "total_crates": null }
fn_clm_router_get_connector_-4819489415947706670
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session // Implementation of Op for Domain<F, api::PaymentsSessionRequest, PaymentData<F>> /// Returns `SessionConnectorDatas` /// Steps carried out in this function /// Get all the `merchant_connector_accounts` which are not disabled /// Filter out connectors which have `invoke_sdk_client` enabled in `payment_method_types` /// If session token is requested for certain wallets only, then return them, else /// return all eligible connectors /// /// `GetToken` parameter specifies whether to get the session token from connector integration /// or from separate implementation ( for googlepay - from metadata and applepay - from metadata and call connector) async fn get_connector<'a>( &'a self, merchant_context: &domain::MerchantContext, state: &SessionState, request: &api::PaymentsSessionRequest, payment_intent: &storage::PaymentIntent, ) -> RouterResult<api::ConnectorChoice> { let db = &state.store; let all_connector_accounts = db .find_merchant_connector_account_by_merchant_id_and_disabled_list( &state.into(), merchant_context.get_merchant_account().get_id(), false, merchant_context.get_merchant_key_store(), ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Database error when querying for merchant connector accounts")?; let profile_id = payment_intent .profile_id .clone() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("profile_id is not set in payment_intent")?; let filtered_connector_accounts = all_connector_accounts .filter_based_on_profile_and_connector_type( &profile_id, common_enums::ConnectorType::PaymentProcessor, ); let requested_payment_method_types = request.wallets.clone(); let mut connector_and_supporting_payment_method_type = Vec::new(); filtered_connector_accounts .iter() .for_each(|connector_account| { let res = connector_account .payment_methods_enabled .clone() .unwrap_or_default() .into_iter() .map(|payment_methods_enabled| { payment_methods_enabled .parse_value::<PaymentMethodsEnabled>("payment_methods_enabled") }) .filter_map(|parsed_payment_method_result| { parsed_payment_method_result .inspect_err(|err| { logger::error!(session_token_parsing_error=?err); }) .ok() }) .flat_map(|parsed_payment_methods_enabled| { parsed_payment_methods_enabled .payment_method_types .unwrap_or_default() .into_iter() .filter(|payment_method_type| { let is_invoke_sdk_client = matches!( payment_method_type.payment_experience, Some(api_models::enums::PaymentExperience::InvokeSdkClient) ); // If session token is requested for the payment method type, // filter it out // if not, then create all sessions tokens let is_sent_in_request = requested_payment_method_types .contains(&payment_method_type.payment_method_type) || requested_payment_method_types.is_empty(); is_invoke_sdk_client && is_sent_in_request }) .map(|payment_method_type| { ( connector_account, payment_method_type.payment_method_type, parsed_payment_methods_enabled.payment_method, ) }) .collect::<Vec<_>>() }) .collect::<Vec<_>>(); connector_and_supporting_payment_method_type.extend(res); }); let mut session_connector_data = api::SessionConnectorDatas::with_capacity( connector_and_supporting_payment_method_type.len(), ); for (merchant_connector_account, payment_method_type, payment_method) in connector_and_supporting_payment_method_type { if let Ok(connector_data) = helpers::get_connector_data_with_token( state, merchant_connector_account.connector_name.to_string(), Some(merchant_connector_account.get_id()), payment_method_type, ) { #[cfg(feature = "v1")] { let new_session_connector_data = api::SessionConnectorData::new( payment_method_type, connector_data, merchant_connector_account.business_sub_label.clone(), payment_method, ); session_connector_data.push(new_session_connector_data) } #[cfg(feature = "v2")] { let new_session_connector_data = api::SessionConnectorData::new(payment_method_type, connector_data, None); session_connector_data.push(new_session_connector_data) } }; } Ok(api::ConnectorChoice::SessionMultiple( session_connector_data, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_update_trackers_-4819489415947706670
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session // Implementation of PaymentSession for UpdateTracker<F, PaymentData<F>, api::PaymentsSessionRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData<F>, _customer: Option<domain::Customer>, storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentSessionOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { let metadata = payment_data.payment_intent.metadata.clone(); payment_data.payment_intent = match metadata { Some(metadata) => state .store .update_payment_intent( &state.into(), payment_data.payment_intent, storage::PaymentIntentUpdate::MetadataUpdate { metadata, updated_by: storage_scheme.to_string(), }, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?, None => payment_data.payment_intent, }; Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 71, "total_crates": null }
fn_clm_router_validate_request_-4819489415947706670
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session // Implementation of PaymentSession for ValidateRequest<F, api::PaymentsSessionRequest, PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsSessionRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<(PaymentSessionOperation<'b, F>, operations::ValidateResult)> { //paymentid is already generated and should be sent in the request let given_payment_id = request.payment_id.clone(); Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(given_payment_id), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 46, "total_crates": null }
fn_clm_router_make_pm_data_-4819489415947706670
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session // Implementation of Op for Domain<F, api::PaymentsSessionRequest, PaymentData<F>> async fn make_pm_data<'b>( &'b self, _state: &'b SessionState, _payment_data: &mut PaymentData<F>, _storage_scheme: storage_enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, _customer: &Option<domain::Customer>, _business_profile: &domain::Profile, _should_retry_with_pan: bool, ) -> RouterResult<( PaymentSessionOperation<'b, F>, Option<domain::PaymentMethodData>, Option<String>, )> { //No payment method data for this operation Ok((Box::new(self), None, None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 25, "total_crates": null }
fn_clm_router_get_trackers_1146735318696729648
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/external_vault_proxy_payment_intent // Implementation of ExternalVaultProxyPaymentIntent for GetTracker<F, PaymentConfirmData<F>, ExternalVaultProxyPaymentsRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &common_utils::id_type::GlobalPaymentId, request: &ExternalVaultProxyPaymentsRequest, merchant_context: &domain::MerchantContext, _profile: &domain::Profile, header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<PaymentConfirmData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; self.validate_status_for_operation(payment_intent.status)?; let cell_id = state.conf.cell_information.id.clone(); let batch_encrypted_data = domain_types::crypto_operation( key_manager_state, common_utils::type_name!(hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt), domain_types::CryptoOperation::BatchEncrypt( hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt::to_encryptable( hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt { payment_method_billing_address: None, }, ), ), common_utils::types::keymanager::Identifier::Merchant(merchant_context.get_merchant_account().get_id().to_owned()), merchant_context.get_merchant_key_store().key.peek(), ) .await .and_then(|val| val.try_into_batchoperation()) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details".to_string())?; let encrypted_data = hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt::from_encryptable(batch_encrypted_data) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details")?; let payment_attempt = match payment_intent.active_attempt_id.clone() { Some(ref active_attempt_id) => db .find_payment_attempt_by_id( key_manager_state, merchant_context.get_merchant_key_store(), active_attempt_id, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Could not find payment attempt")?, None => { // TODO: Implement external vault specific payment attempt creation logic let payment_attempt_domain_model: hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt = hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt::external_vault_proxy_create_domain_model( &payment_intent, cell_id, storage_scheme, request, encrypted_data ) .await?; db.insert_payment_attempt( key_manager_state, merchant_context.get_merchant_key_store(), payment_attempt_domain_model, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not insert payment attempt")? } }; // TODO: Extract external vault specific token/credentials from request let processor_payment_token = None; // request.external_vault_details.processor_payment_token.clone(); let payment_address = hyperswitch_domain_models::payment_address::PaymentAddress::new( payment_intent .shipping_address .clone() .map(|address| address.into_inner()), payment_intent .billing_address .clone() .map(|address| address.into_inner()), payment_attempt .payment_method_billing_address .clone() .map(|address| address.into_inner()), Some(true), ); // TODO: Implement external vault specific mandate data handling let mandate_data_input = api_models::payments::MandateIds { mandate_id: None, mandate_reference_id: processor_payment_token.map(|token| { api_models::payments::MandateReferenceId::ConnectorMandateId( api_models::payments::ConnectorMandateReferenceId::new( Some(token), None, None, None, None, ), ) }), }; let payment_method_data = request.payment_method_data.payment_method_data.clone().map( hyperswitch_domain_models::payment_method_data::ExternalVaultPaymentMethodData::from, ); let payment_data = PaymentConfirmData { flow: std::marker::PhantomData, payment_intent, payment_attempt, payment_method_data: None, // TODO: Review for external vault payment_address, mandate_data: Some(mandate_data_input), payment_method: None, merchant_connector_details: None, external_vault_pmd: payment_method_data, webhook_url: None, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 139, "total_crates": null }
fn_clm_router_update_trackers_1146735318696729648
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/external_vault_proxy_payment_intent // Implementation of ExternalVaultProxyPaymentIntent for UpdateTracker<F, PaymentConfirmData<F>, ExternalVaultProxyPaymentsRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentConfirmData<F>, _customer: Option<domain::Customer>, storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<api_models::enums::FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(BoxedConfirmOperation<'b, F>, PaymentConfirmData<F>)> where F: 'b + Send, { let db = &*state.store; let key_manager_state = &state.into(); let intent_status = common_enums::IntentStatus::Processing; let attempt_status = common_enums::AttemptStatus::Pending; let connector = payment_data .payment_attempt .connector .clone() .get_required_value("connector") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Connector is none when constructing response")?; let merchant_connector_id = Some( payment_data .payment_attempt .merchant_connector_id .clone() .get_required_value("merchant_connector_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Merchant connector id is none when constructing response")?, ); let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::ConfirmIntent { status: intent_status, updated_by: storage_scheme.to_string(), active_attempt_id: Some(payment_data.payment_attempt.id.clone()), }; let authentication_type = payment_data .payment_intent .authentication_type .unwrap_or_default(); let connector_request_reference_id = payment_data .payment_attempt .connector_request_reference_id .clone(); let connector_response_reference_id = payment_data .payment_attempt .connector_response_reference_id .clone(); let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ConfirmIntent { status: attempt_status, updated_by: storage_scheme.to_string(), connector, merchant_connector_id, authentication_type, connector_request_reference_id, connector_response_reference_id, }; let updated_payment_intent = db .update_payment_intent( key_manager_state, payment_data.payment_intent.clone(), payment_intent_update, key_store, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Unable to update payment intent")?; payment_data.payment_intent = updated_payment_intent; let updated_payment_attempt = db .update_payment_attempt( key_manager_state, key_store, payment_data.payment_attempt.clone(), payment_attempt_update, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Unable to update payment attempt")?; payment_data.payment_attempt = updated_payment_attempt; Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 107, "total_crates": null }
fn_clm_router_update_payment_method_1146735318696729648
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/external_vault_proxy_payment_intent // Implementation of ExternalVaultProxyPaymentIntent for Domain<F, ExternalVaultProxyPaymentsRequest, PaymentConfirmData<F>> async fn update_payment_method<'a>( &'a self, state: &SessionState, merchant_context: &domain::MerchantContext, payment_data: &mut PaymentConfirmData<F>, ) { if let (true, Some(payment_method)) = ( payment_data.payment_attempt.customer_acceptance.is_some(), payment_data.payment_method.as_ref(), ) { payment_methods::update_payment_method_status_internal( state, merchant_context.get_merchant_key_store(), merchant_context.get_merchant_account().storage_scheme, common_enums::PaymentMethodStatus::Active, payment_method.get_id(), ) .await .map_err(|err| router_env::logger::error!(err=?err)); }; }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 100, "total_crates": null }
fn_clm_router_to_domain_1146735318696729648
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/external_vault_proxy_payment_intent // Implementation of ExternalVaultProxyPaymentIntent for Operation<F, ExternalVaultProxyPaymentsRequest> fn to_domain( &self, ) -> RouterResult<&dyn Domain<F, ExternalVaultProxyPaymentsRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_to_update_tracker_1146735318696729648
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/external_vault_proxy_payment_intent // Implementation of ExternalVaultProxyPaymentIntent for Operation<F, ExternalVaultProxyPaymentsRequest> fn to_update_tracker( &self, ) -> RouterResult< &(dyn UpdateTracker<F, Self::Data, ExternalVaultProxyPaymentsRequest> + Send + Sync), > { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_get_trackers_-3045300143717224678
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_post_session_tokens // Implementation of PaymentPostSessionTokens for GetTracker<F, PaymentData<F>, api::PaymentsPostSessionTokensRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsPostSessionTokensRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse< 'a, F, api::PaymentsPostSessionTokensRequest, PaymentData<F>, >, > { let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; let db = &*state.store; let key_manager_state: &KeyManagerState = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_payment_id_merchant_id( &state.into(), &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // TODO (#7195): Add platform merchant account validation once publishable key auth is solved helpers::authenticate_client_secret(Some(request.client_secret.peek()), &payment_intent)?; let mut payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, payment_intent.active_attempt.get_id().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let currency = payment_intent.currency.get_required_value("currency")?; let amount = payment_attempt.get_total_amount().into(); let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; payment_attempt.payment_method = Some(request.payment_method); payment_attempt.payment_method_type = Some(request.payment_method_type); let shipping_address = helpers::get_address_by_id( state, payment_intent.shipping_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let billing_address = helpers::get_address_by_id( state, payment_intent.billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: None, mandate_id: None, mandate_connector: None, customer_acceptance: None, token: None, token_data: None, setup_mandate: None, address: payments::PaymentAddress::new( shipping_address.as_ref().map(From::from), billing_address.as_ref().map(From::from), None, business_profile.use_billing_as_payment_method_billing, ), confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: None, payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 125, "total_crates": null }
fn_clm_router_update_trackers_-3045300143717224678
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_post_session_tokens // Implementation of PaymentPostSessionTokens for UpdateTracker<F, PaymentData<F>, api::PaymentsPostSessionTokensRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData<F>, _customer: Option<domain::Customer>, _storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentPostSessionTokensOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_validate_request_-3045300143717224678
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_post_session_tokens // Implementation of PaymentPostSessionTokens for ValidateRequest<F, api::PaymentsPostSessionTokensRequest, PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsPostSessionTokensRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<( PaymentPostSessionTokensOperation<'b, F>, operations::ValidateResult, )> { //payment id is already generated and should be sent in the request let given_payment_id = request.payment_id.clone(); Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(given_payment_id), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 46, "total_crates": null }
fn_clm_router_make_pm_data_-3045300143717224678
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_post_session_tokens // Implementation of PaymentPostSessionTokens for Domain<F, api::PaymentsPostSessionTokensRequest, PaymentData<F>> async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, _payment_data: &mut PaymentData<F>, _storage_scheme: storage_enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, _customer: &Option<domain::Customer>, _business_profile: &domain::Profile, _should_retry_with_pan: bool, ) -> RouterResult<( PaymentPostSessionTokensOperation<'a, F>, Option<domain::PaymentMethodData>, Option<String>, )> { Ok((Box::new(self), None, None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 25, "total_crates": null }
fn_clm_router_get_or_create_customer_details_-3045300143717224678
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_post_session_tokens // Implementation of PaymentPostSessionTokens for Domain<F, api::PaymentsPostSessionTokensRequest, PaymentData<F>> async fn get_or_create_customer_details<'a>( &'a self, _state: &SessionState, _payment_data: &mut PaymentData<F>, _request: Option<payments::CustomerDetails>, _merchant_key_store: &domain::MerchantKeyStore, _storage_scheme: storage_enums::MerchantStorageScheme, ) -> errors::CustomResult< ( PaymentPostSessionTokensOperation<'a, F>, Option<domain::Customer>, ), errors::StorageError, > { Ok((Box::new(self), None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 19, "total_crates": null }
fn_clm_router_get_trackers_-5674244578545538501
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_start // Implementation of PaymentStart for GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, _request: &api::PaymentsStartRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse<'a, F, api::PaymentsStartRequest, PaymentData<F>>, > { let (mut payment_intent, payment_attempt, currency, amount); let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; payment_intent = db .find_payment_intent_by_payment_id_merchant_id( key_manager_state, &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // TODO (#7195): Add platform merchant account validation once Merchant ID auth is solved helpers::validate_payment_status_against_not_allowed_statuses( payment_intent.status, &[ storage_enums::IntentStatus::Failed, storage_enums::IntentStatus::Succeeded, ], "update", )?; helpers::authenticate_client_secret( payment_intent.client_secret.as_ref(), &payment_intent, )?; payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, payment_intent.active_attempt.get_id().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; currency = payment_attempt.currency.get_required_value("currency")?; amount = payment_attempt.get_total_amount().into(); let shipping_address = helpers::get_address_by_id( state, payment_intent.shipping_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let billing_address = helpers::get_address_by_id( state, payment_intent.billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let payment_method_billing = helpers::get_address_by_id( state, payment_attempt.payment_method_billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let token_data = if let Some(token) = payment_attempt.payment_token.clone() { Some( helpers::retrieve_payment_token_data(state, token, payment_attempt.payment_method) .await?, ) } else { None }; payment_intent.shipping_address_id = shipping_address.clone().map(|i| i.address_id); payment_intent.billing_address_id = billing_address.clone().map(|i| i.address_id); let customer_details = CustomerDetails { customer_id: payment_intent.customer_id.clone(), ..CustomerDetails::default() }; let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { flow: PhantomData, payment_intent, currency, amount, email: None, mandate_id: None, mandate_connector: None, setup_mandate: None, customer_acceptance: None, token: payment_attempt.payment_token.clone(), address: PaymentAddress::new( shipping_address.as_ref().map(From::from), billing_address.as_ref().map(From::from), payment_method_billing.as_ref().map(From::from), business_profile.use_billing_as_payment_method_billing, ), token_data, confirm: Some(payment_attempt.confirm), payment_attempt, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: Some(customer_details), payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 155, "total_crates": null }
fn_clm_router_update_trackers_-5674244578545538501
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_start // Implementation of PaymentStart for UpdateTracker<F, PaymentData<F>, api::PaymentsStartRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData<F>, _customer: Option<domain::Customer>, _storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _mechant_key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentSessionOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_validate_request_-5674244578545538501
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_start // Implementation of PaymentStart for ValidateRequest<F, api::PaymentsStartRequest, PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsStartRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<(PaymentSessionOperation<'b, F>, operations::ValidateResult)> { let request_merchant_id = Some(&request.merchant_id); helpers::validate_merchant_id( merchant_context.get_merchant_account().get_id(), request_merchant_id, ) .change_context(errors::ApiErrorResponse::InvalidDataFormat { field_name: "merchant_id".to_string(), expected_format: "merchant_id from merchant account".to_string(), })?; let payment_id = request.payment_id.clone(); Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(payment_id), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 58, "total_crates": null }
fn_clm_router_make_pm_data_-5674244578545538501
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_start // Implementation of Op for Domain<F, api::PaymentsStartRequest, PaymentData<F>> async fn make_pm_data<'a>( &'a self, state: &'a SessionState, payment_data: &mut PaymentData<F>, storage_scheme: storage_enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, customer: &Option<domain::Customer>, business_profile: &domain::Profile, should_retry_with_pan: bool, ) -> RouterResult<( PaymentSessionOperation<'a, F>, Option<domain::PaymentMethodData>, Option<String>, )> { if payment_data .payment_attempt .connector .clone() .map(|connector_name| connector_name == *"bluesnap".to_string()) .unwrap_or(false) { Box::pin(helpers::make_pm_data( Box::new(self), state, payment_data, merchant_key_store, customer, storage_scheme, business_profile, should_retry_with_pan, )) .await } else { Ok((Box::new(self), None, None)) } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 39, "total_crates": null }
fn_clm_router_get_or_create_customer_details_-5674244578545538501
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_start // Implementation of Op for Domain<F, api::PaymentsStartRequest, PaymentData<F>> async fn get_or_create_customer_details<'a>( &'a self, state: &SessionState, payment_data: &mut PaymentData<F>, request: Option<CustomerDetails>, key_store: &domain::MerchantKeyStore, storage_scheme: common_enums::enums::MerchantStorageScheme, ) -> CustomResult< (PaymentSessionOperation<'a, F>, Option<domain::Customer>), errors::StorageError, > { helpers::create_customer_if_not_exist( state, Box::new(self), payment_data, request, &key_store.merchant_id, key_store, storage_scheme, ) .await }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 21, "total_crates": null }
fn_clm_router_to_domain_6256667103790768994
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session_intent // Implementation of PaymentSessionIntent for Operation<F, PaymentsSessionRequest> fn to_domain(&self) -> RouterResult<&dyn Domain<F, PaymentsSessionRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_perform_routing_6256667103790768994
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session_intent // Implementation of PaymentSessionIntent for Domain<F, PaymentsSessionRequest, payments::PaymentIntentData<F>> async fn perform_routing<'a>( &'a self, merchant_context: &domain::MerchantContext, business_profile: &domain::Profile, state: &SessionState, payment_data: &mut payments::PaymentIntentData<F>, ) -> CustomResult<api::ConnectorCallType, errors::ApiErrorResponse> { let db = &state.store; let all_connector_accounts = db .find_merchant_connector_account_by_merchant_id_and_disabled_list( &state.into(), merchant_context.get_merchant_account().get_id(), false, merchant_context.get_merchant_key_store(), ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Database error when querying for merchant connector accounts")?; let profile_id = business_profile.get_id(); let filtered_connector_accounts = all_connector_accounts .filter_based_on_profile_and_connector_type( profile_id, common_enums::ConnectorType::PaymentProcessor, ); let connector_and_supporting_payment_method_type = filtered_connector_accounts .get_connector_and_supporting_payment_method_type_for_session_call(); let session_connector_data: api::SessionConnectorDatas = connector_and_supporting_payment_method_type .into_iter() .filter_map( |(merchant_connector_account, payment_method_type, payment_method)| { match helpers::get_connector_data_with_token( state, merchant_connector_account.connector_name.to_string(), Some(merchant_connector_account.get_id()), payment_method_type, ) { Ok(connector_data) => Some(api::SessionConnectorData::new( payment_method_type, connector_data, None, payment_method, )), Err(err) => { logger::error!(session_token_error=?err); None } } }, ) .collect(); let session_token_routing_result = payments::perform_session_token_routing( state.clone(), business_profile, merchant_context.clone(), payment_data, session_connector_data, ) .await?; let pre_routing = storage::PaymentRoutingInfo { algorithm: None, pre_routing_results: Some((|| { let mut pre_routing_results: HashMap< common_enums::PaymentMethodType, storage::PreRoutingConnectorChoice, > = HashMap::new(); for (pm_type, routing_choice) in session_token_routing_result.routing_result { let mut routable_choice_list = vec![]; for choice in routing_choice { let routable_choice = api::routing::RoutableConnectorChoice { choice_kind: api::routing::RoutableChoiceKind::FullStruct, connector: choice .connector .connector_name .to_string() .parse::<common_enums::RoutableConnectors>() .change_context(errors::ApiErrorResponse::InternalServerError)?, merchant_connector_id: choice.connector.merchant_connector_id.clone(), }; routable_choice_list.push(routable_choice); } pre_routing_results.insert( pm_type, storage::PreRoutingConnectorChoice::Multiple(routable_choice_list), ); } Ok::<_, error_stack::Report<errors::ApiErrorResponse>>(pre_routing_results) })()?), }; // Store the routing results in payment intent payment_data.payment_intent.prerouting_algorithm = Some(pre_routing); Ok(api::ConnectorCallType::SessionMultiple( session_token_routing_result.final_result, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 73, "total_crates": null }
fn_clm_router_update_trackers_6256667103790768994
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session_intent // Implementation of PaymentSessionIntent for UpdateTracker<F, payments::PaymentIntentData<F>, PaymentsSessionRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, _req_state: ReqState, mut payment_data: payments::PaymentIntentData<F>, customer: Option<domain::Customer>, storage_scheme: enums::MerchantStorageScheme, updated_customer: Option<customer::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<common_enums::FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<( PaymentSessionOperation<'b, F>, payments::PaymentIntentData<F>, )> where F: 'b + Send, { let prerouting_algorithm = payment_data.payment_intent.prerouting_algorithm.clone(); payment_data.payment_intent = match prerouting_algorithm { Some(prerouting_algorithm) => state .store .update_payment_intent( &state.into(), payment_data.payment_intent, storage::PaymentIntentUpdate::SessionIntentUpdate { prerouting_algorithm, updated_by: storage_scheme.to_string(), }, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?, None => payment_data.payment_intent, }; Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 71, "total_crates": null }
fn_clm_router_to_update_tracker_6256667103790768994
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session_intent // Implementation of PaymentSessionIntent for Operation<F, PaymentsSessionRequest> fn to_update_tracker( &self, ) -> RouterResult< &(dyn UpdateTracker<F, payments::PaymentIntentData<F>, PaymentsSessionRequest> + Send + Sync), > { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_get_trackers_6256667103790768994
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_session_intent // Implementation of PaymentSessionIntent for GetTracker<F, payments::PaymentIntentData<F>, PaymentsSessionRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &common_utils::id_type::GlobalPaymentId, _request: &PaymentsSessionRequest, merchant_context: &domain::MerchantContext, _profile: &domain::Profile, header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<payments::PaymentIntentData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // TODO (#7195): Add platform merchant account validation once publishable key auth is solved self.validate_status_for_operation(payment_intent.status)?; let payment_data = payments::PaymentIntentData { flow: PhantomData, payment_intent, client_secret: None, sessions_token: vec![], vault_session_details: None, connector_customer_id: None, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 53, "total_crates": null }
fn_clm_router_get_trackers_-1309005924769836806
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_record // Implementation of PaymentAttemptRecord for GetTracker<F, PaymentAttemptRecordData<F>, PaymentsAttemptRecordRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &common_utils::id_type::GlobalPaymentId, request: &PaymentsAttemptRecordRequest, merchant_context: &domain::MerchantContext, _profile: &domain::Profile, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<PaymentAttemptRecordData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; self.validate_status_for_operation(payment_intent.status)?; let payment_method_billing_address = request .payment_method_data .as_ref() .and_then(|data| { data.billing .as_ref() .map(|address| address.clone().encode_to_value()) }) .transpose() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to encode payment_method_billing address")? .map(masking::Secret::new); let batch_encrypted_data = domain_types::crypto_operation( key_manager_state, common_utils::type_name!(hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt), domain_types::CryptoOperation::BatchEncrypt( hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt::to_encryptable( hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt { payment_method_billing_address, }, ), ), common_utils::types::keymanager::Identifier::Merchant(merchant_context.get_merchant_account().get_id().to_owned()), merchant_context.get_merchant_key_store().key.peek(), ) .await .and_then(|val| val.try_into_batchoperation()) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details".to_string())?; let encrypted_data = hyperswitch_domain_models::payments::payment_attempt::FromRequestEncryptablePaymentAttempt::from_encryptable(batch_encrypted_data) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details")?; let cell_id = state.conf.cell_information.id.clone(); let payment_attempt_domain_model = hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt::create_domain_model_using_record_request( &payment_intent, cell_id, storage_scheme, request, encrypted_data, ) .await?; let payment_attempt = db .insert_payment_attempt( key_manager_state, merchant_context.get_merchant_key_store(), payment_attempt_domain_model, storage_scheme, ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not insert payment attempt")?; let revenue_recovery_data = hyperswitch_domain_models::payments::RevenueRecoveryData { billing_connector_id: request.billing_connector_id.clone(), processor_payment_method_token: request.processor_payment_method_token.clone(), connector_customer_id: request.connector_customer_id.clone(), retry_count: request.retry_count, invoice_next_billing_time: request.invoice_next_billing_time, triggered_by: request.triggered_by, card_network: request.card_network.clone(), card_issuer: request.card_issuer.clone(), }; let payment_address = hyperswitch_domain_models::payment_address::PaymentAddress::new( payment_intent .shipping_address .clone() .map(|address| address.into_inner()), payment_intent .billing_address .clone() .map(|address| address.into_inner()), payment_attempt .payment_method_billing_address .clone() .map(|address| address.into_inner()), Some(true), ); let payment_data = PaymentAttemptRecordData { flow: PhantomData, payment_intent, payment_attempt, payment_address, revenue_recovery_data, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 149, "total_crates": null }
fn_clm_router_to_domain_-1309005924769836806
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_record // Implementation of None for Operation<F, PaymentsAttemptRecordRequest> fn to_domain( &self, ) -> RouterResult<&(dyn Domain<F, PaymentsAttemptRecordRequest, Self::Data>)> { Ok(*self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_update_trackers_-1309005924769836806
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_record // Implementation of PaymentAttemptRecord for UpdateTracker<F, PaymentAttemptRecordData<F>, PaymentsAttemptRecordRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentAttemptRecordData<F>, _customer: Option<domain::Customer>, storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<( PaymentsAttemptRecordOperation<'b, F>, PaymentAttemptRecordData<F>, )> where F: 'b + Send, { let feature_metadata = payment_data.get_updated_feature_metadata()?; let active_attempt_id = match payment_data.revenue_recovery_data.triggered_by { common_enums::TriggeredBy::Internal => Some(payment_data.payment_attempt.id.clone()), common_enums::TriggeredBy::External => None, }; let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::RecordUpdate { status: common_enums::IntentStatus::from(payment_data.payment_attempt.status), feature_metadata: Box::new(feature_metadata), updated_by: storage_scheme.to_string(), active_attempt_id } ; payment_data.payment_intent = state .store .update_payment_intent( &state.into(), payment_data.payment_intent, payment_intent_update, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 77, "total_crates": null }
fn_clm_router_to_update_tracker_-1309005924769836806
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_record // Implementation of None for Operation<F, PaymentsAttemptRecordRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, PaymentsAttemptRecordRequest> + Send + Sync)> { Ok(*self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_validate_status_for_operation_-1309005924769836806
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_record // Implementation of PaymentAttemptRecord for ValidateStatusForOperation fn validate_status_for_operation( &self, intent_status: common_enums::IntentStatus, ) -> Result<(), errors::ApiErrorResponse> { // need to verify this? match intent_status { // Payment attempt can be recorded for failed payment as well in revenue recovery flow. common_enums::IntentStatus::RequiresPaymentMethod | common_enums::IntentStatus::Failed => Ok(()), common_enums::IntentStatus::Succeeded | common_enums::IntentStatus::Cancelled | common_enums::IntentStatus::CancelledPostCapture | common_enums::IntentStatus::Processing | common_enums::IntentStatus::Conflicted | common_enums::IntentStatus::RequiresCustomerAction | common_enums::IntentStatus::RequiresMerchantAction | common_enums::IntentStatus::RequiresCapture | common_enums::IntentStatus::PartiallyAuthorizedAndRequiresCapture | common_enums::IntentStatus::PartiallyCaptured | common_enums::IntentStatus::RequiresConfirmation | common_enums::IntentStatus::PartiallyCapturedAndCapturable | common_enums::IntentStatus::Expired => { Err(errors::ApiErrorResponse::PaymentUnexpectedState { current_flow: format!("{self:?}"), field_name: "status".to_string(), current_value: intent_status.to_string(), states: [ common_enums::IntentStatus::RequiresPaymentMethod, common_enums::IntentStatus::Failed, ] .map(|enum_value| enum_value.to_string()) .join(", "), }) } } }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 45, "total_crates": null }
fn_clm_router_to_domain_2749888314861745634
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_v2 // Implementation of PaymentsCancel for Operation<F, api::PaymentsCancelRequest> fn to_domain(&self) -> RouterResult<&dyn Domain<F, api::PaymentsCancelRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_get_trackers_2749888314861745634
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_v2 // Implementation of PaymentsCancel for GetTracker< F, hyperswitch_domain_models::payments::PaymentCancelData<F>, api::PaymentsCancelRequest, > async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &common_utils::id_type::GlobalPaymentId, request: &api::PaymentsCancelRequest, merchant_context: &domain::MerchantContext, profile: &domain::Profile, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse<hyperswitch_domain_models::payments::PaymentCancelData<F>>, > { let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_intent = db .find_payment_intent_by_id( key_manager_state, payment_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Failed to find payment intent for cancellation")?; self.validate_status_for_operation(payment_intent.status)?; let active_attempt_id = payment_intent.active_attempt_id.as_ref().ok_or_else(|| { errors::ApiErrorResponse::InvalidRequestData { message: "Payment cancellation not possible - no active payment attempt found" .to_string(), } })?; let payment_attempt = db .find_payment_attempt_by_id( key_manager_state, merchant_context.get_merchant_key_store(), active_attempt_id, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Failed to find payment attempt for cancellation")?; let mut payment_data = hyperswitch_domain_models::payments::PaymentCancelData { flow: PhantomData, payment_intent, payment_attempt, }; payment_data.set_cancellation_reason(request.cancellation_reason.clone()); let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 77, "total_crates": null }
fn_clm_router_update_trackers_2749888314861745634
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_v2 // Implementation of PaymentsCancel for UpdateTracker< F, hyperswitch_domain_models::payments::PaymentCancelData<F>, api::PaymentsCancelRequest, > async fn update_trackers<'b>( &'b self, state: &'b SessionState, req_state: ReqState, mut payment_data: hyperswitch_domain_models::payments::PaymentCancelData<F>, _customer: Option<domain::Customer>, storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, merchant_key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<( BoxedCancelOperation<'b, F>, hyperswitch_domain_models::payments::PaymentCancelData<F>, )> where F: 'b + Send, { let db = &*state.store; let key_manager_state = &state.into(); let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::VoidUpdate { status: enums::AttemptStatus::VoidInitiated, cancellation_reason: payment_data.payment_attempt.cancellation_reason.clone(), updated_by: storage_scheme.to_string(), }; let updated_payment_attempt = db .update_payment_attempt( key_manager_state, merchant_key_store, payment_data.payment_attempt.clone(), payment_attempt_update, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) .attach_printable("Failed to update payment attempt for cancellation")?; payment_data.set_payment_attempt(updated_payment_attempt); Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 77, "total_crates": null }
fn_clm_router_to_update_tracker_2749888314861745634
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_v2 // Implementation of PaymentsCancel for Operation<F, api::PaymentsCancelRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, api::PaymentsCancelRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_perform_routing_2749888314861745634
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_v2 // Implementation of PaymentsCancel for Domain<F, api::PaymentsCancelRequest, hyperswitch_domain_models::payments::PaymentCancelData<F>> async fn perform_routing<'a>( &'a self, _merchant_context: &domain::MerchantContext, _business_profile: &domain::Profile, state: &SessionState, payment_data: &mut hyperswitch_domain_models::payments::PaymentCancelData<F>, ) -> RouterResult<api::ConnectorCallType> { let payment_attempt = &payment_data.payment_attempt; let connector = payment_attempt .connector .as_ref() .get_required_value("connector") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Connector not found for payment cancellation")?; let merchant_connector_id = payment_attempt .merchant_connector_id .as_ref() .get_required_value("merchant_connector_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Merchant connector ID not found for payment cancellation")?; let connector_data = api::ConnectorData::get_connector_by_name( &state.conf.connectors, connector, api::GetToken::Connector, Some(merchant_connector_id.to_owned()), ) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Invalid connector name received")?; Ok(api::ConnectorCallType::PreDetermined(connector_data.into())) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 45, "total_crates": null }
fn_clm_router_to_domain_8357384470270917935
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_list // Implementation of PaymentGetListAttempts for Operation<F, PaymentAttemptListRequest> fn to_domain(&self) -> RouterResult<&(dyn Domain<F, PaymentAttemptListRequest, Self::Data>)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_update_trackers_8357384470270917935
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_list // Implementation of PaymentGetListAttempts for UpdateTracker<F, payments::PaymentAttemptListData<F>, PaymentAttemptListRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: payments::PaymentAttemptListData<F>, _customer: Option<domain::Customer>, _storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<( PaymentAttemptsListOperation<'b, F>, payments::PaymentAttemptListData<F>, )> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_to_update_tracker_8357384470270917935
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_list // Implementation of PaymentGetListAttempts for Operation<F, PaymentAttemptListRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, PaymentAttemptListRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_get_trackers_8357384470270917935
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_list // Implementation of PaymentGetListAttempts for GetTracker<F, payments::PaymentAttemptListData<F>, PaymentAttemptListRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, _payment_id: &common_utils::id_type::GlobalPaymentId, request: &PaymentAttemptListRequest, merchant_context: &domain::MerchantContext, _profile: &domain::Profile, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<payments::PaymentAttemptListData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_attempt_list = db .find_payment_attempts_by_payment_intent_id( key_manager_state, &request.payment_intent_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let payment_data = payments::PaymentAttemptListData { flow: PhantomData, payment_attempt_list, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 51, "total_crates": null }
fn_clm_router_to_get_tracker_8357384470270917935
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_attempt_list // Implementation of PaymentGetListAttempts for Operation<F, PaymentAttemptListRequest> fn to_get_tracker( &self, ) -> RouterResult<&(dyn GetTracker<F, Self::Data, PaymentAttemptListRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 44, "total_crates": null }
fn_clm_router_get_trackers_-8591524072475892681
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_post_capture // Implementation of PaymentCancelPostCapture for GetTracker<F, PaymentData<F>, api::PaymentsCancelPostCaptureRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsCancelPostCaptureRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult< operations::GetTrackerResponse< 'a, F, api::PaymentsCancelPostCaptureRequest, PaymentData<F>, >, > { let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; let payment_intent = db .find_payment_intent_by_payment_id_merchant_id( key_manager_state, &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; helpers::validate_payment_status_against_allowed_statuses( payment_intent.status, &[ enums::IntentStatus::Succeeded, enums::IntentStatus::PartiallyCaptured, enums::IntentStatus::PartiallyCapturedAndCapturable, ], "cancel_post_capture", )?; let mut payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, payment_intent.active_attempt.get_id().as_str(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let shipping_address = helpers::get_address_by_id( state, payment_intent.shipping_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let billing_address = helpers::get_address_by_id( state, payment_intent.billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let payment_method_billing = helpers::get_address_by_id( state, payment_attempt.payment_method_billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let currency = payment_attempt.currency.get_required_value("currency")?; let amount = payment_attempt.get_total_amount().into(); payment_attempt .cancellation_reason .clone_from(&request.cancellation_reason); let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: None, mandate_id: None, mandate_connector: None, setup_mandate: None, customer_acceptance: None, token: None, token_data: None, address: core_types::PaymentAddress::new( shipping_address.as_ref().map(From::from), billing_address.as_ref().map(From::from), payment_method_billing.as_ref().map(From::from), business_profile.use_billing_as_payment_method_billing, ), confirm: None, payment_method_data: None, payment_method_token: None, payment_method_info: None, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: None, creds_identifier: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, multiple_capture_data: None, redirect_response: None, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details: None, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: None, whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: false, }; let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details: None, payment_data, business_profile, mandate_type: None, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 135, "total_crates": null }
fn_clm_router_update_trackers_-8591524072475892681
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_post_capture // Implementation of PaymentCancelPostCapture for UpdateTracker<F, PaymentData<F>, api::PaymentsCancelPostCaptureRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData<F>, _customer: Option<domain::Customer>, _storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(PaymentCancelPostCaptureOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_validate_request_-8591524072475892681
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_post_capture // Implementation of PaymentCancelPostCapture for ValidateRequest<F, api::PaymentsCancelPostCaptureRequest, PaymentData<F>> fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCancelPostCaptureRequest, merchant_context: &'a domain::MerchantContext, ) -> RouterResult<( PaymentCancelPostCaptureOperation<'b, F>, operations::ValidateResult, )> { Ok(( Box::new(self), operations::ValidateResult { merchant_id: merchant_context.get_merchant_account().get_id().to_owned(), payment_id: api::PaymentIdType::PaymentIntentId(request.payment_id.to_owned()), storage_scheme: merchant_context.get_merchant_account().storage_scheme, requeue: false, }, )) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 46, "total_crates": null }
fn_clm_router_make_pm_data_-8591524072475892681
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_post_capture // Implementation of PaymentCancelPostCapture for Domain<F, api::PaymentsCancelPostCaptureRequest, PaymentData<F>> async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, _payment_data: &mut PaymentData<F>, _storage_scheme: enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, _customer: &Option<domain::Customer>, _business_profile: &domain::Profile, _should_retry_with_pan: bool, ) -> RouterResult<( PaymentCancelPostCaptureOperation<'a, F>, Option<domain::PaymentMethodData>, Option<String>, )> { Ok((Box::new(self), None, None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 25, "total_crates": null }
fn_clm_router_get_or_create_customer_details_-8591524072475892681
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_cancel_post_capture // Implementation of PaymentCancelPostCapture for Domain<F, api::PaymentsCancelPostCaptureRequest, PaymentData<F>> async fn get_or_create_customer_details<'a>( &'a self, _state: &SessionState, _payment_data: &mut PaymentData<F>, _request: Option<payments::CustomerDetails>, _merchant_key_store: &domain::MerchantKeyStore, _storage_scheme: enums::MerchantStorageScheme, ) -> errors::CustomResult< ( PaymentCancelPostCaptureOperation<'a, F>, Option<domain::Customer>, ), errors::StorageError, > { Ok((Box::new(self), None)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 19, "total_crates": null }
fn_clm_router_get_trackers_-6439515347345564038
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_create_intent // Implementation of PaymentIntentCreate for GetTracker<F, payments::PaymentIntentData<F>, PaymentsCreateIntentRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &common_utils::id_type::GlobalPaymentId, request: &PaymentsCreateIntentRequest, merchant_context: &domain::MerchantContext, profile: &domain::Profile, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<payments::PaymentIntentData<F>>> { let db = &*state.store; if let Some(routing_algorithm_id) = request.routing_algorithm_id.as_ref() { helpers::validate_routing_id_with_profile_id( db, routing_algorithm_id, profile.get_id(), ) .await?; } let key_manager_state = &state.into(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let batch_encrypted_data = domain_types::crypto_operation( key_manager_state, common_utils::type_name!(hyperswitch_domain_models::payments::PaymentIntent), domain_types::CryptoOperation::BatchEncrypt( hyperswitch_domain_models::payments::FromRequestEncryptablePaymentIntent::to_encryptable( hyperswitch_domain_models::payments::FromRequestEncryptablePaymentIntent { shipping_address: request.shipping.clone().map(|address| address.encode_to_value()).transpose().change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to encode shipping address")?.map(masking::Secret::new), billing_address: request.billing.clone().map(|address| address.encode_to_value()).transpose().change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to encode billing address")?.map(masking::Secret::new), customer_details: None, }, ), ), common_utils::types::keymanager::Identifier::Merchant(merchant_context.get_merchant_account().get_id().to_owned()), merchant_context.get_merchant_key_store().key.peek(), ) .await .and_then(|val| val.try_into_batchoperation()) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details".to_string())?; let encrypted_data = hyperswitch_domain_models::payments::FromRequestEncryptablePaymentIntent::from_encryptable(batch_encrypted_data) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while encrypting payment intent details")?; let payment_intent_domain = hyperswitch_domain_models::payments::PaymentIntent::create_domain_model_from_request( payment_id, merchant_context, profile, request.clone(), encrypted_data, ) .await?; let payment_intent = db .insert_payment_intent( key_manager_state, payment_intent_domain, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_duplicate_response(errors::ApiErrorResponse::GenericDuplicateError { message: format!( "Payment Intent with payment_id {} already exists", payment_id.get_string_repr() ), }) .attach_printable("failed while inserting new payment intent")?; let client_secret = helpers::create_client_secret( state, merchant_context.get_merchant_account().get_id(), authentication::ResourceId::Payment(payment_id.clone()), ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Unable to create client secret")?; let payment_data = payments::PaymentIntentData { flow: PhantomData, payment_intent, client_secret: Some(client_secret.secret), sessions_token: vec![], vault_session_details: None, connector_customer_id: None, }; let get_trackers_response = operations::GetTrackerResponse { payment_data }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 139, "total_crates": null }
fn_clm_router_to_domain_-6439515347345564038
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_create_intent // Implementation of PaymentIntentCreate for Operation<F, PaymentsCreateIntentRequest> fn to_domain(&self) -> RouterResult<&dyn Domain<F, PaymentsCreateIntentRequest, Self::Data>> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 92, "total_crates": null }
fn_clm_router_update_trackers_-6439515347345564038
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_create_intent // Implementation of PaymentIntentCreate for UpdateTracker<F, payments::PaymentIntentData<F>, PaymentsCreateIntentRequest> async fn update_trackers<'b>( &'b self, _state: &'b SessionState, _req_state: ReqState, payment_data: payments::PaymentIntentData<F>, _customer: Option<domain::Customer>, _storage_scheme: enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, _key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<( PaymentsCreateIntentOperation<'b, F>, payments::PaymentIntentData<F>, )> where F: 'b + Send, { Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 61, "total_crates": null }
fn_clm_router_to_update_tracker_-6439515347345564038
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_create_intent // Implementation of PaymentIntentCreate for Operation<F, PaymentsCreateIntentRequest> fn to_update_tracker( &self, ) -> RouterResult<&(dyn UpdateTracker<F, Self::Data, PaymentsCreateIntentRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 56, "total_crates": null }
fn_clm_router_to_get_tracker_-6439515347345564038
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_create_intent // Implementation of PaymentIntentCreate for Operation<F, PaymentsCreateIntentRequest> fn to_get_tracker( &self, ) -> RouterResult<&(dyn GetTracker<F, Self::Data, PaymentsCreateIntentRequest> + Send + Sync)> { Ok(self) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 44, "total_crates": null }
fn_clm_router_get_trackers_-522700410396971030
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_complete_authorize // Implementation of CompleteAuthorize for GetTracker<F, PaymentData<F>, api::PaymentsRequest> async fn get_trackers<'a>( &'a self, state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsRequest, merchant_context: &domain::MerchantContext, _auth_flow: services::AuthFlow, _header_payload: &hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<operations::GetTrackerResponse<'a, F, api::PaymentsRequest, PaymentData<F>>> { let db = &*state.store; let key_manager_state = &state.into(); let merchant_id = merchant_context.get_merchant_account().get_id(); let storage_scheme = merchant_context.get_merchant_account().storage_scheme; let (mut payment_intent, mut payment_attempt, currency, amount); let payment_id = payment_id .get_payment_intent_id() .change_context(errors::ApiErrorResponse::PaymentNotFound)?; payment_intent = db .find_payment_intent_by_payment_id_merchant_id( key_manager_state, &payment_id, merchant_id, merchant_context.get_merchant_key_store(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; // TODO (#7195): Add platform merchant account validation once client_secret auth is solved payment_intent.setup_future_usage = request .setup_future_usage .or(payment_intent.setup_future_usage); helpers::authenticate_client_secret(request.client_secret.as_ref(), &payment_intent)?; helpers::validate_payment_status_against_not_allowed_statuses( payment_intent.status, &[ storage_enums::IntentStatus::Failed, storage_enums::IntentStatus::Succeeded, ], "confirm", )?; let browser_info = request .browser_info .clone() .as_ref() .map(utils::Encode::encode_to_value) .transpose() .change_context(errors::ApiErrorResponse::InvalidDataValue { field_name: "browser_info", })?; let recurring_details = request.recurring_details.clone(); payment_attempt = db .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_intent.payment_id, merchant_id, &payment_intent.active_attempt.get_id(), storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; let mandate_type = m_helpers::get_mandate_type( request.mandate_data.clone(), request.off_session, payment_intent.setup_future_usage, request.customer_acceptance.clone(), request.payment_token.clone(), payment_attempt.payment_method, ) .change_context(errors::ApiErrorResponse::MandateValidationFailed { reason: "Expected one out of recurring_details and mandate_data but got both".into(), })?; let m_helpers::MandateGenericData { token, payment_method, payment_method_type, mandate_data, recurring_mandate_payment_data, mandate_connector, payment_method_info, } = Box::pin(helpers::get_token_pm_type_mandate_details( state, request, mandate_type.to_owned(), merchant_context, payment_attempt.payment_method_id.clone(), payment_intent.customer_id.as_ref(), )) .await?; let customer_acceptance: Option<CustomerAcceptance> = request.customer_acceptance.clone().or(payment_method_info .clone() .map(|pm| { pm.customer_acceptance .parse_value::<CustomerAcceptance>("CustomerAcceptance") }) .transpose() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to deserialize to CustomerAcceptance")?); let token = token.or_else(|| payment_attempt.payment_token.clone()); if let Some(payment_method) = payment_method { let should_validate_pm_or_token_given = //this validation should happen if data was stored in the vault helpers::should_store_payment_method_data_in_vault( &state.conf.temp_locker_enable_config, payment_attempt.connector.clone(), payment_method, ); if should_validate_pm_or_token_given { helpers::validate_pm_or_token_given( &request.payment_method, &request .payment_method_data .as_ref() .and_then(|pmd| pmd.payment_method_data.clone()), &request.payment_method_type, &mandate_type, &token, &request.ctp_service_details, )?; } } let token_data = if let Some((token, payment_method)) = token .as_ref() .zip(payment_method.or(payment_attempt.payment_method)) { Some( helpers::retrieve_payment_token_data(state, token.clone(), Some(payment_method)) .await?, ) } else { None }; payment_attempt.payment_method = payment_method.or(payment_attempt.payment_method); payment_attempt.browser_info = browser_info.or(payment_attempt.browser_info); payment_attempt.payment_method_type = payment_method_type.or(payment_attempt.payment_method_type); payment_attempt.payment_experience = request .payment_experience .or(payment_attempt.payment_experience); currency = payment_attempt.currency.get_required_value("currency")?; amount = payment_attempt.get_total_amount().into(); let customer_id = payment_intent .customer_id .as_ref() .or(request.customer_id.as_ref()) .cloned(); helpers::validate_customer_id_mandatory_cases( request.setup_future_usage.is_some(), customer_id.as_ref(), )?; let shipping_address = helpers::create_or_update_address_for_payment_by_request( state, request.shipping.as_ref(), payment_intent.shipping_address_id.clone().as_deref(), merchant_id, payment_intent.customer_id.as_ref(), merchant_context.get_merchant_key_store(), &payment_id, storage_scheme, ) .await?; payment_intent.shipping_address_id = shipping_address .as_ref() .map(|shipping_address| shipping_address.address_id.clone()); let billing_address = helpers::get_address_by_id( state, payment_intent.billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let payment_method_billing = helpers::get_address_by_id( state, payment_attempt.payment_method_billing_address_id.clone(), merchant_context.get_merchant_key_store(), &payment_intent.payment_id, merchant_id, merchant_context.get_merchant_account().storage_scheme, ) .await?; let redirect_response = request .feature_metadata .as_ref() .and_then(|fm| fm.redirect_response.clone()); payment_intent.shipping_address_id = shipping_address.clone().map(|i| i.address_id); payment_intent.billing_address_id = billing_address.clone().map(|i| i.address_id); payment_intent.return_url = request .return_url .as_ref() .map(|a| a.to_string()) .or(payment_intent.return_url); payment_intent.allowed_payment_method_types = request .get_allowed_payment_method_types_as_value() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Error converting allowed_payment_types to Value")? .or(payment_intent.allowed_payment_method_types); payment_intent.connector_metadata = request .get_connector_metadata_as_value() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Error converting connector_metadata to Value")? .or(payment_intent.connector_metadata); payment_intent.feature_metadata = request .get_feature_metadata_as_value() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Error converting feature_metadata to Value")? .or(payment_intent.feature_metadata); payment_intent.metadata = request.metadata.clone().or(payment_intent.metadata); // The operation merges mandate data from both request and payment_attempt let setup_mandate = mandate_data; let mandate_details_present = payment_attempt.mandate_details.is_some() || request.mandate_data.is_some(); helpers::validate_mandate_data_and_future_usage( payment_intent.setup_future_usage, mandate_details_present, )?; let profile_id = payment_intent .profile_id .as_ref() .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("'profile_id' not set in payment intent")?; let business_profile = db .find_business_profile_by_profile_id( key_manager_state, merchant_context.get_merchant_key_store(), profile_id, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; let creds_identifier = request .merchant_connector_details .as_ref() .map(|merchant_connector_details| { merchant_connector_details.creds_identifier.to_owned() }); let payment_data = PaymentData { flow: PhantomData, payment_intent, payment_attempt, currency, amount, email: request.email.clone(), mandate_id: None, mandate_connector, setup_mandate, customer_acceptance, token, token_data, address: PaymentAddress::new( shipping_address.as_ref().map(From::from), billing_address.as_ref().map(From::from), payment_method_billing.as_ref().map(From::from), business_profile.use_billing_as_payment_method_billing, ), confirm: request.confirm, payment_method_data: request .payment_method_data .as_ref() .and_then(|pmd| pmd.payment_method_data.clone().map(Into::into)), payment_method_token: None, payment_method_info, force_sync: None, all_keys_required: None, refunds: vec![], disputes: vec![], attempts: None, sessions_token: vec![], card_cvc: request.card_cvc.clone(), creds_identifier, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data, ephemeral_key: None, multiple_capture_data: None, redirect_response, surcharge_details: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], authentication: None, recurring_details, poll_config: None, tax_data: None, session_id: None, service_details: None, card_testing_guard_data: None, vault_operation: None, threeds_method_comp_ind: request.threeds_method_comp_ind.clone(), whole_connector_response: None, is_manual_retry_enabled: None, is_l2_l3_enabled: business_profile.is_l2_l3_enabled, }; let customer_details = Some(CustomerDetails { customer_id, name: request.name.clone(), email: request.email.clone(), phone: request.phone.clone(), phone_country_code: request.phone_country_code.clone(), tax_registration_id: None, }); let get_trackers_response = operations::GetTrackerResponse { operation: Box::new(self), customer_details, payment_data, business_profile, mandate_type, }; Ok(get_trackers_response) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 327, "total_crates": null }
fn_clm_router_update_trackers_-522700410396971030
clm
function
// Repository: hyperswitch // Crate: router // Purpose: Main application server handling HTTP requests, authentication, and business logic orchestration // Module: crates/router/src/core/payments/operations/payment_complete_authorize // Implementation of CompleteAuthorize for UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> async fn update_trackers<'b>( &'b self, state: &'b SessionState, req_state: ReqState, mut payment_data: PaymentData<F>, _customer: Option<domain::Customer>, storage_scheme: storage_enums::MerchantStorageScheme, _updated_customer: Option<storage::CustomerUpdate>, key_store: &domain::MerchantKeyStore, _frm_suggestion: Option<FrmSuggestion>, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, ) -> RouterResult<(CompleteAuthorizeOperation<'b, F>, PaymentData<F>)> where F: 'b + Send, { let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::CompleteAuthorizeUpdate { shipping_address_id: payment_data.payment_intent.shipping_address_id.clone() }; let db = &*state.store; let payment_intent = payment_data.payment_intent.clone(); let updated_payment_intent = db .update_payment_intent( &state.into(), payment_intent, payment_intent_update, key_store, storage_scheme, ) .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; req_state .event_context .event(AuditEvent::new(AuditEventType::PaymentCompleteAuthorize)) .with(payment_data.to_event()) .emit(); payment_data.payment_intent = updated_payment_intent; Ok((Box::new(self), payment_data)) }
{ "crate": "router", "file": null, "file_size": null, "is_async": false, "is_pub": false, "num_enums": null, "num_structs": null, "num_tables": null, "score": 81, "total_crates": null }