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

feat(router): add an endpoint to list configured connector webhooks (#10825)

Akshaya Shankar590f3c5ea2cb
diff --git a/api-reference/v1/merchant-connector-account/merchant-connector-webhook--list.mdx b/api-reference/v1/merchant-connector-account/merchant-connector-webhook--list.mdx
new file mode 100644
index 0000000000..ea159810fb
--- /dev/null
+++ b/api-reference/v1/merchant-connector-account/merchant-connector-webhook--list.mdx
@@ -0,0 +1,3 @@
+---
+openapi: get /account/{account_id}/webhooks/{merchant_connector_id}
+---
\ No newline at end of file
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 08dd8779b1..44a0b05e90 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -2799,7 +2799,7 @@
]
}
},
- "/account/{account_id}/connectors/webhooks/{merchant_connector_id}": {
+ "/account/{account_id}/webhooks/{merchant_connector_id}": {
"post": {
"tags": [
"Merchant Connector Account"
@@ -15413,6 +15413,25 @@
}
]
},
+ "ConnectorWebhookListResponse": {
+ "type": "object",
+ "required": [
+ "connector",
+ "webhooks"
+ ],
+ "properties": {
+ "connector": {
+ "type": "string"
+ },
+ "webhooks": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/ConnectorWebhookResponse"
+ }
+ }
+ },
+ "additionalProperties": false
+ },
"ConnectorWebhookRegisterRequest": {
"type": "object",
"description": "Register a webhook at the connector",
@@ -15428,6 +15447,26 @@
},
"additionalProperties": false
},
+ "ConnectorWebhookResponse": {
+ "type": "object",
+ "required": [
+ "connector_webhook_id"
+ ],
+ "properties": {
+ "event_type": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/ConnectorWebhookEventType"
+ }
+ ],
+ "nullable": true
+ },
+ "connector_webhook_id": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ },
"ContractBasedRoutingConfig": {
"type": "object",
"properties": {
diff --git a/crates/api_models/src/events.rs b/crates/api_models/src/events.rs
index ebf0c0de9b..4c3f5633a5 100644
--- a/crates/api_models/src/events.rs
+++ b/crates/api_models/src/events.rs
@@ -79,6 +79,7 @@ impl_api_event_type!(
ConvertOrganizationToPlatformRequest,
ConvertOrganizationToPlatformResponse,
ConnectorWebhookRegisterRequest,
+ ConnectorWebhookListResponse,
MerchantConnectorResponse,
MerchantConnectorId,
MandateResponse,
diff --git a/crates/api_models/src/merchant_connector_webhook_management.rs b/crates/api_models/src/merchant_connector_webhook_management.rs
index bbe01da93d..b41555df1c 100644
--- a/crates/api_models/src/merchant_connector_webhook_management.rs
+++ b/crates/api_models/src/merchant_connector_webhook_management.rs
@@ -20,3 +20,18 @@ pub struct RegisterConnectorWebhookResponse {
pub error_code: Option<String>,
pub error_message: Option<String>,
}
+
+#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
+#[serde(deny_unknown_fields)]
+pub struct ConnectorWebhookListResponse {
+ pub connector: String,
+ pub webhooks: Vec<ConnectorWebhookResponse>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
+#[serde(deny_unknown_fields)]
+pub struct ConnectorWebhookResponse {
+ #[schema(value_type = Option<ConnectorWebhookEventType>)]
+ pub event_type: common_enums::ConnectorWebhookEventType,
+ pub connector_webhook_id: String,
+}
diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs
index ce3a0cfbd7..5a5591d289 100644
--- a/crates/diesel_models/src/merchant_connector_account.rs
+++ b/crates/diesel_models/src/merchant_connector_account.rs
@@ -106,6 +106,7 @@ pub struct MerchantConnectorAccount {
pub version: common_enums::ApiVersion,
pub id: id_type::MerchantConnectorAccountId,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
+ #[serde(default)]
pub connector_webhook_registration_details: Option<serde_json::Value>,
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index d3b40f7647..a2c09ebb14 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -350,6 +350,8 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::admin::CardTestingGuardStatus,
api_models::merchant_connector_webhook_management::ConnectorWebhookRegisterRequest,
api_models::merchant_connector_webhook_management::RegisterConnectorWebhookResponse,
+ api_models::merchant_connector_webhook_management::ConnectorWebhookResponse,
+ api_models::merchant_connector_webhook_management::ConnectorWebhookListResponse,
api_models::customers::CustomerRequest,
api_models::customers::CustomerUpdateRequest,
api_models::customers::CustomerDeleteResponse,
diff --git a/crates/openapi/src/routes/merchant_connector_account.rs b/crates/openapi/src/routes/merchant_connector_account.rs
index 48250e2eb5..5c51fab174 100644
--- a/crates/openapi/src/routes/merchant_connector_account.rs
+++ b/crates/openapi/src/routes/merchant_connector_account.rs
@@ -334,7 +334,7 @@ pub async fn connector_delete() {}
#[cfg(feature = "v1")]
#[utoipa::path(
post,
- path = "/account/{account_id}/connectors/webhooks/{merchant_connector_id}",
+ path = "/account/{account_id}/webhooks/{merchant_connector_id}",
request_body(
content = ConnectorWebhookRegisterRequest,
examples(
@@ -369,3 +369,24 @@ pub async fn connector_delete() {}
security(("api_key" = []))
)]
pub async fn connector_webhook_register() {}
+
+/// Configure Connector Webhook - Register
+///
+/// List webhooks configured with hyperswitch at the connector
+#[cfg(feature = "v1")]
+#[utoipa::path(
+ get,
+ path = "/account/{account_id}/webhooks/{merchant_connector_id}",
+ params(
+ ("account_id" = String, Path, description = "The unique identifier for the merchant account"),
+ ("merchant_connector_id" = String, Path, description = "The unique identifier for the Merchant Connector")
+ ),
+ responses(
+ (status = 200, description = "List of webhooks configured with hyperswitch at the connector", body = ConnectorWebhookListResponse),
+ (status = 401, description = "Unauthorized request")
+ ),
+ tag = "Merchant Connector Account",
+ operation_id = "List Connector Webhooks",
+ security(("api_key" = []))
+)]
+pub async fn retrieve_connector_webhook() {}
diff --git a/crates/router/src/core/merchant_connector_webhook_management.rs b/crates/router/src/core/merchant_connector_webhook_management.rs
index c759dd4fd7..b66c1116f0 100644
--- a/crates/router/src/core/merchant_connector_webhook_management.rs
+++ b/crates/router/src/core/merchant_connector_webhook_management.rs
@@ -1,5 +1,4 @@
mod transformers;
-use api_models::merchant_connector_webhook_management;
use common_utils::id_type;
use error_stack::ResultExt;
use hyperswitch_domain_models::{
@@ -29,8 +28,10 @@ pub async fn register_connector_webhook(
merchant_id: &id_type::MerchantId,
profile_id: Option<id_type::ProfileId>,
merchant_connector_id: &id_type::MerchantConnectorAccountId,
- req: merchant_connector_webhook_management::ConnectorWebhookRegisterRequest,
-) -> RouterResponse<merchant_connector_webhook_management::RegisterConnectorWebhookResponse> {
+ req: api_models::merchant_connector_webhook_management::ConnectorWebhookRegisterRequest,
+) -> RouterResponse<
+ api_models::merchant_connector_webhook_management::RegisterConnectorWebhookResponse,
+> {
let db = state.store.as_ref();
let key_store = db
.get_merchant_key_store_by_merchant_id(merchant_id, &db.get_master_key().to_vec().into())
@@ -134,3 +135,46 @@ pub async fn register_connector_webhook(
Ok(service_api::ApplicationResponse::Json(response))
}
+
+#[cfg(feature = "v1")]
+pub async fn fetch_connector_webhook(
+ state: SessionState,
+ merchant_id: id_type::MerchantId,
+ profile_id: Option<id_type::ProfileId>,
+ merchant_connector_id: id_type::MerchantConnectorAccountId,
+) -> RouterResponse<api_models::merchant_connector_webhook_management::ConnectorWebhookListResponse>
+{
+ let store = state.store.as_ref();
+ let key_store = store
+ .get_merchant_key_store_by_merchant_id(
+ &merchant_id,
+ &store.get_master_key().to_vec().into(),
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+
+ let mca = store
+ .find_by_merchant_connector_account_merchant_id_merchant_connector_id(
+ &merchant_id,
+ &merchant_connector_id,
+ &key_store,
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: merchant_connector_id.get_string_repr().to_string(),
+ })?;
+
+ let connector_webook_data =
+ configure_connector_webhook_flow::get_connector_webhook_list_response(
+ &mca.connector_webhook_registration_details,
+ )?;
+
+ core_utils::validate_profile_id_from_auth_layer(profile_id, &mca)?;
+
+ Ok(service_api::ApplicationResponse::Json(
+ api_models::merchant_connector_webhook_management::ConnectorWebhookListResponse {
+ connector: mca.connector_name.clone(),
+ webhooks: connector_webook_data,
+ },
+ ))
+}
diff --git a/crates/router/src/core/merchant_connector_webhook_management/transformers.rs b/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
index dad5c30cbf..039a6a56fb 100644
--- a/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
+++ b/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
@@ -212,3 +212,29 @@ pub fn construct_connector_webhook_registration_response(
error_message: register_webhook_response.error_message.clone(),
})
}
+#[cfg(feature = "v1")]
+pub fn get_connector_webhook_list_response(
+ register_webhook_response: &Option<serde_json::Value>,
+) -> RouterResult<Vec<api_models::merchant_connector_webhook_management::ConnectorWebhookResponse>>
+{
+ use std::collections::HashMap;
+
+ let webhook_map: HashMap<String, domain::ConnectorWebhookData> = match register_webhook_response
+ {
+ Some(webhook_response) => serde_json::from_value(webhook_response.clone())
+ .change_context(errors::ApiErrorResponse::InternalServerError)?,
+ None => HashMap::new(),
+ };
+
+ let webhooks = webhook_map
+ .into_iter()
+ .map(|(connector_webhook_id, webhook_data)| {
+ api_models::merchant_connector_webhook_management::ConnectorWebhookResponse {
+ event_type: webhook_data.event_type,
+ connector_webhook_id,
+ }
+ })
+ .collect();
+
+ Ok(webhooks)
+}
diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rs
index 26b56b2dbd..74a23e0556 100644
--- a/crates/router/src/routes/admin.rs
+++ b/crates/router/src/routes/admin.rs
@@ -1162,3 +1162,53 @@ pub async fn connector_webhook_register(
))
.await
}
+
+/// Configure Connector Webhook - Register
+///
+/// List webhooks configured with hyperswitch at the connector
+#[cfg(feature = "v1")]
+#[
+ instrument(skip_all, fields(flow = ?Flow::MerchantConnectorWebhookList))]
+pub async fn retrieve_connector_webhook(
+ state: web::Data<AppState>,
+ req: HttpRequest,
+ path: web::Path<(
+ common_utils::id_type::MerchantId,
+ common_utils::id_type::MerchantConnectorAccountId,
+ )>,
+) -> HttpResponse {
+ let flow = Flow::MerchantConnectorWebhookList;
+ let (merchant_id, merchant_connector_id) = path.into_inner();
+ let payload = web::Json(admin::MerchantConnectorId {
+ merchant_id: merchant_id.clone(),
+ merchant_connector_id,
+ })
+ .into_inner();
+
+ Box::pin(api::server_wrap(
+ flow,
+ state,
+ &req,
+ payload,
+ |state, auth, req, _| {
+ fetch_connector_webhook(
+ state,
+ req.merchant_id.clone(),
+ auth.profile.map(|profile| profile.get_id().clone()),
+ req.merchant_connector_id,
+ )
+ },
+ auth::auth_type(
+ &auth::ApiKeyAuthWithMerchantIdFromRoute(merchant_id.clone()),
+ &auth::JWTAuthMerchantFromRoute {
+ merchant_id,
+ required_permission: Permission::ProfileAccountRead,
+ allow_connected: true,
+ allow_platform: true,
+ },
+ req.headers(),
+ ),
+ api_locking::LockAction::NotApplicable,
+ ))
+ .await
+}
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index f501c4258c..aa5522fd1e 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -2031,7 +2031,8 @@ impl MerchantConnectorAccount {
)
.service(
web::resource("/{merchant_id}/connectors/webhooks/{merchant_connector_id}")
- .route(web::post().to(connector_webhook_register)),
+ .route(web::post().to(connector_webhook_register))
+ .route(web::get().to(retrieve_connector_webhook)),
);
}
#[cfg(feature = "oltp")]
diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rs
index be16f29b77..1b28b1f8b6 100644
--- a/crates/router/src/routes/lock_utils.rs
+++ b/crates/router/src/routes/lock_utils.rs
@@ -383,7 +383,9 @@ impl From<Flow> for ApiIdentifier {
| Flow::NetworkTokenEligibilityCheck => Self::GenericTokenization,
Flow::RecoveryDataBackfill | Flow::RevenueRecoveryRedis => Self::RecoveryRecovery,
- Flow::MerchantConnectorWebhookRegister => Self::MerchantConnectorWebhookManagement,
+ Flow::MerchantConnectorWebhookRegister | Flow::MerchantConnectorWebhookList => {
+ Self::MerchantConnectorWebhookManagement
+ }
}
}
}
diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rs
index 8492e98ad8..d4bc1c53dc 100644
--- a/crates/router_env/src/logger/types.rs
+++ b/crates/router_env/src/logger/types.rs
@@ -94,6 +94,8 @@ pub enum Flow {
MerchantTransferKey,
/// Merchant Connector Webhook register flow.
MerchantConnectorWebhookRegister,
+ /// Merchant Connector Webhook list flow.
+ MerchantConnectorWebhookList,
/// ConfigKey create flow.
ConfigKeyCreate,
/// ConfigKey fetch flow.