Skip to content

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

fix(connector): move authorised status to charged in setup mandate (#3017)

SamraatBansal663754d629d5
diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs
index 1868611184..1de107af08 100644
--- a/crates/router/src/connector/cybersource.rs
+++ b/crates/router/src/connector/cybersource.rs
@@ -307,18 +307,15 @@ impl
data: &types::SetupMandateRouterData,
res: types::Response,
) -> CustomResult<types::SetupMandateRouterData, errors::ConnectorError> {
- let response: cybersource::CybersourcePaymentsResponse = res
+ let response: cybersource::CybersourceSetupMandatesResponse = res
.response
- .parse_struct("CybersourceMandateResponse")
+ .parse_struct("CybersourceSetupMandatesResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- types::RouterData::try_from((
- types::ResponseRouterData {
- response,
- data: data.clone(),
- http_code: res.status_code,
- },
- false,
- ))
+ types::RouterData::try_from(types::ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
}
fn get_error_response(
diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs
index 656c45b6d6..81df299667 100644
--- a/crates/router/src/connector/cybersource/transformers.rs
+++ b/crates/router/src/connector/cybersource/transformers.rs
@@ -499,6 +499,16 @@ pub struct CybersourcePaymentsResponse {
token_information: Option<CybersourceTokenInformation>,
}
+#[derive(Debug, Clone, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CybersourceSetupMandatesResponse {
+ id: String,
+ status: CybersourcePaymentStatus,
+ error_information: Option<CybersourceErrorInformation>,
+ client_reference_information: Option<ClientReferenceInformation>,
+ token_information: Option<CybersourceTokenInformation>,
+}
+
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientReferenceInformation {
@@ -553,7 +563,69 @@ impl<F, T>
reason: Some(error.reason),
status_code: item.http_code,
attempt_status: None,
- connector_transaction_id: None,
+ connector_transaction_id: Some(item.response.id),
+ }),
+ _ => Ok(types::PaymentsResponseData::TransactionResponse {
+ resource_id: types::ResponseId::ConnectorTransactionId(
+ item.response.id.clone(),
+ ),
+ redirection_data: None,
+ mandate_reference,
+ connector_metadata: None,
+ network_txn_id: None,
+ connector_response_reference_id: item
+ .response
+ .client_reference_information
+ .map(|cref| cref.code)
+ .unwrap_or(Some(item.response.id)),
+ }),
+ },
+ ..item.data
+ })
+ }
+}
+
+impl<F, T>
+ TryFrom<
+ types::ResponseRouterData<
+ F,
+ CybersourceSetupMandatesResponse,
+ T,
+ types::PaymentsResponseData,
+ >,
+ > for types::RouterData<F, T, types::PaymentsResponseData>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: types::ResponseRouterData<
+ F,
+ CybersourceSetupMandatesResponse,
+ T,
+ types::PaymentsResponseData,
+ >,
+ ) -> Result<Self, Self::Error> {
+ let mandate_reference =
+ item.response
+ .token_information
+ .map(|token_info| types::MandateReference {
+ connector_mandate_id: Some(token_info.instrument_identifier.id),
+ payment_method_id: None,
+ });
+ let mut mandate_status: enums::AttemptStatus = item.response.status.into();
+ if matches!(mandate_status, enums::AttemptStatus::Authorized) {
+ //In case of zero auth mandates we want to make the payment reach the terminal status so we are converting the authorized status to charged as well.
+ mandate_status = enums::AttemptStatus::Charged
+ }
+ Ok(Self {
+ status: mandate_status,
+ response: match item.response.error_information {
+ Some(error) => Err(types::ErrorResponse {
+ code: consts::NO_ERROR_CODE.to_string(),
+ message: error.message,
+ reason: Some(error.reason),
+ status_code: item.http_code,
+ attempt_status: None,
+ connector_transaction_id: Some(item.response.id),
}),
_ => Ok(types::PaymentsResponseData::TransactionResponse {
resource_id: types::ResponseId::ConnectorTransactionId(