diff --git a/src/__tests__/notification.spec.ts b/src/__tests__/notification.spec.ts index 11fbc585f..830000229 100644 --- a/src/__tests__/notification.spec.ts +++ b/src/__tests__/notification.spec.ts @@ -20,6 +20,7 @@ import {TransferNotificationRequest} from "../typings/transferWebhooks/transferN import { PaymentMethodRequestRemovedNotificationRequest } from "../typings/managementWebhooks/paymentMethodRequestRemovedNotificationRequest"; import { PaymentMethodScheduledForRemovalNotificationRequest } from "../typings/managementWebhooks/paymentMethodScheduledForRemovalNotificationRequest"; import { TransactionNotificationRequestV4 } from "../typings/transactionWebhooks/transactionNotificationRequestV4"; +import { NegativeBalanceCompensationWarningNotificationRequest } from "../typings/negativeBalanceWarningWebhooks/negativeBalanceCompensationWarningNotificationRequest"; describe("Notification Test", function (): void { @@ -272,4 +273,42 @@ describe("Notification Test", function (): void { expect(genericWebhook instanceof PaymentMethodScheduledForRemovalNotificationRequest).toBe(false); expect(transactionCreated.type).toEqual(TransactionNotificationRequestV4.TypeEnum.BalancePlatformTransactionCreated); }); + + it("should deserialize NegativeBalanceCompensationWarning Webhook", function (): void { + const json = { + "data": { + "balancePlatform": "YOUR_BALANCE_PLATFORM", + "creationDate": "2024-07-02T02:01:08+02:00", + "id": "BA00000000000000000001", + "accountHolder": { + "description": "Description for the account holder.", + "reference": "YOUR_REFERENCE", + "id": "AH00000000000000000001" + }, + "amount": { + "currency": "EUR", + "value": -145050 + }, + "liableBalanceAccountId": "BA11111111111111111111", + "negativeBalanceSince": "2024-10-19T00:33:13+02:00", + "scheduledCompensationAt": "2024-12-01T01:00:00+01:00" + }, + "environment": "test", + "timestamp": "2024-10-22T00:00:00+02:00", + "type": "balancePlatform.negativeBalanceCompensationWarning.scheduled" + }; + const jsonString = JSON.stringify(json); + const bankingWebhookHandler = new BankingWebhookHandler(jsonString); + const negativeBalanceCompensationWarningNotificationRequest = bankingWebhookHandler.getNegativeBalanceCompensationWarningNotificationRequest(); + expect(negativeBalanceCompensationWarningNotificationRequest).toBeTruthy(); + expect(negativeBalanceCompensationWarningNotificationRequest.type).toBe(NegativeBalanceCompensationWarningNotificationRequest + .TypeEnum.BalancePlatformNegativeBalanceCompensationWarningScheduled + ); + expect(negativeBalanceCompensationWarningNotificationRequest.environment).toBe("test"); + expect(negativeBalanceCompensationWarningNotificationRequest.timestamp?.toISOString()).toBe(new Date("2024-10-22T00:00:00+02:00").toISOString()); + expect(negativeBalanceCompensationWarningNotificationRequest.data).toBeDefined(); + expect(negativeBalanceCompensationWarningNotificationRequest.data.balancePlatform).toBe("YOUR_BALANCE_PLATFORM"); + expect(negativeBalanceCompensationWarningNotificationRequest.data.id).toBe("BA00000000000000000001"); + expect(negativeBalanceCompensationWarningNotificationRequest.data.creationDate?.toISOString()).toBe(new Date("2024-07-02T02:01:08+02:00").toISOString()); + }); }); \ No newline at end of file diff --git a/src/notification/bankingWebhookHandler.ts b/src/notification/bankingWebhookHandler.ts index c2a6c80a1..83d68a905 100644 --- a/src/notification/bankingWebhookHandler.ts +++ b/src/notification/bankingWebhookHandler.ts @@ -4,7 +4,8 @@ * This file is open source and available under the MIT license. * See the LICENSE file for more info. */ -import {configurationWebhooks, acsWebhooks, reportWebhooks, transferWebhooks, transactionWebhooks} from "../typings"; + +import {configurationWebhooks, acsWebhooks, reportWebhooks, transferWebhooks, transactionWebhooks, negativeBalanceWarningWebhooks} from "../typings"; class BankingWebhookHandler { private readonly payload: string; @@ -20,6 +21,7 @@ class BankingWebhookHandler { | configurationWebhooks.PaymentNotificationRequest | configurationWebhooks.SweepConfigurationNotificationRequest | configurationWebhooks.CardOrderNotificationRequest + | negativeBalanceWarningWebhooks.NegativeBalanceCompensationWarningNotificationRequest | reportWebhooks.ReportNotificationRequest | transferWebhooks.TransferNotificationRequest | transactionWebhooks.TransactionNotificationRequestV4 { @@ -49,6 +51,10 @@ class BankingWebhookHandler { return this.getSweepConfigurationNotificationRequest(); } + if(Object.values(negativeBalanceWarningWebhooks.NegativeBalanceCompensationWarningNotificationRequest.TypeEnum).includes(type)){ + return this.getNegativeBalanceCompensationWarningNotificationRequest(); + } + if(Object.values(reportWebhooks.ReportNotificationRequest.TypeEnum).includes(type)){ return this.getReportNotificationRequest(); } @@ -87,6 +93,10 @@ class BankingWebhookHandler { public getSweepConfigurationNotificationRequest(): configurationWebhooks.SweepConfigurationNotificationRequest { return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "SweepConfigurationNotificationRequest"); } + + public getNegativeBalanceCompensationWarningNotificationRequest(): negativeBalanceWarningWebhooks.NegativeBalanceCompensationWarningNotificationRequest { + return negativeBalanceWarningWebhooks.ObjectSerializer.deserialize(this.payload, "NegativeBalanceCompensationWarningNotificationRequest"); + } public getReportNotificationRequest(): reportWebhooks.ReportNotificationRequest { return reportWebhooks.ObjectSerializer.deserialize(this.payload, "ReportNotificationRequest"); diff --git a/src/typings/index.ts b/src/typings/index.ts index 0959b740f..f81d1b98d 100644 --- a/src/typings/index.ts +++ b/src/typings/index.ts @@ -32,4 +32,5 @@ export * as reportWebhooks from './reportWebhooks/models'; export * as transferWebhooks from './transferWebhooks/models'; export * as managementWebhooks from './managementWebhooks/models'; export * as acsWebhooks from './acsWebhooks/models'; -export * as transactionWebhooks from './transactionWebhooks/models'; \ No newline at end of file +export * as transactionWebhooks from './transactionWebhooks/models'; +export * as negativeBalanceWarningWebhooks from './negativeBalanceWarningWebhooks/models'; \ No newline at end of file