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): [Authorizedotnet]Fix webhooks (#1261)

chikke srujan776c833de706
diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rs
index 83e9613883..c6bc558e9b 100644
--- a/crates/router/src/connector/authorizedotnet.rs
+++ b/crates/router/src/connector/authorizedotnet.rs
@@ -667,13 +667,13 @@ impl api::IncomingWebhook for Authorizedotnet {
authorizedotnet::AuthorizedotnetWebhookEvent::RefundCreated => {
Ok(api_models::webhooks::ObjectReferenceId::RefundId(
api_models::webhooks::RefundIdType::ConnectorRefundId(
- authorizedotnet::get_trans_id(details)?,
+ authorizedotnet::get_trans_id(&details)?,
),
))
}
_ => Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::ConnectorTransactionId(
- authorizedotnet::get_trans_id(details)?,
+ authorizedotnet::get_trans_id(&details)?,
),
)),
}
@@ -712,10 +712,16 @@ impl api::IncomingWebhook for Authorizedotnet {
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
- let payload = serde_json::to_value(request.body)
- .into_report()
+ let payload: authorizedotnet::AuthorizedotnetWebhookObjectId = request
+ .body
+ .parse_struct("AuthorizedotnetWebhookObjectId")
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
- Ok(payload)
+ let sync_payload = serde_json::to_value(
+ authorizedotnet::AuthorizedotnetSyncResponse::try_from(payload)?,
+ )
+ .into_report()
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)?;
+ Ok(sync_payload)
}
}
diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs
index 014d945b82..1ae9870723 100644
--- a/crates/router/src/connector/authorizedotnet/transformers.rs
+++ b/crates/router/src/connector/authorizedotnet/transformers.rs
@@ -343,19 +343,20 @@ impl From<AuthorizedotnetPaymentStatus> for enums::AttemptStatus {
}
}
-#[derive(Debug, Clone, Deserialize, PartialEq)]
+#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
pub struct ResponseMessage {
code: String,
pub text: String,
}
-#[derive(Debug, Clone, Deserialize, PartialEq)]
+#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
enum ResultCode {
+ #[default]
Ok,
Error,
}
-#[derive(Debug, Clone, Deserialize, PartialEq)]
+#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ResponseMessages {
result_code: ResultCode,
@@ -723,7 +724,7 @@ impl TryFrom<&types::PaymentsSyncRouterData> for AuthorizedotnetCreateSyncReques
}
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum SyncStatus {
RefundSettledSuccessfully,
@@ -738,7 +739,7 @@ pub enum SyncStatus {
#[serde(rename = "FDSPendingReview")]
FDSPendingReview,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncTransactionResponse {
#[serde(rename = "transId")]
@@ -746,7 +747,7 @@ pub struct SyncTransactionResponse {
transaction_status: SyncStatus,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
pub struct AuthorizedotnetSyncResponse {
transaction: Option<SyncTransactionResponse>,
messages: ResponseMessages,
@@ -932,11 +933,41 @@ impl From<AuthorizedotnetWebhookEvent> for api::IncomingWebhookEvent {
}
}
+impl From<AuthorizedotnetWebhookEvent> for SyncStatus {
+ // status mapping reference https://developer.authorize.net/api/reference/features/webhooks.html#Event_Types_and_Payloads
+ fn from(event_type: AuthorizedotnetWebhookEvent) -> Self {
+ match event_type {
+ AuthorizedotnetWebhookEvent::AuthorizationCreated => Self::AuthorizedPendingCapture,
+ AuthorizedotnetWebhookEvent::CaptureCreated
+ | AuthorizedotnetWebhookEvent::AuthCapCreated => Self::CapturedPendingSettlement,
+ AuthorizedotnetWebhookEvent::PriorAuthCapture => Self::SettledSuccessfully,
+ AuthorizedotnetWebhookEvent::VoidCreated => Self::Voided,
+ AuthorizedotnetWebhookEvent::RefundCreated => Self::RefundSettledSuccessfully,
+ }
+ }
+}
+
pub fn get_trans_id(
- details: AuthorizedotnetWebhookObjectId,
+ details: &AuthorizedotnetWebhookObjectId,
) -> Result<String, errors::ConnectorError> {
details
.payload
.id
+ .clone()
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)
}
+
+impl TryFrom<AuthorizedotnetWebhookObjectId> for AuthorizedotnetSyncResponse {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(item: AuthorizedotnetWebhookObjectId) -> Result<Self, Self::Error> {
+ Ok(Self {
+ transaction: Some(SyncTransactionResponse {
+ transaction_id: get_trans_id(&item)?,
+ transaction_status: SyncStatus::from(item.event_type),
+ }),
+ messages: ResponseMessages {
+ ..Default::default()
+ },
+ })
+ }
+}