diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json index 8da8f56f70..76a35e926e 100644 --- a/api-reference/v2/openapi_spec_v2.json +++ b/api-reference/v2/openapi_spec_v2.json @@ -17881,41 +17881,6 @@ "propertyName": "payment_processing_details_at" } }, - "PaymentRetrieveBody": { - "type": "object", - "properties": { - "merchant_id": { - "type": "string", - "description": "The identifier for the Merchant Account.", - "nullable": true - }, - "force_sync": { - "type": "boolean", - "description": "Decider to enable or disable the connector call for retrieve request", - "nullable": true - }, - "client_secret": { - "type": "string", - "description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK", - "nullable": true - }, - "expand_captures": { - "type": "boolean", - "description": "If enabled provides list of captures linked to latest attempt", - "nullable": true - }, - "expand_attempts": { - "type": "boolean", - "description": "If enabled provides list of attempts linked to payment intent", - "nullable": true - }, - "all_keys_required": { - "type": "boolean", - "description": "If enabled, provides whole connector response", - "nullable": true - } - } - }, "PaymentRevenueRecoveryMetadata": { "type": "object", "required": [ @@ -18128,6 +18093,11 @@ } ], "nullable": true + }, + "return_raw_connector_response": { + "type": "boolean", + "description": "If true, returns stringified connector raw response body", + "nullable": true } }, "additionalProperties": false @@ -19127,6 +19097,11 @@ } ], "nullable": true + }, + "return_raw_connector_response": { + "type": "boolean", + "description": "Stringified connector raw response body. Only returned if `return_raw_connector_response` is true", + "nullable": true } }, "additionalProperties": false @@ -19311,6 +19286,11 @@ "nullable": true, "maxLength": 30, "minLength": 30 + }, + "raw_connector_response": { + "type": "string", + "description": "Stringified connector raw response body. Only returned if `return_raw_connector_response` is true", + "nullable": true } } }, @@ -19331,9 +19311,9 @@ "description": "These are the query params that are sent in case of redirect response.\nThese can be ingested by the connector to take necessary actions.", "nullable": true }, - "all_keys_required": { + "return_raw_connector_response": { "type": "boolean", - "description": "If enabled, provides whole connector response", + "description": "If true, returns stringified connector raw response body", "nullable": true }, "merchant_connector_details": { @@ -19394,9 +19374,9 @@ "description": "These are the query params that are sent in case of redirect response.\nThese can be ingested by the connector to take necessary actions.", "nullable": true }, - "all_keys_required": { + "return_raw_connector_response": { "type": "boolean", - "description": "If enabled, provides whole connector response", + "description": "If true, returns stringified connector raw response body", "nullable": true } } diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 2ff07472a0..9150697aa1 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -5347,6 +5347,9 @@ pub struct PaymentsConfirmIntentRequest { /// Merchant connector details used to make payments. #[schema(value_type = Option)] pub merchant_connector_details: Option, + + /// If true, returns stringified connector raw response body + pub return_raw_connector_response: Option, } #[cfg(feature = "v2")] @@ -5523,6 +5526,9 @@ pub struct PaymentsRequest { /// Merchant connector details used to make payments. #[schema(value_type = Option)] pub merchant_connector_details: Option, + + /// Stringified connector raw response body. Only returned if `return_raw_connector_response` is true + pub return_raw_connector_response: Option, } #[cfg(feature = "v2")] @@ -5575,6 +5581,7 @@ impl From<&PaymentsRequest> for PaymentsConfirmIntentRequest { payment_method_id: request.payment_method_id.clone(), payment_token: None, merchant_connector_details: request.merchant_connector_details.clone(), + return_raw_connector_response: request.return_raw_connector_response, } } } @@ -5597,8 +5604,8 @@ pub struct PaymentsRetrieveRequest { /// These are the query params that are sent in case of redirect response. /// These can be ingested by the connector to take necessary actions. pub param: Option, - /// If enabled, provides whole connector response - pub all_keys_required: Option, + /// If true, returns stringified connector raw response body + pub return_raw_connector_response: Option, /// Merchant connector details used to make payments. #[schema(value_type = Option)] pub merchant_connector_details: Option, @@ -5619,8 +5626,8 @@ pub struct PaymentsStatusRequest { /// These are the query params that are sent in case of redirect response. /// These can be ingested by the connector to take necessary actions. pub param: Option, - /// If enabled, provides whole connector response - pub all_keys_required: Option, + /// If true, returns stringified connector raw response body + pub return_raw_connector_response: Option, } /// Error details for the payment @@ -5776,6 +5783,9 @@ pub struct PaymentsResponse { example = "pay_mbabizu24mvu3mela5njyhpit4" )] pub merchant_reference_id: Option, + + /// Stringified connector raw response body. Only returned if `return_raw_connector_response` is true + pub raw_connector_response: Option, } #[cfg(feature = "v2")] @@ -7496,6 +7506,7 @@ pub struct PaymentsSessionResponse { pub vault_details: Option, } +#[cfg(feature = "v1")] #[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)] pub struct PaymentRetrieveBody { /// The identifier for the Merchant Account. @@ -7513,6 +7524,7 @@ pub struct PaymentRetrieveBody { pub all_keys_required: Option, } +#[cfg(feature = "v1")] #[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)] pub struct PaymentRetrieveBodyWithCredentials { /// The identifier for payment. diff --git a/crates/common_types/src/domain.rs b/crates/common_types/src/domain.rs index f41f874cd0..66ffa6029d 100644 --- a/crates/common_types/src/domain.rs +++ b/crates/common_types/src/domain.rs @@ -106,3 +106,11 @@ pub struct MerchantConnectorAuthDetails { }"#)] pub merchant_connector_creds: common_utils::pii::SecretSerdeValue, } + +/// Connector Response Data that are required to be populated in response +#[cfg(feature = "v2")] +#[derive(Clone, Debug)] +pub struct ConnectorResponseData { + /// Stringified connector raw response body + pub raw_connector_response: Option, +} diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index eeda9e7887..95bb5a875d 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -852,7 +852,7 @@ pub struct PaymentAttemptUpdateInternal { // payment_experience: Option, // preprocessing_step_id: Option, pub error_reason: Option, - // connector_response_reference_id: Option, + pub connector_response_reference_id: Option, // multiple_capture_count: Option, // pub surcharge_amount: Option, // tax_on_surcharge: Option, @@ -910,6 +910,7 @@ impl PaymentAttemptUpdateInternal { network_error_message, payment_method_id, connector_request_reference_id, + connector_response_reference_id, } = self; PaymentAttempt { @@ -939,7 +940,8 @@ impl PaymentAttemptUpdateInternal { preprocessing_step_id: source.preprocessing_step_id, error_reason: error_reason.or(source.error_reason), multiple_capture_count: source.multiple_capture_count, - connector_response_reference_id: source.connector_response_reference_id, + connector_response_reference_id: connector_response_reference_id + .or(source.connector_response_reference_id), amount_capturable: amount_capturable.unwrap_or(source.amount_capturable), updated_by, merchant_connector_id: merchant_connector_id.or(source.merchant_connector_id), diff --git a/crates/hyperswitch_connectors/src/connectors/razorpay.rs b/crates/hyperswitch_connectors/src/connectors/razorpay.rs index 39b83c73e4..33cdc32698 100644 --- a/crates/hyperswitch_connectors/src/connectors/razorpay.rs +++ b/crates/hyperswitch_connectors/src/connectors/razorpay.rs @@ -316,7 +316,7 @@ impl ConnectorIntegration CustomResult { Ok(format!( - "{}v1/payments/create/json", + "{}v1/payments/create/upi", self.base_url(connectors) )) } @@ -404,15 +404,15 @@ impl ConnectorIntegration for Raz req: &PaymentsSyncRouterData, connectors: &Connectors, ) -> CustomResult { - let connector_payment_id = req + let order_id = req .request - .connector_transaction_id - .get_connector_transaction_id() - .change_context(errors::ConnectorError::MissingConnectorTransactionID)?; + .connector_reference_id + .clone() + .ok_or(errors::ConnectorError::RequestEncodingFailed)?; Ok(format!( - "{}v1/payments/{}", + "{}v1/orders/{}/payments", self.base_url(connectors), - connector_payment_id, + order_id, )) } @@ -512,21 +512,11 @@ impl ConnectorIntegration fo fn handle_response( &self, - data: &PaymentsCaptureRouterData, - event_builder: Option<&mut ConnectorEvent>, - res: Response, + _data: &PaymentsCaptureRouterData, + _event_builder: Option<&mut ConnectorEvent>, + _res: Response, ) -> CustomResult { - let response: razorpay::RazorpayPaymentsResponse = res - .response - .parse_struct("Razorpay PaymentsCaptureResponse") - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - event_builder.map(|i| i.set_response_body(&response)); - router_env::logger::info!(connector_response=?response); - RouterData::try_from(ResponseRouterData { - response, - data: data.clone(), - http_code: res.status_code, - }) + Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into()) } fn get_error_response( diff --git a/crates/hyperswitch_connectors/src/connectors/razorpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/razorpay/transformers.rs index 23aa882829..0176ae4785 100644 --- a/crates/hyperswitch_connectors/src/connectors/razorpay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/razorpay/transformers.rs @@ -11,7 +11,7 @@ use hyperswitch_domain_models::{ payment_method_data::{PaymentMethodData, UpiData}, router_data::{ConnectorAuthType, RouterData}, router_flow_types::refunds::{Execute, RSync}, - router_request_types::ResponseId, + router_request_types::{PaymentsAuthorizeData, ResponseId}, router_response_types::{PaymentsResponseData, RefundsResponseData}, types, }; @@ -227,18 +227,29 @@ pub struct NextAction { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct RazorpayPaymentsResponse { pub razorpay_payment_id: String, - pub next: Option>, } -impl TryFrom> - for RouterData +impl + TryFrom< + ResponseRouterData< + F, + RazorpayPaymentsResponse, + PaymentsAuthorizeData, + PaymentsResponseData, + >, + > for RouterData { type Error = error_stack::Report; fn try_from( - item: ResponseRouterData, + item: ResponseRouterData< + F, + RazorpayPaymentsResponse, + PaymentsAuthorizeData, + PaymentsResponseData, + >, ) -> Result { let connector_metadata = get_wait_screen_metadata()?; - + let order_id = item.data.request.get_order_id()?; Ok(Self { status: enums::AttemptStatus::AuthenticationPending, response: Ok(PaymentsResponseData::TransactionResponse { @@ -249,7 +260,7 @@ impl TryFrom CustomResult, err #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RazorpaySyncResponse { + items: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RazorpaySyncItem { id: String, status: RazorpayStatus, } @@ -311,8 +328,15 @@ impl TryFrom, ) -> Result { + let status = match item.response.items.last() { + Some(last_item) => { + let razorpay_status = last_item.status; + get_psync_razorpay_payment_status(razorpay_status) + } + None => item.data.status, + }; Ok(Self { - status: get_psync_razorpay_payment_status(item.response.status), + status, response: Ok(PaymentsResponseData::TransactionResponse { resource_id: ResponseId::NoResponseId, redirection_data: Box::new(None), diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs index b346b40d97..1353d06819 100644 --- a/crates/hyperswitch_connectors/src/utils.rs +++ b/crates/hyperswitch_connectors/src/utils.rs @@ -6209,7 +6209,7 @@ pub(crate) fn convert_payment_authorize_router_response( connector_mandate_request_reference_id: data.connector_mandate_request_reference_id.clone(), authentication_id: data.authentication_id.clone(), psd2_sca_exemption_type: data.psd2_sca_exemption_type, - whole_connector_response: data.whole_connector_response.clone(), + raw_connector_response: data.raw_connector_response.clone(), } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index d644c519ea..9078f1d49d 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -1763,6 +1763,7 @@ pub struct ConfirmIntentResponseUpdate { pub connector_metadata: Option, pub amount_capturable: Option, pub connector_token_details: Option, + pub connector_response_reference_id: Option, } #[cfg(feature = "v2")] @@ -1776,6 +1777,7 @@ pub enum PaymentAttemptUpdate { merchant_connector_id: Option, authentication_type: storage_enums::AuthenticationType, connector_request_reference_id: Option, + connector_response_reference_id: Option, }, /// Update the payment attempt on confirming the intent, before calling the connector, when payment_method_id is present ConfirmIntentTokenized { @@ -2569,6 +2571,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal merchant_connector_id, authentication_type, connector_request_reference_id, + connector_response_reference_id, } => Self { status: Some(status), payment_method_id: None, @@ -2594,6 +2597,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal network_decline_code: None, network_error_message: None, connector_request_reference_id, + connector_response_reference_id, }, PaymentAttemptUpdate::ErrorUpdate { status, @@ -2626,6 +2630,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal network_decline_code: error.network_decline_code, network_error_message: error.network_error_message, connector_request_reference_id: None, + connector_response_reference_id: None, }, PaymentAttemptUpdate::ConfirmIntentResponse(confirm_intent_response_update) => { let ConfirmIntentResponseUpdate { @@ -2636,6 +2641,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal connector_metadata, amount_capturable, connector_token_details, + connector_response_reference_id, } = *confirm_intent_response_update; Self { status: Some(status), @@ -2663,6 +2669,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal network_decline_code: None, network_error_message: None, connector_request_reference_id: None, + connector_response_reference_id, } } PaymentAttemptUpdate::SyncUpdate { @@ -2694,6 +2701,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal network_decline_code: None, network_error_message: None, connector_request_reference_id: None, + connector_response_reference_id: None, }, PaymentAttemptUpdate::CaptureUpdate { status, @@ -2724,6 +2732,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal network_decline_code: None, network_error_message: None, connector_request_reference_id: None, + connector_response_reference_id: None, }, PaymentAttemptUpdate::PreCaptureUpdate { amount_to_capture, @@ -2753,6 +2762,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal network_decline_code: None, network_error_message: None, connector_request_reference_id: None, + connector_response_reference_id: None, }, PaymentAttemptUpdate::ConfirmIntentTokenized { status, @@ -2786,6 +2796,7 @@ impl From for diesel_models::PaymentAttemptUpdateInternal network_decline_code: None, network_error_message: None, connector_request_reference_id: None, + connector_response_reference_id: None, }, } } diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index dd1004c701..851ac69a81 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -103,8 +103,8 @@ pub struct RouterData { /// Contains the type of sca exemption required for the transaction pub psd2_sca_exemption_type: Option, - /// Contains whole connector response - pub whole_connector_response: Option, + /// Contains stringified connector raw response body + pub raw_connector_response: Option, } // Different patterns of authentication. @@ -567,6 +567,7 @@ impl resource_id, redirection_data, connector_metadata, + connector_response_reference_id, .. } => { let attempt_status = self.get_attempt_status_for_db_update(payment_data); @@ -595,6 +596,8 @@ impl token_details.get_connector_token_request_reference_id() }), ), + connector_response_reference_id: connector_response_reference_id + .clone(), }, )) } @@ -1253,6 +1256,7 @@ impl resource_id, redirection_data, connector_metadata, + connector_response_reference_id, .. } => { let attempt_status = self.get_attempt_status_for_db_update(payment_data); @@ -1281,6 +1285,9 @@ impl token_details.get_connector_token_request_reference_id() }), ), + + connector_response_reference_id: connector_response_reference_id + .clone(), }, )) } diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs index c7987122ea..31879b4cfe 100644 --- a/crates/hyperswitch_domain_models/src/router_request_types.rs +++ b/crates/hyperswitch_domain_models/src/router_request_types.rs @@ -508,6 +508,7 @@ pub struct PaymentsSyncData { pub split_payments: Option, pub amount: MinorUnit, pub integrity_object: Option, + pub connector_reference_id: Option, } #[derive(Debug, Default, Clone)] diff --git a/crates/hyperswitch_interfaces/src/conversion_impls.rs b/crates/hyperswitch_interfaces/src/conversion_impls.rs index 252caed961..ae5f071a20 100644 --- a/crates/hyperswitch_interfaces/src/conversion_impls.rs +++ b/crates/hyperswitch_interfaces/src/conversion_impls.rs @@ -84,7 +84,7 @@ fn get_default_router_data( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, } } diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs index 4a3c03d69f..11dae0588a 100644 --- a/crates/openapi/src/openapi_v2.rs +++ b/crates/openapi/src/openapi_v2.rs @@ -424,7 +424,6 @@ Never share your secret api keys. Keep them guarded and secure. api_models::payments::PaymentsRequest, api_models::payments::PaymentsResponse, api_models::payments::PaymentsListResponseItem, - api_models::payments::PaymentRetrieveBody, api_models::payments::PaymentsRetrieveRequest, api_models::payments::PaymentsStatusRequest, api_models::payments::PaymentsCaptureRequest, diff --git a/crates/router/src/core/authentication/transformers.rs b/crates/router/src/core/authentication/transformers.rs index e1cf04c20a..91b7c23f05 100644 --- a/crates/router/src/core/authentication/transformers.rs +++ b/crates/router/src/core/authentication/transformers.rs @@ -206,7 +206,7 @@ pub fn construct_router_data( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type, - whole_connector_response: None, + raw_connector_response: None, }) } diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs index 786192f8e9..a33dcc89a9 100644 --- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs +++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs @@ -161,7 +161,7 @@ impl ConstructFlowSpecificData( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs index ea34b8af17..d33cd51e57 100644 --- a/crates/router/src/core/fraud_check/flows/record_return.rs +++ b/crates/router/src/core/fraud_check/flows/record_return.rs @@ -129,7 +129,7 @@ impl ConstructFlowSpecificData( get_tracker_response: operations::GetTrackerResponse, call_connector_action: CallConnectorAction, header_payload: HeaderPayload, -) -> RouterResult<(D, Req, Option, Option, Option)> +) -> RouterResult<( + D, + Req, + Option, + Option, + Option, + common_types::domain::ConnectorResponseData, +)> where F: Send + Clone + Sync, Req: Send + Sync + Authenticate, @@ -204,7 +211,7 @@ where .perform_routing(&merchant_context, profile, state, &mut payment_data) .await?; - let payment_data = match connector { + let (payment_data, connector_response_data) = match connector { ConnectorCallType::PreDetermined(connector_data) => { let router_data = call_connector_service( state, @@ -224,10 +231,14 @@ where profile, false, false, //should_retry_with_pan is set to false in case of PreDetermined ConnectorCallType - req.get_all_keys_required(), + req.should_return_raw_response(), ) .await?; + let connector_response_data = common_types::domain::ConnectorResponseData { + raw_connector_response: router_data.raw_connector_response.clone(), + }; + let payments_response_operation = Box::new(PaymentResponse); payments_response_operation @@ -241,7 +252,7 @@ where ) .await?; - payments_response_operation + let payment_data = payments_response_operation .to_post_update_tracker()? .update_tracker( state, @@ -250,7 +261,9 @@ where merchant_context.get_merchant_key_store(), merchant_context.get_merchant_account().storage_scheme, ) - .await? + .await?; + + (payment_data, connector_response_data) } ConnectorCallType::Retryable(connectors) => { let mut connectors = connectors.clone().into_iter(); @@ -273,10 +286,14 @@ where profile, false, false, //should_retry_with_pan is set to false in case of PreDetermined ConnectorCallType - req.get_all_keys_required(), + req.should_return_raw_response(), ) .await?; + let connector_response_data = common_types::domain::ConnectorResponseData { + raw_connector_response: router_data.raw_connector_response.clone(), + }; + let payments_response_operation = Box::new(PaymentResponse); payments_response_operation @@ -290,7 +307,7 @@ where ) .await?; - payments_response_operation + let payment_data = payments_response_operation .to_post_update_tracker()? .update_tracker( state, @@ -299,10 +316,17 @@ where merchant_context.get_merchant_key_store(), merchant_context.get_merchant_account().storage_scheme, ) - .await? + .await?; + + (payment_data, connector_response_data) } ConnectorCallType::SessionMultiple(vec) => todo!(), - ConnectorCallType::Skip => payment_data, + ConnectorCallType::Skip => ( + payment_data, + common_types::domain::ConnectorResponseData { + raw_connector_response: None, + }, + ), }; let payment_intent_status = payment_data.get_payment_intent().status; @@ -321,7 +345,14 @@ where }) .await; - Ok((payment_data, req, customer, None, None)) + Ok(( + payment_data, + req, + customer, + None, + None, + connector_response_data, + )) } #[cfg(feature = "v2")] @@ -337,7 +368,13 @@ pub async fn internal_payments_operation_core( get_tracker_response: operations::GetTrackerResponse, call_connector_action: CallConnectorAction, header_payload: HeaderPayload, -) -> RouterResult<(D, Req, Option, Option)> +) -> RouterResult<( + D, + Req, + Option, + Option, + common_types::domain::ConnectorResponseData, +)> where F: Send + Clone + Sync, Req: Send + Sync + Authenticate, @@ -379,10 +416,14 @@ where call_connector_action.clone(), header_payload.clone(), profile, - req.get_all_keys_required(), + req.should_return_raw_response(), ) .await?; + let connector_response_data = common_types::domain::ConnectorResponseData { + raw_connector_response: router_data.raw_connector_response.clone(), + }; + let payments_response_operation = Box::new(PaymentResponse); let payment_data = payments_response_operation @@ -396,7 +437,7 @@ where ) .await?; - Ok((payment_data, req, None, None)) + Ok((payment_data, req, None, None, connector_response_data)) } #[cfg(feature = "v1")] @@ -686,7 +727,7 @@ where false, false, None, - ::get_all_keys_required(&req), + ::should_return_raw_response(&req), ) .await?; @@ -810,7 +851,7 @@ where false, false, routing_decision, - ::get_all_keys_required(&req), + ::should_return_raw_response(&req), ) .await?; @@ -941,7 +982,7 @@ where session_surcharge_details, &business_profile, header_payload.clone(), - ::get_all_keys_required(&req), + ::should_return_raw_response(&req), )) .await? } @@ -1070,7 +1111,7 @@ pub async fn proxy_for_payments_operation_core( call_connector_action: CallConnectorAction, auth_flow: services::AuthFlow, header_payload: HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult<(D, Req, Option, Option, Option)> where F: Send + Clone + Sync, @@ -1184,7 +1225,7 @@ where schedule_time, header_payload.clone(), &business_profile, - all_keys_required, + return_raw_connector_response, ) .await?; @@ -1270,7 +1311,7 @@ pub async fn proxy_for_payments_operation_core( get_tracker_response: operations::GetTrackerResponse, call_connector_action: CallConnectorAction, header_payload: HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult<(D, Req, Option, Option)> where F: Send + Clone + Sync, @@ -1315,7 +1356,7 @@ where call_connector_action.clone(), header_payload.clone(), &profile, - all_keys_required, + return_raw_connector_response, ) .await?; @@ -1865,7 +1906,7 @@ pub async fn proxy_for_payments_core( auth_flow: services::AuthFlow, call_connector_action: CallConnectorAction, header_payload: HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResponse where F: Send + Clone + Sync, @@ -1896,7 +1937,7 @@ where call_connector_action, auth_flow, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ) .await?; @@ -1925,7 +1966,7 @@ pub async fn proxy_for_payments_core( payment_id: id_type::GlobalPaymentId, call_connector_action: CallConnectorAction, header_payload: HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResponse where F: Send + Clone + Sync, @@ -1977,7 +2018,7 @@ where get_tracker_response, call_connector_action, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ) .await?; @@ -1988,6 +2029,7 @@ where header_payload.x_hs_latency, &merchant_context, &profile, + None, ) } @@ -2065,7 +2107,7 @@ pub async fn record_attempt_core( force_sync: true, expand_attempts: false, param: None, - all_keys_required: None, + return_raw_connector_response: None, merchant_connector_details: None, }, operations::GetTrackerResponse { @@ -2125,6 +2167,7 @@ pub async fn record_attempt_core( header_payload.x_hs_latency, &merchant_context, &profile, + None, ) } @@ -2334,37 +2377,58 @@ where ) .await?; - let (payment_data, connector_http_status_code, external_latency) = + let (payment_data, connector_http_status_code, external_latency, connector_response_data) = if state.conf.merchant_id_auth.merchant_id_auth_enabled { - let (payment_data, _req, connector_http_status_code, external_latency) = - internal_payments_operation_core::<_, _, _, _, _>( - &state, - req_state, - merchant_context.clone(), - &profile, - operation.clone(), - req, - get_tracker_response, - call_connector_action, - header_payload.clone(), - ) - .await?; - (payment_data, connector_http_status_code, external_latency) + let ( + payment_data, + _req, + connector_http_status_code, + external_latency, + connector_response_data, + ) = internal_payments_operation_core::<_, _, _, _, _>( + &state, + req_state, + merchant_context.clone(), + &profile, + operation.clone(), + req, + get_tracker_response, + call_connector_action, + header_payload.clone(), + ) + .await?; + ( + payment_data, + connector_http_status_code, + external_latency, + connector_response_data, + ) } else { - let (payment_data, _req, _customer, connector_http_status_code, external_latency) = - payments_operation_core::<_, _, _, _, _>( - &state, - req_state, - merchant_context.clone(), - &profile, - operation.clone(), - req, - get_tracker_response, - call_connector_action, - header_payload.clone(), - ) - .await?; - (payment_data, connector_http_status_code, external_latency) + let ( + payment_data, + _req, + _customer, + connector_http_status_code, + external_latency, + connector_response_data, + ) = payments_operation_core::<_, _, _, _, _>( + &state, + req_state, + merchant_context.clone(), + &profile, + operation.clone(), + req, + get_tracker_response, + call_connector_action, + header_payload.clone(), + ) + .await?; + ( + payment_data, + connector_http_status_code, + external_latency, + connector_response_data, + ) }; payment_data.generate_response( @@ -2374,6 +2438,7 @@ where header_payload.x_hs_latency, &merchant_context, &profile, + Some(connector_response_data), ) } @@ -3000,7 +3065,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync { param: Some(req.query_params.clone()), force_sync: true, expand_attempts: false, - all_keys_required: None, + return_raw_connector_response: None, merchant_connector_details: None, // TODO: Implement for connectors requiring 3DS or redirection-based authentication flows. }; @@ -3056,7 +3121,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync { .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to decide the response flow")?; - let (payment_data, _, _, _, _) = + let (payment_data, _, _, _, _, _) = Box::pin(payments_operation_core::( state, req_state, @@ -3378,7 +3443,7 @@ pub async fn call_connector_service( is_retry_payment: bool, should_retry_with_pan: bool, routing_decision: Option, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult<( RouterData, helpers::MerchantConnectorAccountType, @@ -3539,16 +3604,28 @@ where router_data = router_data.add_session_token(state, &connector).await?; - let should_continue_further = access_token::update_router_data_with_access_token_result( + let mut should_continue_further = access_token::update_router_data_with_access_token_result( &add_access_token_result, &mut router_data, &call_connector_action, ); - let should_continue_further = router_data + let add_create_order_result = router_data .create_order_at_connector(state, &connector, should_continue_further) .await?; + if add_create_order_result.is_create_order_performed { + if let Ok(order_id_opt) = &add_create_order_result.create_order_result { + payment_data.set_connector_response_reference_id(order_id_opt.clone()); + } + should_continue_further = router_data + .update_router_data_with_create_order_result( + add_create_order_result, + should_continue_further, + ) + .await?; + } + let updated_customer = call_create_connector_customer_if_required( state, customer, @@ -3664,7 +3741,7 @@ where connector_request, business_profile, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ) .await } else { @@ -3696,7 +3773,7 @@ pub async fn call_connector_service( business_profile: &domain::Profile, is_retry_payment: bool, should_retry_with_pan: bool, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult> where F: Send + Clone + Sync, @@ -3765,16 +3842,28 @@ where router_data = router_data.add_session_token(state, &connector).await?; - let should_continue_further = access_token::update_router_data_with_access_token_result( + let mut should_continue_further = access_token::update_router_data_with_access_token_result( &add_access_token_result, &mut router_data, &call_connector_action, ); - let should_continue_further = router_data + let add_create_order_result = router_data .create_order_at_connector(state, &connector, should_continue_further) .await?; + if add_create_order_result.is_create_order_performed { + if let Ok(order_id_opt) = &add_create_order_result.create_order_result { + payment_data.set_connector_response_reference_id(order_id_opt.clone()); + } + should_continue_further = router_data + .update_router_data_with_create_order_result( + add_create_order_result, + should_continue_further, + ) + .await?; + } + // In case of authorize flow, pre-task and post-tasks are being called in build request // if we do not want to proceed further, then the function will return Ok(None, false) let (connector_request, should_continue_further) = if should_continue_further { @@ -3819,7 +3908,7 @@ where connector_request, business_profile, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ) .await } else { @@ -3851,7 +3940,7 @@ pub async fn proxy_for_call_connector_service( header_payload: HeaderPayload, business_profile: &domain::Profile, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult<( RouterData, helpers::MerchantConnectorAccountType, @@ -3992,7 +4081,7 @@ where connector_request, business_profile, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ) .await } else { @@ -4019,7 +4108,7 @@ pub async fn proxy_for_call_connector_service( call_connector_action: CallConnectorAction, header_payload: HeaderPayload, business_profile: &domain::Profile, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult> where F: Send + Clone + Sync, @@ -4116,7 +4205,7 @@ where connector_request, business_profile, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ) .await } else { @@ -4143,7 +4232,7 @@ pub async fn internal_call_connector_service( call_connector_action: CallConnectorAction, header_payload: HeaderPayload, business_profile: &domain::Profile, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult> where F: Send + Clone + Sync, @@ -4211,10 +4300,22 @@ where &call_connector_action, ); - let should_continue_further = router_data + let add_create_order_result = router_data .create_order_at_connector(state, &connector, should_continue_further) .await?; + if add_create_order_result.is_create_order_performed { + if let Ok(order_id_opt) = &add_create_order_result.create_order_result { + payment_data.set_connector_response_reference_id(order_id_opt.clone()); + } + should_continue_further = router_data + .update_router_data_with_create_order_result( + add_create_order_result, + should_continue_further, + ) + .await?; + } + let (connector_request, should_continue_further) = if should_continue_further { router_data .build_flow_specific_connector_request(state, &connector, call_connector_action.clone()) @@ -4247,7 +4348,7 @@ where connector_request, business_profile, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ) .await } else { @@ -4509,7 +4610,7 @@ pub async fn call_multiple_connectors_service( _session_surcharge_details: Option, business_profile: &domain::Profile, header_payload: HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult where Op: Debug, @@ -4560,7 +4661,7 @@ where None, business_profile, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ); join_handlers.push(res); @@ -4620,7 +4721,7 @@ pub async fn call_multiple_connectors_service( session_surcharge_details: Option, business_profile: &domain::Profile, header_payload: HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult where Op: Debug, @@ -4682,7 +4783,7 @@ where None, business_profile, header_payload.clone(), - all_keys_required, + return_raw_connector_response, ); join_handlers.push(res); @@ -8893,6 +8994,7 @@ pub trait OperationSessionGetters { fn get_token_data(&self) -> Option<&storage::PaymentTokenData>; fn get_mandate_connector(&self) -> Option<&MandateConnectorDetails>; fn get_force_sync(&self) -> Option; + #[cfg(feature = "v1")] fn get_all_keys_required(&self) -> Option; fn get_capture_method(&self) -> Option; fn get_merchant_connector_id_in_attempt(&self) -> Option; @@ -8902,6 +9004,8 @@ pub trait OperationSessionGetters { ) -> Option; fn get_connector_customer_id(&self) -> Option; + + #[cfg(feature = "v1")] fn get_whole_connector_response(&self) -> Option; #[cfg(feature = "v1")] @@ -8980,6 +9084,8 @@ pub trait OperationSessionSetters { #[cfg(feature = "v2")] fn set_connector_request_reference_id(&mut self, reference_id: Option); + fn set_connector_response_reference_id(&mut self, reference_id: Option); + #[cfg(feature = "v2")] fn set_vault_session_details( &mut self, @@ -9292,6 +9398,10 @@ impl OperationSessionSetters for PaymentData { ) { self.payment_attempt.routing_approach = routing_approach; } + + fn set_connector_response_reference_id(&mut self, reference_id: Option) { + self.payment_attempt.connector_response_reference_id = reference_id; + } } #[cfg(feature = "v2")] @@ -9446,14 +9556,6 @@ impl OperationSessionGetters for PaymentIntentData { todo!(); } - fn get_all_keys_required(&self) -> Option { - todo!(); - } - - fn get_whole_connector_response(&self) -> Option { - todo!(); - } - fn get_pre_routing_result( &self, ) -> Option> { @@ -9572,6 +9674,10 @@ impl OperationSessionSetters for PaymentIntentData { todo!() } + fn set_connector_response_reference_id(&mut self, reference_id: Option) { + todo!() + } + fn set_vault_session_details( &mut self, vault_session_details: Option, @@ -9737,14 +9843,6 @@ impl OperationSessionGetters for PaymentConfirmData { Some(&self.payment_attempt) } - fn get_all_keys_required(&self) -> Option { - todo!() - } - - fn get_whole_connector_response(&self) -> Option { - todo!() - } - fn get_pre_routing_result( &self, ) -> Option> { @@ -9868,6 +9966,10 @@ impl OperationSessionSetters for PaymentConfirmData { self.payment_attempt.connector_request_reference_id = reference_id; } + fn set_connector_response_reference_id(&mut self, reference_id: Option) { + self.payment_attempt.connector_response_reference_id = reference_id; + } + fn set_vault_session_details( &mut self, external_vault_session_details: Option, @@ -10033,14 +10135,6 @@ impl OperationSessionGetters for PaymentStatusData { Some(&self.payment_attempt) } - fn get_all_keys_required(&self) -> Option { - todo!() - } - - fn get_whole_connector_response(&self) -> Option { - todo!() - } - fn get_pre_routing_result( &self, ) -> Option> { @@ -10160,6 +10254,10 @@ impl OperationSessionSetters for PaymentStatusData { todo!() } + fn set_connector_response_reference_id(&mut self, reference_id: Option) { + todo!() + } + fn set_vault_session_details( &mut self, external_vault_session_details: Option, @@ -10326,13 +10424,6 @@ impl OperationSessionGetters for PaymentCaptureData { Some(&self.payment_attempt) } - fn get_all_keys_required(&self) -> Option { - todo!(); - } - - fn get_whole_connector_response(&self) -> Option { - todo!(); - } fn get_pre_routing_result( &self, ) -> Option> { @@ -10452,6 +10543,10 @@ impl OperationSessionSetters for PaymentCaptureData { todo!() } + fn set_connector_response_reference_id(&mut self, reference_id: Option) { + todo!() + } + fn set_vault_session_details( &mut self, external_vault_session_details: Option, @@ -10613,13 +10708,6 @@ impl OperationSessionGetters for PaymentAttemptListData { todo!() } - fn get_all_keys_required(&self) -> Option { - todo!(); - } - - fn get_whole_connector_response(&self) -> Option { - todo!(); - } fn get_pre_routing_result( &self, ) -> Option> { diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index 2b68120274..5cc7cfa777 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -78,7 +78,7 @@ pub trait Feature { connector_request: Option, business_profile: &domain::Profile, header_payload: hyperswitch_domain_models::payments::HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult where Self: Sized, @@ -182,6 +182,22 @@ pub trait Feature { &mut self, _state: &SessionState, _connector: &api::ConnectorData, + _should_continue_payment: bool, + ) -> RouterResult + where + F: Clone, + Self: Sized, + dyn api::Connector: services::ConnectorIntegration, + { + Ok(types::CreateOrderResult { + create_order_result: Ok(None), + is_create_order_performed: false, + }) + } + + async fn update_router_data_with_create_order_result( + &mut self, + _create_order_result: types::CreateOrderResult, should_continue_payment: bool, ) -> RouterResult where diff --git a/crates/router/src/core/payments/flows/approve_flow.rs b/crates/router/src/core/payments/flows/approve_flow.rs index 30b7b834f5..e2f671d914 100644 --- a/crates/router/src/core/payments/flows/approve_flow.rs +++ b/crates/router/src/core/payments/flows/approve_flow.rs @@ -80,7 +80,7 @@ impl Feature _connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { Err(ApiErrorResponse::NotImplemented { message: NotImplementedMessage::Reason("Flow not supported".to_string()), diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index ace3588c22..4df6ae9fe9 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -171,7 +171,7 @@ impl Feature for types::PaymentsAu connector_request: Option, business_profile: &domain::Profile, header_payload: hyperswitch_domain_models::payments::HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::Authorize, @@ -188,7 +188,7 @@ impl Feature for types::PaymentsAu &self, call_connector_action.clone(), connector_request, - all_keys_required, + return_raw_connector_response, ) .await .to_payment_failed_response()?; @@ -422,17 +422,92 @@ impl Feature for types::PaymentsAu state: &SessionState, connector: &api::ConnectorData, should_continue_payment: bool, + ) -> RouterResult { + if connector + .connector_name + .requires_order_creation_before_payment(self.payment_method) + && should_continue_payment + { + let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< + api::CreateOrder, + types::CreateOrderRequestData, + types::PaymentsResponseData, + > = connector.connector.get_connector_integration(); + + let request_data = types::CreateOrderRequestData::try_from(self.request.clone())?; + + let response_data: Result = + Err(types::ErrorResponse::default()); + + let createorder_router_data = + helpers::router_data_type_conversion::<_, api::CreateOrder, _, _, _, _>( + self.clone(), + request_data, + response_data, + ); + + let resp = services::execute_connector_processing_step( + state, + connector_integration, + &createorder_router_data, + payments::CallConnectorAction::Trigger, + None, + None, + ) + .await + .to_payment_failed_response()?; + + let create_order_resp = match resp.response { + Ok(res) => { + if let types::PaymentsResponseData::PaymentsCreateOrderResponse { order_id } = + res + { + Ok(Some(order_id)) + } else { + Err(error_stack::report!(ApiErrorResponse::InternalServerError) + .attach_printable(format!( + "Unexpected response format from connector: {res:?}", + )))? + } + } + Err(error) => Err(error), + }; + + Ok(types::CreateOrderResult { + create_order_result: create_order_resp, + is_create_order_performed: true, + }) + } else { + Ok(types::CreateOrderResult { + create_order_result: Ok(None), + is_create_order_performed: false, + }) + } + } + + async fn update_router_data_with_create_order_result( + &mut self, + create_order_result: types::CreateOrderResult, + should_continue_further: bool, ) -> RouterResult { - let create_order_result = - create_order_at_connector(self, state, connector, should_continue_payment).await?; - - let should_continue_payment = update_router_data_with_create_order_result( - create_order_result, - self, - should_continue_payment, - )?; - - Ok(should_continue_payment) + if create_order_result.is_create_order_performed { + match create_order_result.create_order_result { + Ok(Some(order_id)) => { + self.request.order_id = Some(order_id.clone()); + self.response = + Ok(types::PaymentsResponseData::PaymentsCreateOrderResponse { order_id }); + Ok(true) + } + Ok(None) => Err(error_stack::report!(ApiErrorResponse::InternalServerError) + .attach_printable("Order Id not found."))?, + Err(err) => { + self.response = Err(err.clone()); + Ok(false) + } + } + } else { + Ok(should_continue_further) + } } } @@ -719,102 +794,3 @@ async fn process_capture_flow( router_data.response = Ok(updated_response); Ok(router_data) } - -async fn create_order_at_connector( - router_data: &mut types::RouterData< - F, - types::PaymentsAuthorizeData, - types::PaymentsResponseData, - >, - state: &SessionState, - connector: &api::ConnectorData, - should_continue_payment: bool, -) -> RouterResult { - if connector - .connector_name - .requires_order_creation_before_payment(router_data.payment_method) - && should_continue_payment - { - let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< - api::CreateOrder, - types::CreateOrderRequestData, - types::PaymentsResponseData, - > = connector.connector.get_connector_integration(); - - let request_data = types::CreateOrderRequestData::try_from(router_data.request.clone())?; - - let response_data: Result = - Err(types::ErrorResponse::default()); - - let createorder_router_data = - helpers::router_data_type_conversion::<_, api::CreateOrder, _, _, _, _>( - router_data.clone(), - request_data, - response_data, - ); - - let resp = services::execute_connector_processing_step( - state, - connector_integration, - &createorder_router_data, - payments::CallConnectorAction::Trigger, - None, - None, - ) - .await - .to_payment_failed_response()?; - - let create_order_resp = match resp.response { - Ok(res) => { - if let types::PaymentsResponseData::PaymentsCreateOrderResponse { order_id } = res { - Ok(Some(order_id)) - } else { - Err(error_stack::report!(ApiErrorResponse::InternalServerError) - .attach_printable(format!( - "Unexpected response format from connector: {res:?}", - )))? - } - } - Err(error) => Err(error), - }; - - Ok(types::CreateOrderResult { - create_order_result: create_order_resp, - is_create_order_performed: true, - }) - } else { - Ok(types::CreateOrderResult { - create_order_result: Ok(None), - is_create_order_performed: false, - }) - } -} - -fn update_router_data_with_create_order_result( - create_order_result: types::CreateOrderResult, - router_data: &mut types::RouterData< - F, - types::PaymentsAuthorizeData, - types::PaymentsResponseData, - >, - should_continue_further: bool, -) -> RouterResult { - if create_order_result.is_create_order_performed { - match create_order_result.create_order_result { - Ok(Some(order_id)) => { - router_data.request.order_id = Some(order_id.clone()); - router_data.response = - Ok(types::PaymentsResponseData::PaymentsCreateOrderResponse { order_id }); - Ok(true) - } - Ok(None) => Err(error_stack::report!(ApiErrorResponse::InternalServerError) - .attach_printable("Order Id not found."))?, - Err(err) => { - router_data.response = Err(err.clone()); - Ok(false) - } - } - } else { - Ok(should_continue_further) - } -} diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rs index fc27a60042..046213dbe5 100644 --- a/crates/router/src/core/payments/flows/cancel_flow.rs +++ b/crates/router/src/core/payments/flows/cancel_flow.rs @@ -79,7 +79,7 @@ impl Feature connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { metrics::PAYMENT_CANCEL_COUNT.add( 1, diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rs index 545b3fc263..09d60db9a4 100644 --- a/crates/router/src/core/payments/flows/capture_flow.rs +++ b/crates/router/src/core/payments/flows/capture_flow.rs @@ -108,7 +108,7 @@ impl Feature connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::Capture, diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rs index 4fb4e7574a..d734f195ce 100644 --- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs +++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs @@ -100,7 +100,7 @@ impl Feature connector_request: Option, business_profile: &domain::Profile, header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::CompleteAuthorize, diff --git a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs index 092be33219..c7dee2ad9e 100644 --- a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs +++ b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs @@ -87,7 +87,7 @@ impl Feature, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::IncrementalAuthorization, diff --git a/crates/router/src/core/payments/flows/post_session_tokens_flow.rs b/crates/router/src/core/payments/flows/post_session_tokens_flow.rs index e29739cf01..118dd17a10 100644 --- a/crates/router/src/core/payments/flows/post_session_tokens_flow.rs +++ b/crates/router/src/core/payments/flows/post_session_tokens_flow.rs @@ -87,7 +87,7 @@ impl Feature connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::PostSessionTokens, diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs index 38fc08a1df..87536525be 100644 --- a/crates/router/src/core/payments/flows/psync_flow.rs +++ b/crates/router/src/core/payments/flows/psync_flow.rs @@ -111,7 +111,7 @@ impl Feature connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::PSync, @@ -134,7 +134,7 @@ impl Feature pending_connector_capture_id_list, call_connector_action, connector_integration, - all_keys_required, + return_raw_connector_response, ) .await?; // Initiating Integrity checks @@ -156,7 +156,7 @@ impl Feature &self, call_connector_action, connector_request, - all_keys_required, + return_raw_connector_response, ) .await .to_payment_failed_response()?; @@ -241,7 +241,7 @@ where types::PaymentsSyncData, types::PaymentsResponseData, >, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult; } @@ -259,7 +259,7 @@ impl RouterDataPSync types::PaymentsSyncData, types::PaymentsResponseData, >, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult { let mut capture_sync_response_map = HashMap::new(); if let payments::CallConnectorAction::HandleResponse(_) = call_connector_action { @@ -270,7 +270,7 @@ impl RouterDataPSync self, call_connector_action.clone(), None, - all_keys_required, + return_raw_connector_response, ) .await .to_payment_failed_response()?; @@ -289,7 +289,7 @@ impl RouterDataPSync &cloned_router_data, call_connector_action.clone(), None, - all_keys_required, + return_raw_connector_response, ) .await .to_payment_failed_response()?; diff --git a/crates/router/src/core/payments/flows/reject_flow.rs b/crates/router/src/core/payments/flows/reject_flow.rs index 852058dc37..efb34be54b 100644 --- a/crates/router/src/core/payments/flows/reject_flow.rs +++ b/crates/router/src/core/payments/flows/reject_flow.rs @@ -79,7 +79,7 @@ impl Feature _connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { Err(ApiErrorResponse::NotImplemented { message: NotImplementedMessage::Reason("Flow not supported".to_string()), diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs index a805f455b4..ae0450f28f 100644 --- a/crates/router/src/core/payments/flows/session_flow.rs +++ b/crates/router/src/core/payments/flows/session_flow.rs @@ -121,7 +121,7 @@ impl Feature for types::PaymentsSessio _connector_request: Option, business_profile: &domain::Profile, header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { metrics::SESSION_TOKEN_CREATED.add( 1, diff --git a/crates/router/src/core/payments/flows/session_update_flow.rs b/crates/router/src/core/payments/flows/session_update_flow.rs index e717ff50c2..cd42f855c1 100644 --- a/crates/router/src/core/payments/flows/session_update_flow.rs +++ b/crates/router/src/core/payments/flows/session_update_flow.rs @@ -87,7 +87,7 @@ impl Feature connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::SdkSessionUpdate, diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index a5bcdb4f55..f99d13bd31 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -117,7 +117,7 @@ impl Feature for types::Setup connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - _all_keys_required: Option, + _return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::SetupMandate, diff --git a/crates/router/src/core/payments/flows/update_metadata_flow.rs b/crates/router/src/core/payments/flows/update_metadata_flow.rs index a6a3583325..f654b7ead1 100644 --- a/crates/router/src/core/payments/flows/update_metadata_flow.rs +++ b/crates/router/src/core/payments/flows/update_metadata_flow.rs @@ -86,7 +86,7 @@ impl Feature connector_request: Option, _business_profile: &domain::Profile, _header_payload: hyperswitch_domain_models::payments::HeaderPayload, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> RouterResult { let connector_integration: services::BoxedPaymentConnectorIntegrationInterface< api::UpdateMetadata, @@ -100,7 +100,7 @@ impl Feature &self, call_connector_action, connector_request, - all_keys_required, + return_raw_connector_response, ) .await .to_payment_failed_response()?; diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 4b7791bb08..5eaee11c18 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -4175,7 +4175,7 @@ pub fn router_data_type_conversion( connector_mandate_request_reference_id: router_data.connector_mandate_request_reference_id, authentication_id: router_data.authentication_id, psd2_sca_exemption_type: router_data.psd2_sca_exemption_type, - whole_connector_response: router_data.whole_connector_response, + raw_connector_response: router_data.raw_connector_response, } } diff --git a/crates/router/src/core/payments/operations/payment_confirm_intent.rs b/crates/router/src/core/payments/operations/payment_confirm_intent.rs index dce33895fd..8ab7ddcfa2 100644 --- a/crates/router/src/core/payments/operations/payment_confirm_intent.rs +++ b/crates/router/src/core/payments/operations/payment_confirm_intent.rs @@ -588,6 +588,11 @@ impl UpdateTracker, PaymentsConfirmInt .connector_request_reference_id .clone(); + 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) => { @@ -611,6 +616,7 @@ impl UpdateTracker, PaymentsConfirmInt merchant_connector_id, authentication_type, connector_request_reference_id, + connector_response_reference_id, } } }; diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index ff618a7b34..939679ef51 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1412,7 +1412,7 @@ async fn payment_response_update_tracker( .as_mut() .map(|info| info.status = status) }); - payment_data.whole_connector_response = router_data.whole_connector_response.clone(); + payment_data.whole_connector_response = router_data.raw_connector_response.clone(); // TODO: refactor of gsm_error_category with respective feature flag #[allow(unused_variables)] diff --git a/crates/router/src/core/payments/operations/proxy_payments_intent.rs b/crates/router/src/core/payments/operations/proxy_payments_intent.rs index a65f4cdd99..30ea6913c6 100644 --- a/crates/router/src/core/payments/operations/proxy_payments_intent.rs +++ b/crates/router/src/core/payments/operations/proxy_payments_intent.rs @@ -409,6 +409,11 @@ impl UpdateTracker, ProxyPaymentsReque .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(), @@ -416,6 +421,7 @@ impl UpdateTracker, ProxyPaymentsReque merchant_connector_id, authentication_type, connector_request_reference_id, + connector_response_reference_id, }; let updated_payment_intent = db diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 636b1da0bb..71ff92b0bb 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -171,7 +171,7 @@ where connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } @@ -399,7 +399,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>( connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -563,7 +563,7 @@ pub async fn construct_payment_router_data_for_capture<'a>( connector_mandate_request_reference_id, psd2_sca_exemption_type: None, authentication_id: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -626,6 +626,7 @@ pub async fn construct_router_data_for_psync<'a>( // TODO: Get the charges object from feature metadata split_payments: None, payment_experience: None, + connector_reference_id: attempt.connector_response_reference_id.clone(), }; // TODO: evaluate the fields in router data, if they are required or not @@ -689,7 +690,7 @@ pub async fn construct_router_data_for_psync<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -871,7 +872,7 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>( connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, authentication_id: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -1088,7 +1089,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>( connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -1287,7 +1288,7 @@ where connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: payment_data.payment_intent.psd2_sca_exemption_type, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -1477,7 +1478,7 @@ pub async fn construct_payment_router_data_for_update_metadata<'a>( connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: payment_data.payment_intent.psd2_sca_exemption_type, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -1524,6 +1525,7 @@ where Self: Sized, { #[cfg(feature = "v2")] + #[allow(clippy::too_many_arguments)] fn generate_response( self, state: &SessionState, @@ -1532,6 +1534,7 @@ where is_latency_header_enabled: Option, merchant_context: &domain::MerchantContext, profile: &domain::Profile, + connector_response_data: Option, ) -> RouterResponse; } @@ -1549,6 +1552,7 @@ where is_latency_header_enabled: Option, merchant_context: &domain::MerchantContext, profile: &domain::Profile, + _connector_response_data: Option, ) -> RouterResponse { let payment_intent = &self.payment_intent; let payment_attempt = &self.payment_attempt; @@ -1872,6 +1876,7 @@ where is_latency_header_enabled: Option, merchant_context: &domain::MerchantContext, profile: &domain::Profile, + connector_response_data: Option, ) -> RouterResponse { let payment_intent = self.payment_intent; let payment_attempt = self.payment_attempt; @@ -1897,6 +1902,9 @@ where let payment_address = self.payment_address; + let raw_connector_response = + connector_response_data.and_then(|data| data.raw_connector_response); + let payment_method_data = Some(api_models::payments::PaymentMethodDataResponseWithBilling { payment_method_data: None, @@ -1951,7 +1959,7 @@ where payment_method_subtype: Some(payment_attempt.payment_method_subtype), next_action, connector_transaction_id: payment_attempt.connector_payment_id.clone(), - connector_reference_id: None, + connector_reference_id: payment_attempt.connector_response_reference_id.clone(), connector_token_details, merchant_connector_id, browser_info: None, @@ -1965,6 +1973,7 @@ where shipping: None, //TODO: add this is_iframe_redirection_enabled: None, merchant_reference_id: payment_intent.merchant_reference_id.clone(), + raw_connector_response, }; Ok(services::ApplicationResponse::JsonWithHeaders(( @@ -1988,6 +1997,7 @@ where is_latency_header_enabled: Option, merchant_context: &domain::MerchantContext, profile: &domain::Profile, + connector_response_data: Option, ) -> RouterResponse { let payment_intent = self.payment_intent; let payment_attempt = &self.payment_attempt; @@ -2022,6 +2032,9 @@ where .map(From::from), }); + let raw_connector_response = + connector_response_data.and_then(|data| data.raw_connector_response); + let connector_token_details = self .payment_attempt .connector_token_details @@ -2047,7 +2060,7 @@ where payment_method_type: Some(payment_attempt.payment_method_type), payment_method_subtype: Some(payment_attempt.payment_method_subtype), connector_transaction_id: payment_attempt.connector_payment_id.clone(), - connector_reference_id: None, + connector_reference_id: payment_attempt.connector_response_reference_id.clone(), merchant_connector_id, browser_info: None, connector_token_details, @@ -2060,6 +2073,7 @@ where return_url, is_iframe_redirection_enabled: payment_intent.is_iframe_redirection_enabled, merchant_reference_id: payment_intent.merchant_reference_id.clone(), + raw_connector_response, }; Ok(services::ApplicationResponse::JsonWithHeaders(( @@ -2083,6 +2097,7 @@ where _is_latency_header_enabled: Option, _merchant_context: &domain::MerchantContext, _profile: &domain::Profile, + _connector_response_data: Option, ) -> RouterResponse { let payment_attempt = self.payment_attempt; let response = api_models::payments::PaymentAttemptResponse::foreign_from(&payment_attempt); @@ -2107,6 +2122,7 @@ where _is_latency_header_enabled: Option, _merchant_context: &domain::MerchantContext, _profile: &domain::Profile, + _connector_response_data: Option, ) -> RouterResponse { let payment_attempt = self.payment_attempt; let payment_intent = self.payment_intent; @@ -3718,6 +3734,10 @@ impl TryFrom> for types::PaymentsSyncData currency: payment_data.currency, split_payments: payment_data.payment_intent.split_payments, payment_experience: payment_data.payment_attempt.payment_experience, + connector_reference_id: payment_data + .payment_attempt + .connector_response_reference_id + .clone(), }) } } diff --git a/crates/router/src/core/relay/utils.rs b/crates/router/src/core/relay/utils.rs index effc2178ec..1adacfbe94 100644 --- a/crates/router/src/core/relay/utils.rs +++ b/crates/router/src/core/relay/utils.rs @@ -143,7 +143,7 @@ pub async fn construct_relay_refund_router_data( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) diff --git a/crates/router/src/core/revenue_recovery/api.rs b/crates/router/src/core/revenue_recovery/api.rs index 3627d5062c..052f4351c7 100644 --- a/crates/router/src/core/revenue_recovery/api.rs +++ b/crates/router/src/core/revenue_recovery/api.rs @@ -31,7 +31,7 @@ pub async fn call_psync_api( force_sync: false, param: None, expand_attempts: true, - all_keys_required: None, + return_raw_connector_response: None, merchant_connector_details: None, }; let merchant_context_from_revenue_recovery_data = @@ -53,7 +53,7 @@ pub async fn call_psync_api( ) .await?; - let (payment_data, _req, _, _, _) = Box::pin(payments::payments_operation_core::< + let (payment_data, _req, _, _, _, _) = Box::pin(payments::payments_operation_core::< api_types::PSync, _, _, diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs index 6c841a02d3..20ac12a994 100644 --- a/crates/router/src/core/unified_authentication_service/utils.rs +++ b/crates/router/src/core/unified_authentication_service/utils.rs @@ -124,7 +124,7 @@ pub fn construct_uas_router_data( connector_mandate_request_reference_id: None, authentication_id, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }) } diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index d1d298bd17..c097b3fbfe 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -234,7 +234,7 @@ pub async fn construct_payout_router_data<'a, F>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -401,7 +401,7 @@ pub async fn construct_refund_router_data<'a, F>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -604,7 +604,7 @@ pub async fn construct_refund_router_data<'a, F>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) @@ -1028,7 +1028,7 @@ pub async fn construct_accept_dispute_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } @@ -1126,7 +1126,7 @@ pub async fn construct_submit_evidence_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } @@ -1230,7 +1230,7 @@ pub async fn construct_upload_file_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } @@ -1353,7 +1353,7 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } @@ -1454,7 +1454,7 @@ pub async fn construct_defend_dispute_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } @@ -1549,7 +1549,7 @@ pub async fn construct_retrieve_file_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } diff --git a/crates/router/src/core/webhooks/incoming_v2.rs b/crates/router/src/core/webhooks/incoming_v2.rs index 0cf8b2bfe7..464781876c 100644 --- a/crates/router/src/core/webhooks/incoming_v2.rs +++ b/crates/router/src/core/webhooks/incoming_v2.rs @@ -456,31 +456,37 @@ async fn payments_incoming_webhook_flow( ) .await?; - let (payment_data, _req, customer, connector_http_status_code, external_latency) = - Box::pin(payments::payments_operation_core::< - api::PSync, - _, - _, - _, - PaymentStatusData, - >( - &state, - req_state, - merchant_context.clone(), - &profile, - payments::operations::PaymentGet, - api::PaymentsRetrieveRequest { - force_sync: true, - expand_attempts: false, - param: None, - all_keys_required: None, - merchant_connector_details: None, - }, - get_trackers_response, - consume_or_trigger_flow, - HeaderPayload::default(), - )) - .await?; + let ( + payment_data, + _req, + customer, + connector_http_status_code, + external_latency, + connector_response_data, + ) = Box::pin(payments::payments_operation_core::< + api::PSync, + _, + _, + _, + PaymentStatusData, + >( + &state, + req_state, + merchant_context.clone(), + &profile, + payments::operations::PaymentGet, + api::PaymentsRetrieveRequest { + force_sync: true, + expand_attempts: false, + param: None, + return_raw_connector_response: None, + merchant_connector_details: None, + }, + get_trackers_response, + consume_or_trigger_flow, + HeaderPayload::default(), + )) + .await?; let response = payment_data.generate_response( &state, @@ -489,6 +495,7 @@ async fn payments_incoming_webhook_flow( None, &merchant_context, &profile, + Some(connector_response_data), ); lock_action diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs index 4cf0d784a0..c0c362a9dd 100644 --- a/crates/router/src/core/webhooks/utils.rs +++ b/crates/router/src/core/webhooks/utils.rs @@ -133,7 +133,7 @@ pub async fn construct_webhook_router_data( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, }; Ok(router_data) } diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs index e2363633da..163bc2dab2 100644 --- a/crates/router/src/routes/payments.rs +++ b/crates/router/src/routes/payments.rs @@ -2953,7 +2953,7 @@ pub async fn payment_status( force_sync: payload.force_sync, expand_attempts: payload.expand_attempts, param: payload.param.clone(), - all_keys_required: payload.all_keys_required, + return_raw_connector_response: payload.return_raw_connector_response, merchant_connector_details: None, }; diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 57bb8ec242..fabfe3e38d 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -142,7 +142,7 @@ pub async fn execute_connector_processing_step< req: &'b types::RouterData, call_connector_action: payments::CallConnectorAction, connector_request: Option, - all_keys_required: Option, + return_raw_connector_response: Option, ) -> CustomResult, errors::ConnectorError> where T: Clone + Debug + 'static, @@ -302,7 +302,7 @@ where val + external_latency }), ); - if all_keys_required == Some(true) { + if return_raw_connector_response == Some(true) { let mut decoded = String::from_utf8(body.response.as_ref().to_vec()) .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; if decoded.starts_with('\u{feff}') { @@ -310,7 +310,7 @@ where .trim_start_matches('\u{feff}') .to_string(); } - data.whole_connector_response = Some(decoded); + data.raw_connector_response = Some(decoded); } Ok(data) } @@ -1076,13 +1076,17 @@ pub trait Authenticate { None } - fn get_all_keys_required(&self) -> Option { + fn should_return_raw_response(&self) -> Option { None } } #[cfg(feature = "v2")] -impl Authenticate for api_models::payments::PaymentsConfirmIntentRequest {} +impl Authenticate for api_models::payments::PaymentsConfirmIntentRequest { + fn should_return_raw_response(&self) -> Option { + self.return_raw_connector_response + } +} #[cfg(feature = "v2")] impl Authenticate for api_models::payments::ProxyPaymentsRequest {} @@ -1092,7 +1096,9 @@ impl Authenticate for api_models::payments::PaymentsRequest { self.client_secret.as_ref() } - fn get_all_keys_required(&self) -> Option { + fn should_return_raw_response(&self) -> Option { + // In v1, this maps to `all_keys_required` to retain backward compatibility. + // The equivalent field in v2 is `return_raw_connector_response`. self.all_keys_required } } @@ -1123,7 +1129,15 @@ impl Authenticate for api_models::payments::PaymentsPostSessionTokensRequest { impl Authenticate for api_models::payments::PaymentsUpdateMetadataRequest {} impl Authenticate for api_models::payments::PaymentsRetrieveRequest { - fn get_all_keys_required(&self) -> Option { + #[cfg(feature = "v2")] + fn should_return_raw_response(&self) -> Option { + self.return_raw_connector_response + } + + #[cfg(feature = "v1")] + fn should_return_raw_response(&self) -> Option { + // In v1, this maps to `all_keys_required` to retain backward compatibility. + // The equivalent field in v2 is `return_raw_connector_response`. self.all_keys_required } } diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 52e3f267c8..dd64c5b370 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -1151,7 +1151,7 @@ impl ForeignFrom<(&RouterData, T2) .clone(), authentication_id: data.authentication_id.clone(), psd2_sca_exemption_type: data.psd2_sca_exemption_type, - whole_connector_response: data.whole_connector_response.clone(), + raw_connector_response: data.raw_connector_response.clone(), } } } @@ -1219,7 +1219,7 @@ impl psd2_sca_exemption_type: None, additional_merchant_data: data.additional_merchant_data.clone(), connector_mandate_request_reference_id: None, - whole_connector_response: None, + raw_connector_response: None, } } } diff --git a/crates/router/src/types/api/payments.rs b/crates/router/src/types/api/payments.rs index 62738680b1..02fad384f5 100644 --- a/crates/router/src/types/api/payments.rs +++ b/crates/router/src/types/api/payments.rs @@ -5,7 +5,8 @@ pub use api_models::payments::{ }; #[cfg(feature = "v1")] pub use api_models::payments::{ - PaymentListFilterConstraints, PaymentListResponse, PaymentListResponseV2, + PaymentListFilterConstraints, PaymentListResponse, PaymentListResponseV2, PaymentRetrieveBody, + PaymentRetrieveBodyWithCredentials, }; pub use api_models::{ feature_matrix::{ @@ -18,18 +19,17 @@ pub use api_models::{ MandateValidationFields, NextActionType, OpenBankingSessionToken, PayLaterData, PaymentIdType, PaymentListConstraints, PaymentListFilters, PaymentListFiltersV2, PaymentMethodData, PaymentMethodDataRequest, PaymentMethodDataResponse, PaymentOp, - PaymentRetrieveBody, PaymentRetrieveBodyWithCredentials, PaymentsAggregateResponse, - PaymentsApproveRequest, PaymentsCancelRequest, PaymentsCaptureRequest, - PaymentsCompleteAuthorizeRequest, PaymentsDynamicTaxCalculationRequest, - PaymentsDynamicTaxCalculationResponse, PaymentsExternalAuthenticationRequest, - PaymentsIncrementalAuthorizationRequest, PaymentsManualUpdateRequest, - PaymentsPostSessionTokensRequest, PaymentsPostSessionTokensResponse, - PaymentsRedirectRequest, PaymentsRedirectionResponse, PaymentsRejectRequest, - PaymentsRequest, PaymentsResponse, PaymentsResponseForm, PaymentsRetrieveRequest, - PaymentsSessionRequest, PaymentsSessionResponse, PaymentsStartRequest, - PaymentsUpdateMetadataRequest, PaymentsUpdateMetadataResponse, PgRedirectResponse, - PhoneDetails, RedirectionResponse, SessionToken, UrlDetails, VaultSessionDetails, - VerifyRequest, VerifyResponse, VgsSessionDetails, WalletData, + PaymentsAggregateResponse, PaymentsApproveRequest, PaymentsCancelRequest, + PaymentsCaptureRequest, PaymentsCompleteAuthorizeRequest, + PaymentsDynamicTaxCalculationRequest, PaymentsDynamicTaxCalculationResponse, + PaymentsExternalAuthenticationRequest, PaymentsIncrementalAuthorizationRequest, + PaymentsManualUpdateRequest, PaymentsPostSessionTokensRequest, + PaymentsPostSessionTokensResponse, PaymentsRedirectRequest, PaymentsRedirectionResponse, + PaymentsRejectRequest, PaymentsRequest, PaymentsResponse, PaymentsResponseForm, + PaymentsRetrieveRequest, PaymentsSessionRequest, PaymentsSessionResponse, + PaymentsStartRequest, PaymentsUpdateMetadataRequest, PaymentsUpdateMetadataResponse, + PgRedirectResponse, PhoneDetails, RedirectionResponse, SessionToken, UrlDetails, + VaultSessionDetails, VerifyRequest, VerifyResponse, VgsSessionDetails, WalletData, }, }; pub use common_types::payments::{AcceptanceType, CustomerAcceptance, OnlineMandate}; diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs index c9be34037c..8298be10aa 100644 --- a/crates/router/src/types/api/verify_connector.rs +++ b/crates/router/src/types/api/verify_connector.rs @@ -127,7 +127,7 @@ impl VerifyConnectorData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, } } } diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index 61272a0587..cf0889931d 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -133,7 +133,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, } } @@ -206,7 +206,7 @@ fn construct_refund_router_data() -> types::RefundsRouterData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - whole_connector_response: None, + raw_connector_response: None, } } diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index bf9bc35533..db3aeddfb8 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -553,7 +553,7 @@ pub trait ConnectorActions: Connector { connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, authentication_id: None, - whole_connector_response: None, + raw_connector_response: None, } }