Skip to content

Commit

Permalink
fix(connector): move authorised status to charged in setup mandate (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SamraatBansal authored and SanchithHegde committed Dec 6, 2023
1 parent 6c15fc3 commit 29b2e4c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 10 deletions.
17 changes: 7 additions & 10 deletions crates/router/src/connector/cybersource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,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(
Expand Down
71 changes: 71 additions & 0 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,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 {
Expand Down Expand Up @@ -573,6 +583,67 @@ impl<F, T>
}
}

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,
}),
_ => 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
})
}
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CybersourceTransactionResponse {
Expand Down

0 comments on commit 29b2e4c

Please sign in to comment.