@@ -3,26 +3,26 @@ import captureTrue from "../__mocks__/notification/captureTrue.json";
3
3
import captureFalse from "../__mocks__/notification/captureFalse.json" ;
4
4
import refundTrue from "../__mocks__/notification/refundTrue.json" ;
5
5
import refundFalse from "../__mocks__/notification/refundFalse.json" ;
6
- import NotificationRequest from "../notification/notificationRequest" ;
7
- import { Notification , NotificationRequestItem } from "../typings/notification/models" ;
6
+
8
7
import NotificationEnum = NotificationRequestItem . EventCodeEnum ;
9
8
import SuccessEnum = NotificationRequestItem . SuccessEnum ;
10
- import BankingWebhookHandler from "../notification/bankingWebhookHandler" ;
11
- import { AccountHolderNotificationRequest } from "../typings/configurationWebhooks/accountHolderNotificationRequest" ;
12
- import { BalanceAccountNotificationRequest } from "../typings/configurationWebhooks/balanceAccountNotificationRequest" ;
13
- import HmacValidator from "../utils/hmacValidator" ;
14
- import ManagementWebhookHandler from "../notification/managementWebhookHandler" ;
15
- import {
16
- PaymentMethodCreatedNotificationRequest
17
- } from "../typings/managementWebhooks/paymentMethodCreatedNotificationRequest" ;
18
- import { MerchantUpdatedNotificationRequest } from "../typings/managementWebhooks/merchantUpdatedNotificationRequest" ;
19
- import { AuthenticationNotificationRequest } from "../typings/acsWebhooks/authenticationNotificationRequest" ;
20
- import { TransferNotificationRequest } from "../typings/transferWebhooks/transferNotificationRequest" ;
9
+
10
+ // requests
11
+ import NotificationRequest from "../notification/notificationRequest" ;
12
+ import { Notification , NotificationRequestItem } from "../typings/notification/models" ;
13
+ import { AccountHolderNotificationRequest } from "../typings/configurationWebhooks/accountHolderNotificationRequest" ;
14
+ import { BalanceAccountNotificationRequest } from "../typings/configurationWebhooks/balanceAccountNotificationRequest" ;
15
+ import { PaymentMethodCreatedNotificationRequest } from "../typings/managementWebhooks/paymentMethodCreatedNotificationRequest" ;
16
+ import { MerchantUpdatedNotificationRequest } from "../typings/managementWebhooks/merchantUpdatedNotificationRequest" ;
17
+ import { AuthenticationNotificationRequest } from "../typings/acsWebhooks/authenticationNotificationRequest" ;
18
+ import { TransferNotificationRequest } from "../typings/transferWebhooks/transferNotificationRequest" ;
21
19
import { PaymentMethodRequestRemovedNotificationRequest } from "../typings/managementWebhooks/paymentMethodRequestRemovedNotificationRequest" ;
22
20
import { PaymentMethodScheduledForRemovalNotificationRequest } from "../typings/managementWebhooks/paymentMethodScheduledForRemovalNotificationRequest" ;
23
21
import { TransactionNotificationRequestV4 } from "../typings/transactionWebhooks/transactionNotificationRequestV4" ;
24
22
import { NegativeBalanceCompensationWarningNotificationRequest } from "../typings/negativeBalanceWarningWebhooks/negativeBalanceCompensationWarningNotificationRequest" ;
25
23
import { BalanceAccountBalanceNotificationRequest } from "../typings/balanceWebhooks/balanceAccountBalanceNotificationRequest" ;
24
+
25
+ // handlers
26
26
import { AcsWebhooksHandler } from "../typings/acsWebhooks/acsWebhooksHandler" ;
27
27
import { ReportWebhooksHandler } from "../typings/reportWebhooks/reportWebhooksHandler" ;
28
28
import { ConfigurationWebhooksHandler } from "../typings/configurationWebhooks/configurationWebhooksHandler" ;
@@ -31,6 +31,9 @@ import { NegativeBalanceWarningWebhooksHandler } from "../typings/negativeBalanc
31
31
import { TransactionWebhooksHandler } from "../typings/transactionWebhooks/transactionWebhooksHandler" ;
32
32
import { BalanceWebhooksHandler } from "../typings/balanceWebhooks/balanceWebhooksHandler" ;
33
33
import { ReportNotificationRequest } from "../typings/reportWebhooks/reportNotificationRequest" ;
34
+ import { ManagementWebhooksHandler } from "../typings/managementWebhooks/managementWebhooksHandler" ;
35
+
36
+ import HmacValidator from "../utils/hmacValidator" ;
34
37
35
38
describe ( "Notification Test" , function ( ) : void {
36
39
@@ -230,65 +233,14 @@ describe("Notification Test", function (): void {
230
233
"type" : "paymentMethod.created"
231
234
} ;
232
235
const jsonString = JSON . stringify ( json ) ;
233
- const managementWebhookHandler = new ManagementWebhookHandler ( jsonString ) ;
234
- const paymentMethodCreatedNotificationRequest : PaymentMethodCreatedNotificationRequest = managementWebhookHandler . getPaymentMethodCreatedNotificationRequest ( ) ;
235
- const genericWebhook = managementWebhookHandler . getGenericWebhook ( ) ;
236
+ const managementWebhooksHandler = new ManagementWebhooksHandler ( jsonString ) ;
237
+ const paymentMethodCreatedNotificationRequest : PaymentMethodCreatedNotificationRequest = managementWebhooksHandler . getPaymentMethodCreatedNotificationRequest ( ) ;
238
+ const genericWebhook = managementWebhooksHandler . getGenericWebhook ( ) ;
236
239
expect ( genericWebhook instanceof PaymentMethodCreatedNotificationRequest ) . toBe ( true ) ;
237
240
expect ( genericWebhook instanceof MerchantUpdatedNotificationRequest ) . toBe ( false ) ;
238
241
expect ( paymentMethodCreatedNotificationRequest . type ) . toEqual ( PaymentMethodCreatedNotificationRequest . TypeEnum . PaymentMethodCreated ) ;
239
242
} ) ;
240
243
241
- it ( "should deserialize Banking Authentication Webhook" , function ( ) : void {
242
- const json = {
243
- "data" : {
244
- "balancePlatform" : "YOUR_BALANCE_PLATFORM" ,
245
- "creationDate" : "2023-01-19T17:07:59+01:00" ,
246
- "id" : "a8fc7a40-6e48-498a-bdc2-494daf0f490a" ,
247
- "authentication" : {
248
- "acsTransId" : "a8fc7a40-6e48-498a-bdc2-494daf0f490a" ,
249
- "challenge" : {
250
- "flow" : "OTP_SMS" ,
251
- "lastInteraction" : "2023-01-19T17:37:13+01:00" ,
252
- "phoneNumber" : "******6789" ,
253
- "resends" : 0 ,
254
- "retries" : 2
255
- } ,
256
- "challengeIndicator" : "01" ,
257
- "createdAt" : "2023-01-19T17:07:17+01:00" ,
258
- "deviceChannel" : "app" ,
259
- "dsTransID" : "59de4e30-7f84-4a77-aaf8-1ca493092ef9" ,
260
- "exemptionIndicator" : "noExemptionApplied" ,
261
- "inPSD2Scope" : false ,
262
- "messageCategory" : "payment" ,
263
- "messageVersion" : "2.2.0" ,
264
- "threeDSServerTransID" : "8bc0fdbd-5c8a-4bed-a171-9d10347e7798" ,
265
- "transStatus" : "N" ,
266
- "transStatusReason" : "19" ,
267
- "type" : "challenge"
268
- } ,
269
- "paymentInstrumentId" : "PI3227C223222B5BPCMFXD2XG" ,
270
- "purchase" : {
271
- "date" : "2022-12-22T15:49:03+01:00" ,
272
- "merchantName" : "TeaShop_NL" ,
273
- "originalAmount" : {
274
- "currency" : "EUR" ,
275
- "value" : 1000
276
- }
277
- } ,
278
- "status" : "rejected"
279
- } ,
280
- "environment" : "test" ,
281
- "type" : "balancePlatform.authentication.created"
282
- } ;
283
- const jsonString = JSON . stringify ( json ) ;
284
- const bankingWebhookHandler = new BankingWebhookHandler ( jsonString ) ;
285
- const accountHolderNotificationRequest : TransferNotificationRequest = bankingWebhookHandler . getTransferNotificationRequest ( ) ;
286
- const genericWebhook = bankingWebhookHandler . getGenericWebhook ( ) ;
287
- expect ( accountHolderNotificationRequest . type ) . toEqual ( AuthenticationNotificationRequest . TypeEnum . BalancePlatformAuthenticationCreated ) ;
288
- expect ( genericWebhook instanceof AccountHolderNotificationRequest ) . toBe ( false ) ;
289
- expect ( genericWebhook instanceof AuthenticationNotificationRequest ) . toBe ( true ) ;
290
- } ) ;
291
-
292
244
it ( "should deserialize Management v3 Webhooks" , function ( ) : void {
293
245
const json = {
294
246
"type" : "paymentMethodRequest.removed" ,
@@ -304,9 +256,9 @@ describe("Notification Test", function (): void {
304
256
}
305
257
} ;
306
258
const jsonString = JSON . stringify ( json ) ;
307
- const managementWebhookHandler = new ManagementWebhookHandler ( jsonString ) ;
308
- const paymentMethodRequestRemoved : PaymentMethodRequestRemovedNotificationRequest = managementWebhookHandler . getPaymentMethodRequestRemovedNotificationRequest ( ) ;
309
- const genericWebhook = managementWebhookHandler . getGenericWebhook ( ) ;
259
+ const managementWebhooksHandler = new ManagementWebhooksHandler ( jsonString ) ;
260
+ const paymentMethodRequestRemoved : PaymentMethodRequestRemovedNotificationRequest = managementWebhooksHandler . getPaymentMethodRequestRemovedNotificationRequest ( ) ;
261
+ const genericWebhook = managementWebhooksHandler . getGenericWebhook ( ) ;
310
262
expect ( genericWebhook instanceof PaymentMethodRequestRemovedNotificationRequest ) . toBe ( true ) ;
311
263
expect ( genericWebhook instanceof PaymentMethodScheduledForRemovalNotificationRequest ) . toBe ( false ) ;
312
264
expect ( paymentMethodRequestRemoved . type ) . toEqual ( PaymentMethodRequestRemovedNotificationRequest . TypeEnum . PaymentMethodRequestRemoved ) ;
@@ -354,44 +306,6 @@ describe("Notification Test", function (): void {
354
306
expect ( genericWebhook instanceof PaymentMethodScheduledForRemovalNotificationRequest ) . toBe ( false ) ;
355
307
} ) ;
356
308
357
- it ( "should deserialize NegativeBalanceCompensationWarning Webhook" , function ( ) : void {
358
- const json = {
359
- "data" : {
360
- "balancePlatform" : "YOUR_BALANCE_PLATFORM" ,
361
- "creationDate" : "2024-07-02T02:01:08+02:00" ,
362
- "id" : "BA00000000000000000001" ,
363
- "accountHolder" : {
364
- "description" : "Description for the account holder." ,
365
- "reference" : "YOUR_REFERENCE" ,
366
- "id" : "AH00000000000000000001"
367
- } ,
368
- "amount" : {
369
- "currency" : "EUR" ,
370
- "value" : - 145050
371
- } ,
372
- "liableBalanceAccountId" : "BA11111111111111111111" ,
373
- "negativeBalanceSince" : "2024-10-19T00:33:13+02:00" ,
374
- "scheduledCompensationAt" : "2024-12-01T01:00:00+01:00"
375
- } ,
376
- "environment" : "test" ,
377
- "timestamp" : "2024-10-22T00:00:00+02:00" ,
378
- "type" : "balancePlatform.negativeBalanceCompensationWarning.scheduled"
379
- } ;
380
- const jsonString = JSON . stringify ( json ) ;
381
- const bankingWebhookHandler = new BankingWebhookHandler ( jsonString ) ;
382
- const negativeBalanceCompensationWarningNotificationRequest = bankingWebhookHandler . getNegativeBalanceCompensationWarningNotificationRequest ( ) ;
383
- expect ( negativeBalanceCompensationWarningNotificationRequest ) . toBeTruthy ( ) ;
384
- expect ( negativeBalanceCompensationWarningNotificationRequest . type ) . toBe ( NegativeBalanceCompensationWarningNotificationRequest
385
- . TypeEnum . BalancePlatformNegativeBalanceCompensationWarningScheduled
386
- ) ;
387
- expect ( negativeBalanceCompensationWarningNotificationRequest . environment ) . toBe ( "test" ) ;
388
- expect ( negativeBalanceCompensationWarningNotificationRequest . timestamp ?. toISOString ( ) ) . toBe ( new Date ( "2024-10-22T00:00:00+02:00" ) . toISOString ( ) ) ;
389
- expect ( negativeBalanceCompensationWarningNotificationRequest . data ) . toBeDefined ( ) ;
390
- expect ( negativeBalanceCompensationWarningNotificationRequest . data . balancePlatform ) . toBe ( "YOUR_BALANCE_PLATFORM" ) ;
391
- expect ( negativeBalanceCompensationWarningNotificationRequest . data . id ) . toBe ( "BA00000000000000000001" ) ;
392
- expect ( negativeBalanceCompensationWarningNotificationRequest . data . creationDate ?. toISOString ( ) ) . toBe ( new Date ( "2024-07-02T02:01:08+02:00" ) . toISOString ( ) ) ;
393
- } ) ;
394
-
395
309
it ( "should deserialize AcsWebhook AuthenticationNotificationRequest" , function ( ) : void {
396
310
const json = {
397
311
"data" : {
@@ -768,13 +682,20 @@ describe("Notification Test", function (): void {
768
682
// test getNegativeBalanceCompensationWarningNotificationRequest
769
683
const negativeBalanceCompensationWarningNotificationRequest : NegativeBalanceCompensationWarningNotificationRequest = negativeBalanceWarningWebhooksHandler . getNegativeBalanceCompensationWarningNotificationRequest ( ) ;
770
684
expect ( negativeBalanceCompensationWarningNotificationRequest . type ) . toEqual ( NegativeBalanceCompensationWarningNotificationRequest . TypeEnum . BalancePlatformNegativeBalanceCompensationWarningScheduled ) ;
685
+ expect ( negativeBalanceCompensationWarningNotificationRequest . environment ) . toBe ( "test" ) ;
686
+ expect ( negativeBalanceCompensationWarningNotificationRequest . timestamp ?. toISOString ( ) ) . toBe ( new Date ( "2024-10-22T00:00:00+02:00" ) . toISOString ( ) ) ;
687
+ expect ( negativeBalanceCompensationWarningNotificationRequest . data ) . toBeDefined ( ) ;
688
+ expect ( negativeBalanceCompensationWarningNotificationRequest . data . balancePlatform ) . toBe ( "YOUR_BALANCE_PLATFORM" ) ;
689
+ expect ( negativeBalanceCompensationWarningNotificationRequest . data . id ) . toBe ( "BA00000000000000000001" ) ;
690
+ expect ( negativeBalanceCompensationWarningNotificationRequest . data . creationDate ?. toISOString ( ) ) . toBe ( new Date ( "2024-10-22T00:00:00+02:00" ) . toISOString ( ) ) ;
771
691
// test getGenericWebhook
772
692
const genericWebhook = negativeBalanceWarningWebhooksHandler . getGenericWebhook ( ) ;
773
693
expect ( genericWebhook instanceof NegativeBalanceCompensationWarningNotificationRequest ) . toBe ( true ) ;
774
694
expect ( genericWebhook . type ) . toEqual ( "balancePlatform.negativeBalanceCompensationWarning.scheduled" ) ;
775
695
expect ( genericWebhook . data . accountHolder ?. reference ) . toEqual ( "YOUR_REFERENCE" ) ;
776
696
expect ( genericWebhook . data . accountHolder ?. id ) . toEqual ( "AH00000000000000000001" ) ;
777
- expect ( genericWebhook . data . negativeBalanceSince ?. toISOString ( ) ) . toEqual ( new Date ( "2024-10-19T00:33:13+02:00" ) . toISOString ( ) ) ;
697
+ expect ( genericWebhook . data . negativeBalanceSince ?. toISOString ( ) ) . toEqual ( new Date ( "2024-10-19T00:33:13+02:00" ) . toISOString ( ) ) ;
698
+
778
699
} ) ;
779
700
780
701
} ) ;
0 commit comments