Skip to content

Commit 7c84709

Browse files
authored
Add negativeBalanceWarningWebhook to bankingWebhookHandler (#1459)
* added negativeBalanceWarningWebhooks to index.ts and bankingWebhookHandler * added negativebalancewebhooktest and adjusted the index.ts
1 parent 06f62a6 commit 7c84709

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/__tests__/notification.spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {TransferNotificationRequest} from "../typings/transferWebhooks/transferN
2020
import { PaymentMethodRequestRemovedNotificationRequest } from "../typings/managementWebhooks/paymentMethodRequestRemovedNotificationRequest";
2121
import { PaymentMethodScheduledForRemovalNotificationRequest } from "../typings/managementWebhooks/paymentMethodScheduledForRemovalNotificationRequest";
2222
import { TransactionNotificationRequestV4 } from "../typings/transactionWebhooks/transactionNotificationRequestV4";
23+
import { NegativeBalanceCompensationWarningNotificationRequest } from "../typings/negativeBalanceWarningWebhooks/negativeBalanceCompensationWarningNotificationRequest";
2324

2425
describe("Notification Test", function (): void {
2526

@@ -272,4 +273,42 @@ describe("Notification Test", function (): void {
272273
expect(genericWebhook instanceof PaymentMethodScheduledForRemovalNotificationRequest).toBe(false);
273274
expect(transactionCreated.type).toEqual(TransactionNotificationRequestV4.TypeEnum.BalancePlatformTransactionCreated);
274275
});
276+
277+
it("should deserialize NegativeBalanceCompensationWarning Webhook", function (): void {
278+
const json = {
279+
"data": {
280+
"balancePlatform": "YOUR_BALANCE_PLATFORM",
281+
"creationDate": "2024-07-02T02:01:08+02:00",
282+
"id": "BA00000000000000000001",
283+
"accountHolder": {
284+
"description": "Description for the account holder.",
285+
"reference": "YOUR_REFERENCE",
286+
"id": "AH00000000000000000001"
287+
},
288+
"amount": {
289+
"currency": "EUR",
290+
"value": -145050
291+
},
292+
"liableBalanceAccountId": "BA11111111111111111111",
293+
"negativeBalanceSince": "2024-10-19T00:33:13+02:00",
294+
"scheduledCompensationAt": "2024-12-01T01:00:00+01:00"
295+
},
296+
"environment": "test",
297+
"timestamp": "2024-10-22T00:00:00+02:00",
298+
"type": "balancePlatform.negativeBalanceCompensationWarning.scheduled"
299+
};
300+
const jsonString = JSON.stringify(json);
301+
const bankingWebhookHandler = new BankingWebhookHandler(jsonString);
302+
const negativeBalanceCompensationWarningNotificationRequest = bankingWebhookHandler.getNegativeBalanceCompensationWarningNotificationRequest();
303+
expect(negativeBalanceCompensationWarningNotificationRequest).toBeTruthy();
304+
expect(negativeBalanceCompensationWarningNotificationRequest.type).toBe(NegativeBalanceCompensationWarningNotificationRequest
305+
.TypeEnum.BalancePlatformNegativeBalanceCompensationWarningScheduled
306+
);
307+
expect(negativeBalanceCompensationWarningNotificationRequest.environment).toBe("test");
308+
expect(negativeBalanceCompensationWarningNotificationRequest.timestamp?.toISOString()).toBe(new Date("2024-10-22T00:00:00+02:00").toISOString());
309+
expect(negativeBalanceCompensationWarningNotificationRequest.data).toBeDefined();
310+
expect(negativeBalanceCompensationWarningNotificationRequest.data.balancePlatform).toBe("YOUR_BALANCE_PLATFORM");
311+
expect(negativeBalanceCompensationWarningNotificationRequest.data.id).toBe("BA00000000000000000001");
312+
expect(negativeBalanceCompensationWarningNotificationRequest.data.creationDate?.toISOString()).toBe(new Date("2024-07-02T02:01:08+02:00").toISOString());
313+
});
275314
});

src/notification/bankingWebhookHandler.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* This file is open source and available under the MIT license.
55
* See the LICENSE file for more info.
66
*/
7-
import {configurationWebhooks, acsWebhooks, reportWebhooks, transferWebhooks, transactionWebhooks} from "../typings";
7+
8+
import {configurationWebhooks, acsWebhooks, reportWebhooks, transferWebhooks, transactionWebhooks, negativeBalanceWarningWebhooks} from "../typings";
89

910
class BankingWebhookHandler {
1011
private readonly payload: string;
@@ -20,6 +21,7 @@ class BankingWebhookHandler {
2021
| configurationWebhooks.PaymentNotificationRequest
2122
| configurationWebhooks.SweepConfigurationNotificationRequest
2223
| configurationWebhooks.CardOrderNotificationRequest
24+
| negativeBalanceWarningWebhooks.NegativeBalanceCompensationWarningNotificationRequest
2325
| reportWebhooks.ReportNotificationRequest
2426
| transferWebhooks.TransferNotificationRequest
2527
| transactionWebhooks.TransactionNotificationRequestV4 {
@@ -49,6 +51,10 @@ class BankingWebhookHandler {
4951
return this.getSweepConfigurationNotificationRequest();
5052
}
5153

54+
if(Object.values(negativeBalanceWarningWebhooks.NegativeBalanceCompensationWarningNotificationRequest.TypeEnum).includes(type)){
55+
return this.getNegativeBalanceCompensationWarningNotificationRequest();
56+
}
57+
5258
if(Object.values(reportWebhooks.ReportNotificationRequest.TypeEnum).includes(type)){
5359
return this.getReportNotificationRequest();
5460
}
@@ -87,6 +93,10 @@ class BankingWebhookHandler {
8793
public getSweepConfigurationNotificationRequest(): configurationWebhooks.SweepConfigurationNotificationRequest {
8894
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "SweepConfigurationNotificationRequest");
8995
}
96+
97+
public getNegativeBalanceCompensationWarningNotificationRequest(): negativeBalanceWarningWebhooks.NegativeBalanceCompensationWarningNotificationRequest {
98+
return negativeBalanceWarningWebhooks.ObjectSerializer.deserialize(this.payload, "NegativeBalanceCompensationWarningNotificationRequest");
99+
}
90100

91101
public getReportNotificationRequest(): reportWebhooks.ReportNotificationRequest {
92102
return reportWebhooks.ObjectSerializer.deserialize(this.payload, "ReportNotificationRequest");

src/typings/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export * as reportWebhooks from './reportWebhooks/models';
3232
export * as transferWebhooks from './transferWebhooks/models';
3333
export * as managementWebhooks from './managementWebhooks/models';
3434
export * as acsWebhooks from './acsWebhooks/models';
35-
export * as transactionWebhooks from './transactionWebhooks/models';
35+
export * as transactionWebhooks from './transactionWebhooks/models';
36+
export * as negativeBalanceWarningWebhooks from './negativeBalanceWarningWebhooks/models';

0 commit comments

Comments
 (0)