-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathconfigurationWebhooksHandler.ts
More file actions
143 lines (119 loc) · 5.56 KB
/
configurationWebhooksHandler.ts
File metadata and controls
143 lines (119 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* The version of the OpenAPI document: v2
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
import { configurationWebhooks } from "..";
/**
* Union type for all supported webhook requests.
* Allows generic handling of configuration-related webhook events.
*/
export type GenericWebhook =
| configurationWebhooks.AccountHolderNotificationRequest
| configurationWebhooks.BalanceAccountNotificationRequest
| configurationWebhooks.CardOrderNotificationRequest
| configurationWebhooks.NetworkTokenNotificationRequest
| configurationWebhooks.PaymentNotificationRequest
| configurationWebhooks.ScoreNotificationRequest
| configurationWebhooks.SweepConfigurationNotificationRequest;
/**
* Handler for processing ConfigurationWebhooks.
*
* This class provides functionality to deserialize the payload of ConfigurationWebhooks events.
*/
export class ConfigurationWebhooksHandler {
private readonly payload: Record<string, any>;
public constructor(jsonPayload: string) {
this.payload = JSON.parse(jsonPayload);
}
/**
* This method checks the type of the webhook payload and returns the appropriate deserialized object.
*
* @returns A deserialized object of type GenericWebhook.
* @throws Error if the type is not recognized.
*/
public getGenericWebhook(): GenericWebhook {
const type = this.payload["type"];
if(Object.values(configurationWebhooks.AccountHolderNotificationRequest.TypeEnum).includes(type)) {
return this.getAccountHolderNotificationRequest();
}
if(Object.values(configurationWebhooks.BalanceAccountNotificationRequest.TypeEnum).includes(type)) {
return this.getBalanceAccountNotificationRequest();
}
if(Object.values(configurationWebhooks.CardOrderNotificationRequest.TypeEnum).includes(type)) {
return this.getCardOrderNotificationRequest();
}
if(Object.values(configurationWebhooks.NetworkTokenNotificationRequest.TypeEnum).includes(type)) {
return this.getNetworkTokenNotificationRequest();
}
if(Object.values(configurationWebhooks.PaymentNotificationRequest.TypeEnum).includes(type)) {
return this.getPaymentNotificationRequest();
}
if(Object.values(configurationWebhooks.ScoreNotificationRequest.TypeEnum).includes(type)) {
return this.getScoreNotificationRequest();
}
if(Object.values(configurationWebhooks.SweepConfigurationNotificationRequest.TypeEnum).includes(type)) {
return this.getSweepConfigurationNotificationRequest();
}
throw new Error("Could not parse the json payload: " + this.payload);
}
/**
* Deserialize the webhook payload into a AccountHolderNotificationRequest
*
* @returns Deserialized AccountHolderNotificationRequest object.
*/
public getAccountHolderNotificationRequest(): configurationWebhooks.AccountHolderNotificationRequest {
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "AccountHolderNotificationRequest");
}
/**
* Deserialize the webhook payload into a BalanceAccountNotificationRequest
*
* @returns Deserialized BalanceAccountNotificationRequest object.
*/
public getBalanceAccountNotificationRequest(): configurationWebhooks.BalanceAccountNotificationRequest {
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "BalanceAccountNotificationRequest");
}
/**
* Deserialize the webhook payload into a CardOrderNotificationRequest
*
* @returns Deserialized CardOrderNotificationRequest object.
*/
public getCardOrderNotificationRequest(): configurationWebhooks.CardOrderNotificationRequest {
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "CardOrderNotificationRequest");
}
/**
* Deserialize the webhook payload into a NetworkTokenNotificationRequest
*
* @returns Deserialized NetworkTokenNotificationRequest object.
*/
public getNetworkTokenNotificationRequest(): configurationWebhooks.NetworkTokenNotificationRequest {
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "NetworkTokenNotificationRequest");
}
/**
* Deserialize the webhook payload into a PaymentNotificationRequest
*
* @returns Deserialized PaymentNotificationRequest object.
*/
public getPaymentNotificationRequest(): configurationWebhooks.PaymentNotificationRequest {
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "PaymentNotificationRequest");
}
/**
* Deserialize the webhook payload into a ScoreNotificationRequest
*
* @returns Deserialized ScoreNotificationRequest object.
*/
public getScoreNotificationRequest(): configurationWebhooks.ScoreNotificationRequest {
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "ScoreNotificationRequest");
}
/**
* Deserialize the webhook payload into a SweepConfigurationNotificationRequest
*
* @returns Deserialized SweepConfigurationNotificationRequest object.
*/
public getSweepConfigurationNotificationRequest(): configurationWebhooks.SweepConfigurationNotificationRequest {
return configurationWebhooks.ObjectSerializer.deserialize(this.payload, "SweepConfigurationNotificationRequest");
}
}