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): [SHIFT4] Fix 3DS payments and api key (#9480)

DEEPANSHU BANSAL97fe0723922b
diff --git a/crates/hyperswitch_connectors/src/connectors/shift4.rs b/crates/hyperswitch_connectors/src/connectors/shift4.rs
index 3af15de507..01b23f61e5 100644
--- a/crates/hyperswitch_connectors/src/connectors/shift4.rs
+++ b/crates/hyperswitch_connectors/src/connectors/shift4.rs
@@ -2,6 +2,7 @@ pub mod transformers;
use std::sync::LazyLock;
use api_models::webhooks::IncomingWebhookEvent;
+use base64::Engine;
use common_enums::enums;
use common_utils::{
errors::CustomResult,
@@ -46,7 +47,7 @@ use hyperswitch_interfaces::{
types::{self, Response},
webhooks::{IncomingWebhook, IncomingWebhookRequestDetails},
};
-use masking::Mask;
+use masking::{Mask, PeekInterface};
use transformers::{self as shift4, Shift4PaymentsRequest, Shift4RefundRequest};
use crate::{
@@ -111,9 +112,13 @@ impl ConnectorCommon for Shift4 {
) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
let auth = shift4::Shift4AuthType::try_from(auth_type)
.change_context(errors::ConnectorError::FailedToObtainAuthType)?;
+ let api_key = format!(
+ "Basic {}",
+ common_utils::consts::BASE64_ENGINE.encode(format!("{}:", auth.api_key.peek()))
+ );
Ok(vec![(
headers::AUTHORIZATION.to_string(),
- auth.api_key.into_masked(),
+ api_key.into_masked(),
)])
}
@@ -277,7 +282,19 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
}
}
-impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Shift4 {}
+impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Shift4 {
+ fn build_request(
+ &self,
+ _req: &hyperswitch_domain_models::types::PaymentsCancelRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Err(errors::ConnectorError::NotSupported {
+ message: "Void".to_string(),
+ connector: "Shift4",
+ }
+ .into())
+ }
+}
impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Shift4 {
fn get_headers(
@@ -373,6 +390,12 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
req: &PaymentsCaptureRouterData,
connectors: &Connectors,
) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ if req.request.amount_to_capture != req.request.payment_amount {
+ Err(errors::ConnectorError::NotSupported {
+ message: "Partial Capture".to_string(),
+ connector: "Shift4",
+ })?
+ }
Ok(Some(
RequestBuilder::new()
.method(Method::Post)
@@ -488,7 +511,7 @@ impl ConnectorIntegration<PreProcessing, PaymentsPreProcessingData, PaymentsResp
)?;
let connector_router_data = shift4::Shift4RouterData::try_from((amount, req))?;
let connector_req = Shift4PaymentsRequest::try_from(&connector_router_data)?;
- Ok(RequestContent::Json(Box::new(connector_req)))
+ Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
}
fn build_request(
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Shift4.js b/cypress-tests/cypress/e2e/configs/Payment/Shift4.js
index 82d1e70ecc..2b80bf8b5e 100644
--- a/cypress-tests/cypress/e2e/configs/Payment/Shift4.js
+++ b/cypress-tests/cypress/e2e/configs/Payment/Shift4.js
@@ -33,7 +33,7 @@ const successfulNo3DSCardDetails = {
const successfulThreeDSTestCardDetails = {
...successfulNo3DSCardDetails,
- card_number: "4000000000003063", // Using standard test card with authentication_type: "three_ds"
+ card_number: "4012001800000016", // Using standard test card with authentication_type: "three_ds"
};
const failedNo3DSCardDetails = {
@@ -43,11 +43,11 @@ const failedNo3DSCardDetails = {
const payment_method_data_3ds = {
card: {
- last4: "3063",
+ last4: "0016",
card_type: "DEBIT",
card_network: "Visa",
- card_issuer: "STRIPE PAYMENTS UK LIMITED",
- card_issuing_country: "UNITEDKINGDOM",
+ card_issuer: "VISA PRODUCTION SUPPORT CLIENT BID 1",
+ card_issuing_country: "UNITEDSTATES",
card_isin: "401200",
card_extended_bin: null,
card_exp_month: "10",
@@ -267,6 +267,9 @@ export const connectorDetails = {
},
},
PartialCapture: {
+ Configs: {
+ TRIGGER_SKIP: true, // Partial Capture is not supported in Shift4
+ },
Request: {
amount_to_capture: 2000,
},