Skip to content

Commit

Permalink
Add negativeBalanceWarningWebhook to bankingWebhookHandler (#1459)
Browse files Browse the repository at this point in the history
* added negativeBalanceWarningWebhooks to index.ts and bankingWebhookHandler

* added negativebalancewebhooktest and adjusted the index.ts
  • Loading branch information
DjoykeAbyah authored Feb 3, 2025
1 parent 06f62a6 commit 7c84709
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/__tests__/notification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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());
});
});
12 changes: 11 additions & 1 deletion src/notification/bankingWebhookHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@ class BankingWebhookHandler {
| configurationWebhooks.PaymentNotificationRequest
| configurationWebhooks.SweepConfigurationNotificationRequest
| configurationWebhooks.CardOrderNotificationRequest
| negativeBalanceWarningWebhooks.NegativeBalanceCompensationWarningNotificationRequest
| reportWebhooks.ReportNotificationRequest
| transferWebhooks.TransferNotificationRequest
| transactionWebhooks.TransactionNotificationRequestV4 {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
export * as transactionWebhooks from './transactionWebhooks/models';
export * as negativeBalanceWarningWebhooks from './negativeBalanceWarningWebhooks/models';

0 comments on commit 7c84709

Please sign in to comment.