diff --git a/localenv/mock-account-servicing-entity/app/lib/webhooks.server.ts b/localenv/mock-account-servicing-entity/app/lib/webhooks.server.ts index 96f99ac5d5..04c3cde29d 100644 --- a/localenv/mock-account-servicing-entity/app/lib/webhooks.server.ts +++ b/localenv/mock-account-servicing-entity/app/lib/webhooks.server.ts @@ -12,6 +12,10 @@ import { import { Webhook, WebhookEventType } from 'mock-account-service-lib' import { TenantOptions } from './types' +function cannotHandleWebhook(tenantId: string) { + return process.env.OPERATOR_TENANT_ID && tenantId !== process.env.OPERATOR_TENANT_ID +} + export interface AmountJSON { value: string assetCode: string @@ -40,6 +44,10 @@ export async function handleOutgoingPaymentCompletedFailed(wh: Webhook) { throw new Error('Invalid event type when handling outgoing payment webhook') } const payment = wh.data + // Don't handle webhook if it is referring to a tenant. + if ( + cannotHandleWebhook(wh.tenantId) + ) return const wa = payment['walletAddressId'] as string const acc = await mockAccounts.getByWalletAddressId(wa) @@ -144,6 +152,7 @@ export async function handleIncomingPaymentCompletedExpired( throw new Error('Invalid event type when handling incoming payment webhook') } + if (cannotHandleWebhook(wh.tenantId)) return const payment = wh.data const wa = payment['walletAddressId'] as string const acc = await mockAccounts.getByWalletAddressId(wa) diff --git a/packages/backend/src/webhook/service.ts b/packages/backend/src/webhook/service.ts index b1a54c2c8d..1144889016 100644 --- a/packages/backend/src/webhook/service.ts +++ b/packages/backend/src/webhook/service.ts @@ -206,6 +206,7 @@ async function sendWebhook( const body = { id: webhook.event.id, type: webhook.event.type, + tenantId: webhook.event.tenantId, data: webhook.event.data } diff --git a/packages/mock-account-service-lib/src/types.ts b/packages/mock-account-service-lib/src/types.ts index a81b20f327..6b6a4f4ad9 100644 --- a/packages/mock-account-service-lib/src/types.ts +++ b/packages/mock-account-service-lib/src/types.ts @@ -75,6 +75,7 @@ export interface Config { } export interface Webhook { id: string + tenantId: string type: WebhookEventType data: Record }