Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(core): Extend Support for whole_connector_response in Cancel Flow (#10981)
Anurag7509f40c32f5
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex f47b55a377..900382626e 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -27017,6 +27017,11 @@}],"nullable": true+ },+ "all_keys_required": {+ "type": "boolean",+ "description": "If enabled, provides whole connector response",+ "nullable": true}}},diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 80c0f3a6e2..9796f532a0 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -20465,6 +20465,11 @@"type": "string","description": "The reason for the payment cancel","nullable": true+ },+ "return_raw_connector_response": {+ "type": "boolean",+ "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.rsindex 56491d2582..c8310997cc 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -6462,6 +6462,8 @@ pub struct PaymentsCaptureResponse {pub struct PaymentsCancelRequest {/// The reason for the payment cancelpub cancellation_reason: Option<String>,+ /// If true, returns stringified connector raw response body+ pub return_raw_connector_response: Option<bool>,}#[cfg(feature = "v2")]@@ -10900,6 +10902,9 @@ pub struct PaymentsCancelRequest {#[schema(value_type = Option<MerchantConnectorDetailsWrap>, deprecated)]#[smithy(value_type = "Option<MerchantConnectorDetailsWrap>")]pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,+ /// If enabled, provides whole connector response+ #[smithy(value_type = "Option<bool>")]+ pub all_keys_required: Option<bool>,}/// Request to cancel a payment when the payment is already captureddiff --git a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rsindex e427837d23..1ca24ca373 100644--- a/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/peachpayments/transformers.rs@@ -827,14 +827,6 @@ pub struct EcommerceCardPaymentOnlyResponseData {pub trace_id: Option<String>,}-fn is_payment_success(value: Option<&String>) -> bool {- if let Some(val) = value {- val == "00" || val == "08" || val == "X94"- } else {- false- }-}-fn get_error_code(response_code: Option<&ResponseCode>) -> String {response_code.and_then(|code| code.value())@@ -870,12 +862,7 @@ pub fn get_peachpayments_response(errors::ConnectorError,> {let status = common_enums::AttemptStatus::from(response.transaction_result);- let payments_response = if !is_payment_success(- response- .response_code- .as_ref()- .and_then(|code| code.value()),- ) {+ let payments_response = if utils::is_payment_failure(status) {Err(ErrorResponse {code: get_error_code(response.response_code.as_ref()),message: get_error_message(response.response_code.as_ref()),@@ -920,12 +907,7 @@ pub fn get_webhook_response(.transaction.ok_or(errors::ConnectorError::WebhookResourceObjectNotFound)?;let status = common_enums::AttemptStatus::from(transaction.transaction_result);- let webhook_response = if !is_payment_success(- transaction- .response_code- .as_ref()- .and_then(|code| code.value()),- ) {+ let webhook_response = if utils::is_payment_failure(status) {Err(ErrorResponse {code: get_error_code(transaction.response_code.as_ref()),message: get_error_message(transaction.response_code.as_ref()),@@ -995,12 +977,7 @@ impl<F, T> TryFrom<ResponseRouterData<F, PeachpaymentsCaptureResponse, T, Paymenlet status = common_enums::AttemptStatus::from(item.response.transaction_result);// Check if it's an error response- let response = if !is_payment_success(- item.response- .response_code- .as_ref()- .and_then(|code| code.value()),- ) {+ let response = if utils::is_payment_failure(status) {Err(ErrorResponse {code: get_error_code(item.response.response_code.as_ref()),message: get_error_message(item.response.response_code.as_ref()),diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs b/crates/router/src/core/fraud_check/operation/fraud_check_post.rsindex 980340567d..7d8511308f 100644--- a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs+++ b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs@@ -253,6 +253,7 @@ wherepayment_id: frm_data.payment_intent.get_id().to_owned(),cancellation_reason: frm_data.fraud_check.frm_error.clone(),merchant_connector_details: None,+ all_keys_required: None,};let cancel_res = Box::pin(payments::payments_core::<Void,diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rsindex 4e1939e726..2cd162730a 100644--- a/crates/router/src/core/payments/flows/cancel_flow.rs+++ b/crates/router/src/core/payments/flows/cancel_flow.rs@@ -86,7 +86,7 @@ impl Feature<api::Void, types::PaymentsCancelData>connector_request: Option<services::Request>,_business_profile: &domain::Profile,_header_payload: hyperswitch_domain_models::payments::HeaderPayload,- _return_raw_connector_response: Option<bool>,+ return_raw_connector_response: Option<bool>,_gateway_context: payments::gateway::context::RouterGatewayContext,) -> RouterResult<Self> {metrics::PAYMENT_CANCEL_COUNT.add(@@ -106,7 +106,7 @@ impl Feature<api::Void, types::PaymentsCancelData>&self,call_connector_action,connector_request,- None,+ return_raw_connector_response,).await.to_payment_failed_response()?;diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rsindex ced9a4f023..84c64c5756 100644--- a/crates/router/src/services/api.rs+++ b/crates/router/src/services/api.rs@@ -759,7 +759,19 @@ impl Authenticate for api_models::payments::PaymentsRetrieveRequest {self.all_keys_required}}-impl Authenticate for api_models::payments::PaymentsCancelRequest {}+impl Authenticate for api_models::payments::PaymentsCancelRequest {+ #[cfg(feature = "v2")]+ fn should_return_raw_response(&self) -> Option<bool> {+ self.return_raw_connector_response+ }++ #[cfg(feature = "v1")]+ fn should_return_raw_response(&self) -> Option<bool> {+ // 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+ }+}impl Authenticate for api_models::payments::PaymentsCancelPostCaptureRequest {}impl Authenticate for api_models::payments::PaymentsCaptureRequest {#[cfg(feature = "v2")]