Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connector): fix globalpay error handling #464

Merged
merged 8 commits into from
Jan 27, 2023
Merged
6 changes: 4 additions & 2 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl TryFrom<&types::ConnectorAuthType> for CybersourceAuthType {
}
}
#[derive(Debug, Default, Clone, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "UPPERCASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CybersourcePaymentStatus {
Authorized,
Succeeded,
Expand All @@ -235,6 +235,7 @@ pub enum CybersourcePaymentStatus {
Reversed,
Pending,
Declined,
AuthorizedPendingReview,
Transmitted,
#[default]
Processing,
Expand All @@ -243,7 +244,8 @@ pub enum CybersourcePaymentStatus {
impl From<CybersourcePaymentStatus> for enums::AttemptStatus {
fn from(item: CybersourcePaymentStatus) -> Self {
match item {
CybersourcePaymentStatus::Authorized => Self::Authorized,
CybersourcePaymentStatus::Authorized
| CybersourcePaymentStatus::AuthorizedPendingReview => Self::Authorized,
CybersourcePaymentStatus::Succeeded | CybersourcePaymentStatus::Transmitted => {
Self::Charged
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/globalpay/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub enum FingerprintPresenceIndicator {
}

/// Indicates where a transaction is in its lifecycle.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum GlobalpayPaymentStatus {
/// A Transaction has been successfully authorized and captured. The funding
Expand Down
36 changes: 27 additions & 9 deletions crates/router/src/connector/globalpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use super::{
};
use crate::{
connector::utils::{self, CardData, PaymentsRequestData},
consts,
core::errors,
types::{self, api, storage::enums},
types::{self, api, storage::enums, ErrorResponse},
};

impl TryFrom<&types::PaymentsAuthorizeRouterData> for GlobalpayPaymentsRequest {
Expand Down Expand Up @@ -149,6 +150,28 @@ impl From<GlobalpayPaymentStatus> for enums::RefundStatus {
}
}

fn get_payment_response(
status: enums::AttemptStatus,
response: GlobalpayPaymentsResponse,
) -> Result<types::PaymentsResponseData, ErrorResponse> {
match status {
enums::AttemptStatus::Failure => Err(ErrorResponse {
message: response
.payment_method
.and_then(|pm| pm.message)
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
..Default::default()
}),
_ => Ok(types::PaymentsResponseData::TransactionResponse {
resource_id: types::ResponseId::ConnectorTransactionId(response.id),
redirection_data: None,
redirect: false,
mandate_reference: None,
connector_metadata: None,
}),
}
}

impl<F, T>
TryFrom<types::ResponseRouterData<F, GlobalpayPaymentsResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData>
Expand All @@ -162,15 +185,10 @@ impl<F, T>
types::PaymentsResponseData,
>,
) -> Result<Self, Self::Error> {
let status = enums::AttemptStatus::from(item.response.status);
Ok(Self {
status: enums::AttemptStatus::from(item.response.status),
response: Ok(types::PaymentsResponseData::TransactionResponse {
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),
redirection_data: None,
redirect: false,
mandate_reference: None,
connector_metadata: None,
}),
status,
response: get_payment_response(status, item.response),
..item.data
})
}
Expand Down