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): [Zift] Fix Connector Void Flow (#10205)

awasthi2115d2e01d48e0
diff --git a/config/config.example.toml b/config/config.example.toml
index 78b23c105d..effa8c4ed1 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -330,7 +330,7 @@ worldpayvantiv.secondary_base_url = "https://onlinessr.vantivprelive.com"
worldpayvantiv.third_base_url = "https://services.vantivprelive.com"
worldpayxml.base_url = "https://secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp"
xendit.base_url = "https://api.xendit.co"
-zift.base_url = "https://sandbox-secure.zift.io/gates/xurl?"
+zift.base_url = "https://sandbox-secure.zift.io/"
zsl.base_url = "https://api.sitoffalb.net/"
zen.base_url = "https://api.zen-test.com/"
zen.secondary_base_url = "https://secure.zen-test.com/"
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index 0c378be14f..34cda0d416 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -168,7 +168,7 @@ worldpayvantiv.secondary_base_url = "https://onlinessr.vantivprelive.com"
worldpayvantiv.third_base_url = "https://services.vantivprelive.com"
worldpayxml.base_url = "https://secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp"
xendit.base_url = "https://api.xendit.co"
-zift.base_url = "https://sandbox-secure.zift.io/gates/xurl?"
+zift.base_url = "https://sandbox-secure.zift.io/"
zen.base_url = "https://api.zen-test.com/"
zen.secondary_base_url = "https://secure.zen-test.com/"
zsl.base_url = "https://api.sitoffalb.net/"
diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml
index 1c9df2d09d..aada5688f0 100644
--- a/crates/connector_configs/toml/development.toml
+++ b/crates/connector_configs/toml/development.toml
@@ -7592,6 +7592,7 @@ options=["CRYPTOGRAM_3DS"]
[[zift.debit]]
payment_method_type = "CartesBancaires"
[[zift.debit]]
+ payment_method_type = "UnionPay"
[zift.connector_auth.SignatureKey]
api_key="Username"
api_secret="Password"
diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml
index 4d065389b8..18b72a85e5 100644
--- a/crates/connector_configs/toml/production.toml
+++ b/crates/connector_configs/toml/production.toml
@@ -6328,6 +6328,7 @@ options=["CRYPTOGRAM_3DS"]
[[zift.debit]]
payment_method_type = "CartesBancaires"
[[zift.debit]]
+ payment_method_type = "UnionPay"
[zift.connector_auth.SignatureKey]
api_key="Username"
api_secret="Password"
diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml
index 388a0814e2..7dd7f84bb0 100644
--- a/crates/connector_configs/toml/sandbox.toml
+++ b/crates/connector_configs/toml/sandbox.toml
@@ -7565,12 +7565,12 @@ options=["CRYPTOGRAM_3DS"]
[[zift.debit]]
payment_method_type = "CartesBancaires"
[[zift.debit]]
+ payment_method_type = "UnionPay"
[zift.connector_auth.SignatureKey]
api_key="Username"
api_secret="Password"
key1="Account ID"
-api_key = "API Key"
[payjustnow]
[payjustnow.connector_auth.BodyKey]
api_key = "Signing Key"
diff --git a/crates/hyperswitch_connectors/src/connectors/zift.rs b/crates/hyperswitch_connectors/src/connectors/zift.rs
index 0091cfb056..c98c5858ac 100644
--- a/crates/hyperswitch_connectors/src/connectors/zift.rs
+++ b/crates/hyperswitch_connectors/src/connectors/zift.rs
@@ -28,7 +28,7 @@ use hyperswitch_domain_models::{
},
types::{
PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
- PaymentsSyncRouterData, RefundSyncRouterData, RefundsRouterData,
+ PaymentsSyncRouterData, RefundsRouterData,
},
};
use hyperswitch_interfaces::{
@@ -423,82 +423,77 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
}
impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Zift {
- // fn get_headers(
- // &self,
- // req: &PaymentsCancelRouterData,
- // connectors: &Connectors,
- // ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
- // self.build_headers(req, connectors)
- // }
+ fn get_headers(
+ &self,
+ req: &PaymentsCancelRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
- // fn get_content_type(&self) -> &'static str {
- // self.common_get_content_type()
- // }
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
- // fn get_url(
- // &self,
- // _req: &PaymentsCancelRouterData,
- // connectors: &Connectors,
- // ) -> CustomResult<String, errors::ConnectorError> {
- // Ok(format!("{}gates/xurl", self.base_url(connectors)))
- // }
+ fn get_url(
+ &self,
+ _req: &PaymentsCancelRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Ok(format!("{}gates/xurl", self.base_url(connectors)))
+ }
- // fn get_request_body(
- // &self,
- // req: &PaymentsCancelRouterData,
- // _connectors: &Connectors,
- // ) -> CustomResult<RequestContent, errors::ConnectorError> {
- // let connector_req = zift::ZiftCancelRequest::try_from(req)?;
- // Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
- // }
+ fn get_request_body(
+ &self,
+ req: &PaymentsCancelRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = zift::ZiftCancelRequest::try_from(req)?;
+ Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
+ }
fn build_request(
&self,
- _req: &PaymentsCancelRouterData,
- _connectors: &Connectors,
+ req: &PaymentsCancelRouterData,
+ connectors: &Connectors,
) -> CustomResult<Option<Request>, errors::ConnectorError> {
- Err(errors::ConnectorError::FlowNotSupported {
- flow: "Void".to_owned(),
- connector: "Zift".to_owned(),
- }
- .into())
- // Ok(Some(
- // RequestBuilder::new()
- // .method(Method::Post)
- // .url(&types::PaymentsVoidType::get_url(self, req, connectors)?)
- // .attach_default_headers()
- // .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?)
- // .set_body(types::PaymentsVoidType::get_request_body(
- // self, req, connectors,
- // )?)
- // .build(),
- // ))
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::PaymentsVoidType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?)
+ .set_body(types::PaymentsVoidType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ ))
}
- // fn handle_response(
- // &self,
- // data: &PaymentsCancelRouterData,
- // event_builder: Option<&mut ConnectorEvent>,
- // res: Response,
- // ) -> CustomResult<PaymentsCancelRouterData, errors::ConnectorError> {
- // let response: zift::ZiftVoidResponse = serde_urlencoded::from_bytes(&res.response)
- // .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,
- // })
- // }
+ fn handle_response(
+ &self,
+ data: &PaymentsCancelRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsCancelRouterData, errors::ConnectorError> {
+ let response: zift::ZiftVoidResponse = serde_urlencoded::from_bytes(&res.response)
+ .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,
+ })
+ }
- // fn get_error_response(
- // &self,
- // res: Response,
- // event_builder: Option<&mut ConnectorEvent>,
- // ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
- // self.build_error_response(res, event_builder)
- // }
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
}
impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Zift {
@@ -604,28 +599,22 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Zift {
// Ok(format!("{}gates/xurl", self.base_url(connectors)))
// }
- fn build_request(
- &self,
- _req: &RefundSyncRouterData,
- _connectors: &Connectors,
- ) -> CustomResult<Option<Request>, errors::ConnectorError> {
- // Ok(Some(
- // RequestBuilder::new()
- // .method(Method::Post)
- // .url(&types::RefundSyncType::get_url(self, req, connectors)?)
- // .attach_default_headers()
- // .headers(types::RefundSyncType::get_headers(self, req, connectors)?)
- // .set_body(types::RefundSyncType::get_request_body(
- // self, req, connectors,
- // )?)
- // .build(),
- // ))
- Err(errors::ConnectorError::FlowNotSupported {
- flow: "RefundSync".to_owned(),
- connector: "Zift".to_owned(),
- }
- .into())
- }
+ // fn build_request(
+ // &self,
+ // _req: &RefundSyncRouterData,
+ // _connectors: &Connectors,
+ // ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ // Ok(Some(
+ // RequestBuilder::new()
+ // .method(Method::Post)
+ // .url(&types::RefundSyncType::get_url(self, req, connectors)?)
+ // .attach_default_headers()
+ // .headers(types::RefundSyncType::get_headers(self, req, connectors)?)
+ // .set_body(types::RefundSyncType::get_request_body(
+ // self, req, connectors,
+ // )?)
+ // .build(),
+ // ))
// }
// fn handle_response(
@@ -634,15 +623,15 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Zift {
// event_builder: Option<&mut ConnectorEvent>,
// res: Response,
// ) -> CustomResult<RefundSyncRouterData, errors::ConnectorError> {
- // let response: zift::RefundResponse = serde_urlencoded::from_bytes(&res.response)
- // .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,
- // })
+ // let response: zift::RefundResponse = serde_urlencoded::from_bytes(&res.response)
+ // .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,
+ // })
// }
fn get_error_response(
diff --git a/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs b/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs
index 86e8fc6e6a..61f36d39bf 100644
--- a/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/zift/transformers.rs
@@ -9,8 +9,8 @@ use hyperswitch_domain_models::{
router_request_types::{PaymentsAuthorizeData, PaymentsSyncData, ResponseId},
router_response_types::{MandateReference, PaymentsResponseData, RefundsResponseData},
types::{
- PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
- RefundsRouterData,
+ PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
+ PaymentsSyncRouterData, RefundsRouterData,
},
};
use hyperswitch_interfaces::{
@@ -21,7 +21,10 @@ use masking::Secret;
use serde::{Deserialize, Serialize};
use crate::{
- types::{PaymentsCaptureResponseRouterData, RefundsResponseRouterData, ResponseRouterData},
+ types::{
+ PaymentsCancelResponseRouterData, PaymentsCaptureResponseRouterData,
+ RefundsResponseRouterData, ResponseRouterData,
+ },
utils::{AdditionalCardInfo, CardData, PaymentsAuthorizeRequestData, RouterData as _},
};
@@ -75,6 +78,7 @@ pub enum RequestType {
Capture,
Refund,
Find,
+ Void,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -467,6 +471,7 @@ pub struct ZiftRefundRequest {
auth: ZiftAuthType,
transaction_id: String,
amount: StringMinorUnit,
+ transaction_code: String,
}
impl<F> TryFrom<&ZiftRouterData<&RefundsRouterData<F>>> for ZiftRefundRequest {
@@ -478,21 +483,17 @@ impl<F> TryFrom<&ZiftRouterData<&RefundsRouterData<F>>> for ZiftRefundRequest {
auth,
transaction_id: item.router_data.request.connector_transaction_id.clone(),
amount: item.amount.to_owned(),
+ transaction_code: item.router_data.request.refund_id.clone(),
})
}
}
-
-// impl From<ResponseCode> for enums::RefundStatus {
-// fn from(item: enums::RefundStatus) -> Self {
-// match item {}
-// }
-// }
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RefundResponse {
- transaction_id: String,
+ transaction_id: Option<String>,
response_code: String,
response_message: Option<String>,
+ transaction_code: Option<String>,
}
impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRouterData<Execute> {
@@ -511,7 +512,12 @@ impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRout
};
let response = if refund_response.response_code.is_approved() {
Ok(RefundsResponseData {
- connector_refund_id: item.response.transaction_id.to_string(),
+ connector_refund_id: item
+ .response
+ .transaction_id
+ .clone()
+ .or(item.response.transaction_code.clone())
+ .ok_or(errors::ConnectorError::MissingConnectorRefundID)?,
refund_status,
})
} else {
@@ -704,3 +710,82 @@ impl TryFrom<&ZiftRouterData<&PaymentsCaptureRouterData>> for ZiftCaptureRequest
})
}
}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ZiftCancelRequest {
+ request_type: RequestType,
+ #[serde(flatten)]
+ auth: ZiftAuthType,
+ transaction_id: i64,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "camelCase")]
+pub struct ZiftVoidResponse {
+ pub response_code: String,
+ pub response_message: String,
+}
+
+impl TryFrom<&PaymentsCancelRouterData> for ZiftCancelRequest {
+ type Error = error_stack::Report<errors::ConnectorError>;
+
+ fn try_from(item: &PaymentsCancelRouterData) -> Result<Self, Self::Error> {
+ let auth = ZiftAuthType::try_from(&item.connector_auth_type)?;
+ Ok(Self {
+ request_type: RequestType::Void,
+ auth,
+ transaction_id: item
+ .request
+ .connector_transaction_id
+ .parse::<i64>()
+ .map_err(|_| errors::ConnectorError::ResponseDeserializationFailed)?,
+ })
+ }
+}
+
+impl TryFrom<PaymentsCancelResponseRouterData<ZiftVoidResponse>> for PaymentsCancelRouterData {
+ type Error = error_stack::Report<errors::ConnectorError>;
+
+ fn try_from(
+ item: PaymentsCancelResponseRouterData<ZiftVoidResponse>,
+ ) -> Result<Self, Self::Error> {
+ let void_response = &item.response;
+
+ let response = if void_response.response_code.is_approved() {
+ Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::NoResponseId,
+ redirection_data: Box::new(None),
+ mandate_reference: Box::new(None),
+ connector_metadata: None,
+ network_txn_id: None,
+ connector_response_reference_id: None,
+ incremental_authorization_allowed: None,
+ charges: None,
+ })
+ } else {
+ Err(ErrorResponse {
+ code: void_response.response_code.to_string(),
+ message: void_response.response_message.clone(),
+ reason: Some(void_response.response_message.clone()),
+ status_code: item.http_code,
+ attempt_status: None,
+ connector_transaction_id: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_metadata: None,
+ })
+ };
+
+ Ok(Self {
+ status: if void_response.response_code.is_approved() {
+ common_enums::AttemptStatus::Voided
+ } else {
+ common_enums::AttemptStatus::Failure
+ },
+ response,
+ ..item.data
+ })
+ }
+}