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): [noon] Create psync struct from webhook resource object (#2370)

SamraatBansalf12a43817787
diff --git a/crates/router/src/connector/noon.rs b/crates/router/src/connector/noon.rs
index 625f080d29..deda24bfbd 100644
--- a/crates/router/src/connector/noon.rs
+++ b/crates/router/src/connector/noon.rs
@@ -705,9 +705,15 @@ impl api::IncomingWebhook for Noon {
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
- let reference_object: serde_json::Value = serde_json::from_slice(request.body)
- .into_report()
+ let resource: noon::NoonWebhookObject = request
+ .body
+ .parse_struct("NoonWebhookObject")
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
- Ok(reference_object)
+
+ let res_json = serde_json::to_value(noon::NoonPaymentsResponse::from(resource))
+ .into_report()
+ .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
+
+ Ok(res_json)
}
}
diff --git a/crates/router/src/connector/noon/transformers.rs b/crates/router/src/connector/noon/transformers.rs
index a27ae6d9b7..eff6261891 100644
--- a/crates/router/src/connector/noon/transformers.rs
+++ b/crates/router/src/connector/noon/transformers.rs
@@ -301,7 +301,7 @@ impl TryFrom<&types::ConnectorAuthType> for NoonAuthType {
}
}
}
-#[derive(Default, Debug, Deserialize, strum::Display)]
+#[derive(Default, Debug, Deserialize, Serialize, strum::Display)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "UPPERCASE")]
pub enum NoonPaymentStatus {
@@ -335,12 +335,12 @@ impl From<NoonPaymentStatus> for enums::AttemptStatus {
}
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
pub struct NoonSubscriptionResponse {
identifier: String,
}
-#[derive(Default, Debug, Deserialize)]
+#[derive(Default, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NoonPaymentsOrderResponse {
status: NoonPaymentStatus,
@@ -349,13 +349,13 @@ pub struct NoonPaymentsOrderResponse {
error_message: Option<String>,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NoonCheckoutData {
post_url: url::Url,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NoonPaymentsResponseResult {
order: NoonPaymentsOrderResponse,
@@ -363,7 +363,7 @@ pub struct NoonPaymentsResponseResult {
subscription: Option<NoonSubscriptionResponse>,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
pub struct NoonPaymentsResponse {
result: NoonPaymentsResponseResult,
}
@@ -633,6 +633,32 @@ pub struct NoonWebhookEvent {
pub event_type: NoonWebhookEventTypes,
}
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct NoonWebhookObject {
+ pub order_status: NoonPaymentStatus,
+ pub order_id: u64,
+}
+
+/// This from will ensure that webhook body would be properly parsed into PSync response
+impl From<NoonWebhookObject> for NoonPaymentsResponse {
+ fn from(value: NoonWebhookObject) -> Self {
+ Self {
+ result: NoonPaymentsResponseResult {
+ order: NoonPaymentsOrderResponse {
+ status: value.order_status,
+ id: value.order_id,
+ //For successful payments Noon Always populates error_code as 0.
+ error_code: 0,
+ error_message: None,
+ },
+ checkout_data: None,
+ subscription: None,
+ },
+ }
+ }
+}
+
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NoonErrorResponse {