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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(connector): [iMerchant Solutions] Retrieve Webhook_Object_Reference_Id (#12008)
Anurag4f5f7a0c9e1d
diff --git a/crates/hyperswitch_connectors/src/connectors/imerchantsolutions.rs b/crates/hyperswitch_connectors/src/connectors/imerchantsolutions.rsindex 8aaee852d8..6d1a030f57 100644--- a/crates/hyperswitch_connectors/src/connectors/imerchantsolutions.rs+++ b/crates/hyperswitch_connectors/src/connectors/imerchantsolutions.rs@@ -5,7 +5,7 @@ use std::sync::LazyLock;use common_enums::enums;use common_utils::{errors::CustomResult,- ext_traits::BytesExt,+ ext_traits::{ByteSliceExt, BytesExt},request::{Method, Request, RequestBuilder, RequestContent},types::{AmountConvertor, MinorUnit, MinorUnitForConnector},};@@ -43,7 +43,7 @@ use hyperswitch_interfaces::{types::{self, Response},webhooks,};-use hyperswitch_masking::{ExposeInterface, Mask};+use hyperswitch_masking::Mask;use transformers as imerchantsolutions;use crate::{constants::headers, types::ResponseRouterData, utils};@@ -124,10 +124,20 @@ impl ConnectorCommon for Imerchantsolutions {{let auth = imerchantsolutions::ImerchantsolutionsAuthType::try_from(auth_type).change_context(errors::ConnectorError::FailedToObtainAuthType)?;- Ok(vec![(++ let mut auth_header = vec![(headers::AUTHORIZATION.to_string(),- auth.api_key.expose().into_masked(),- )])+ auth.api_key.into_masked(),+ )];++ if let Some(merchant_id) = auth.merchant_id {+ auth_header.push((+ headers::X_MERCHANT_ID.to_string(),+ merchant_id.into_masked(),+ ));+ }++ Ok(auth_header)}fn build_error_response(@@ -606,9 +616,31 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Imerchantimpl webhooks::IncomingWebhook for Imerchantsolutions {fn get_webhook_object_reference_id(&self,- _request: &webhooks::IncomingWebhookRequestDetails<'_>,+ request: &webhooks::IncomingWebhookRequestDetails<'_>,) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {- Err(report!(errors::ConnectorError::WebhooksNotImplemented))+ let webhook_body: transformers::ImerchantsolutionsWebhookData = request+ .body+ .parse_struct("ImerchantsolutionsWebhookData")+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;++ match webhook_body.event_type {+ transformers::ImerchantsolutionsWebhookEventType::PaymentCompleted+ | transformers::ImerchantsolutionsWebhookEventType::PaymentCancelled+ | transformers::ImerchantsolutionsWebhookEventType::PaymentFailed => {+ Ok(api_models::webhooks::ObjectReferenceId::PaymentId(+ api_models::payments::PaymentIdType::ConnectorTransactionId(+ webhook_body.psp_reference,+ ),+ ))+ }+ transformers::ImerchantsolutionsWebhookEventType::PaymentRefunded => {+ Ok(api_models::webhooks::ObjectReferenceId::RefundId(+ api_models::webhooks::RefundIdType::ConnectorRefundId(+ webhook_body.psp_reference,+ ),+ ))+ }+ }}fn get_webhook_event_type(@@ -695,7 +727,8 @@ static IMERCHANTSOLUTIONS_CONNECTOR_INFO: ConnectorInfo = ConnectorInfo {integration_status: enums::ConnectorIntegrationStatus::Alpha,};-static IMERCHANTSOLUTIONS_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 0] = [];+static IMERCHANTSOLUTIONS_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 2] =+ [enums::EventClass::Payments, enums::EventClass::Refunds];impl ConnectorSpecifications for Imerchantsolutions {fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {diff --git a/crates/hyperswitch_connectors/src/connectors/imerchantsolutions/transformers.rs b/crates/hyperswitch_connectors/src/connectors/imerchantsolutions/transformers.rsindex 1e02afa97c..aba663bf18 100644--- a/crates/hyperswitch_connectors/src/connectors/imerchantsolutions/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/imerchantsolutions/transformers.rs@@ -1,5 +1,5 @@use common_enums::enums;-use common_utils::types::MinorUnit;+use common_utils::{pii, types::MinorUnit};use hyperswitch_domain_models::{payment_method_data::PaymentMethodData,router_data::{ConnectorAuthType, RouterData},@@ -67,6 +67,7 @@ impl TryFrom<&ImerchantsolutionsRouterData<&PaymentsAuthorizeRouterData>>// Auth Structpub struct ImerchantsolutionsAuthType {pub(super) api_key: Secret<String>,+ pub(super) merchant_id: Option<Secret<String>>,}impl TryFrom<&ConnectorAuthType> for ImerchantsolutionsAuthType {@@ -75,6 +76,11 @@ impl TryFrom<&ConnectorAuthType> for ImerchantsolutionsAuthType {match auth_type {ConnectorAuthType::HeaderKey { api_key } => Ok(Self {api_key: api_key.to_owned(),+ merchant_id: None,+ }),+ ConnectorAuthType::BodyKey { api_key, key1 } => Ok(Self {+ api_key: api_key.to_owned(),+ merchant_id: Some(key1.to_owned()),}),_ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),}@@ -225,3 +231,55 @@ pub struct ImerchantsolutionsErrorResponse {pub network_decline_code: Option<String>,pub network_error_message: Option<String>,}++#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "camelCase")]+pub struct ImerchantsolutionsWebhookData {+ #[serde(rename = "type")]+ pub event_type: ImerchantsolutionsWebhookEventType,+ pub payment_id: String,+ pub psp_reference: String,+ pub original_reference: Option<String>,+ pub reference: Option<String>,+ pub merchant_reference: Option<String>,+ pub status: ImerchantsolutionsWebhookStatus,+ pub reason: Option<String>,+ pub error: Option<String>,+ pub amount: Option<MinorUnit>,+ pub captured_amount: Option<MinorUnit>,+ pub total_captured: Option<MinorUnit>,+ refunded_amount: Option<MinorUnit>,+ total_refunded: Option<MinorUnit>,+ currency: enums::Currency,+ processor: Option<String>,+ card_last4: Option<String>,+ card_brand: Option<String>,+ customer_email: Option<pii::Email>,+ partner_id: Option<Secret<String>>,+ merchant_id: Option<String>,+}++#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+pub enum ImerchantsolutionsWebhookEventType {+ #[serde(rename = "payment.completed")]+ PaymentCompleted,+ #[serde(rename = "payment.cancelled")]+ PaymentCancelled,+ #[serde(rename = "payment.failed")]+ PaymentFailed,+ #[serde(rename = "payment.refunded")]+ PaymentRefunded,+}++#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "snake_case")]+pub enum ImerchantsolutionsWebhookStatus {+ Authorized,+ PartiallyCaptured,+ Captured,+ PartiallyRefunded,+ Refunded,+ Cancelled,+ Failed,+ Refused,+}diff --git a/crates/hyperswitch_connectors/src/constants.rs b/crates/hyperswitch_connectors/src/constants.rsindex 72d154737b..7243f26f18 100644--- a/crates/hyperswitch_connectors/src/constants.rs+++ b/crates/hyperswitch_connectors/src/constants.rs@@ -37,6 +37,7 @@ pub(crate) mod headers {pub(crate) const SOAP_ACTION: &str = "SOAPAction";pub(crate) const X_PROFILE_ID: &str = "X-Profile-Id";pub(crate) const X_APPLICATION_KEY: &str = "X-Application-Key";+ pub(crate) const X_MERCHANT_ID: &str = "X-Merchant-Id";}/// Unsupported response type error messagediff --git a/crates/router/src/core/unified_connector_service/connector_config.rs b/crates/router/src/core/unified_connector_service/connector_config.rsindex 177c644d46..14acaae2c1 100644--- a/crates/router/src/core/unified_connector_service/connector_config.rs+++ b/crates/router/src/core/unified_connector_service/connector_config.rs@@ -517,7 +517,10 @@ pub enum ConnectorSpecificConfig {private_key: Option<Secret<String>>,},/// Imerchantsolutions connector configuration- Imerchantsolutions { api_key: Secret<String> },+ Imerchantsolutions {+ api_key: Secret<String>,+ merchant_id: Option<Secret<String>>,+ },/// Sanlam connector configurationSanlam {api_key: Secret<String>,@@ -1421,6 +1424,11 @@ impl ForeignTryFrom<(Connector, &ConnectorAuthType, Option<&serde_json::Value>)>Connector::Imerchantsolutions => match auth {ConnectorAuthType::HeaderKey { api_key } => Ok(Self::Imerchantsolutions {api_key: api_key.clone(),+ merchant_id: None,+ }),+ ConnectorAuthType::BodyKey { api_key, key1 } => Ok(Self::Imerchantsolutions {+ api_key: api_key.clone(),+ merchant_id: Some(key1.clone()),}),_ => Err(err("Imerchantsolutions requires HeaderKey auth type")),},