-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathmanagementWebhooksHandler.ts
More file actions
143 lines (119 loc) · 5.96 KB
/
managementWebhooksHandler.ts
File metadata and controls
143 lines (119 loc) · 5.96 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: v3
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
import { managementWebhooks } from "..";
/**
* Union type for all supported webhook requests.
* Allows generic handling of configuration-related webhook events.
*/
export type GenericWebhook =
| managementWebhooks.MerchantCreatedNotificationRequest
| managementWebhooks.MerchantUpdatedNotificationRequest
| managementWebhooks.PaymentMethodCreatedNotificationRequest
| managementWebhooks.PaymentMethodRequestRemovedNotificationRequest
| managementWebhooks.PaymentMethodScheduledForRemovalNotificationRequest
| managementWebhooks.TerminalBoardingNotificationRequest
| managementWebhooks.TerminalSettingsNotificationRequest;
/**
* Handler for processing ManagementWebhooks.
*
* This class provides functionality to deserialize the payload of ManagementWebhooks events.
*/
export class ManagementWebhooksHandler {
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(managementWebhooks.MerchantCreatedNotificationRequest.TypeEnum).includes(type)) {
return this.getMerchantCreatedNotificationRequest();
}
if(Object.values(managementWebhooks.MerchantUpdatedNotificationRequest.TypeEnum).includes(type)) {
return this.getMerchantUpdatedNotificationRequest();
}
if(Object.values(managementWebhooks.PaymentMethodCreatedNotificationRequest.TypeEnum).includes(type)) {
return this.getPaymentMethodCreatedNotificationRequest();
}
if(Object.values(managementWebhooks.PaymentMethodRequestRemovedNotificationRequest.TypeEnum).includes(type)) {
return this.getPaymentMethodRequestRemovedNotificationRequest();
}
if(Object.values(managementWebhooks.PaymentMethodScheduledForRemovalNotificationRequest.TypeEnum).includes(type)) {
return this.getPaymentMethodScheduledForRemovalNotificationRequest();
}
if(Object.values(managementWebhooks.TerminalBoardingNotificationRequest.TypeEnum).includes(type)) {
return this.getTerminalBoardingNotificationRequest();
}
if(Object.values(managementWebhooks.TerminalSettingsNotificationRequest.TypeEnum).includes(type)) {
return this.getTerminalSettingsNotificationRequest();
}
throw new Error("Could not parse the json payload: " + this.payload);
}
/**
* Deserialize the webhook payload into a MerchantCreatedNotificationRequest
*
* @returns Deserialized MerchantCreatedNotificationRequest object.
*/
public getMerchantCreatedNotificationRequest(): managementWebhooks.MerchantCreatedNotificationRequest {
return managementWebhooks.ObjectSerializer.deserialize(this.payload, "MerchantCreatedNotificationRequest");
}
/**
* Deserialize the webhook payload into a MerchantUpdatedNotificationRequest
*
* @returns Deserialized MerchantUpdatedNotificationRequest object.
*/
public getMerchantUpdatedNotificationRequest(): managementWebhooks.MerchantUpdatedNotificationRequest {
return managementWebhooks.ObjectSerializer.deserialize(this.payload, "MerchantUpdatedNotificationRequest");
}
/**
* Deserialize the webhook payload into a PaymentMethodCreatedNotificationRequest
*
* @returns Deserialized PaymentMethodCreatedNotificationRequest object.
*/
public getPaymentMethodCreatedNotificationRequest(): managementWebhooks.PaymentMethodCreatedNotificationRequest {
return managementWebhooks.ObjectSerializer.deserialize(this.payload, "PaymentMethodCreatedNotificationRequest");
}
/**
* Deserialize the webhook payload into a PaymentMethodRequestRemovedNotificationRequest
*
* @returns Deserialized PaymentMethodRequestRemovedNotificationRequest object.
*/
public getPaymentMethodRequestRemovedNotificationRequest(): managementWebhooks.PaymentMethodRequestRemovedNotificationRequest {
return managementWebhooks.ObjectSerializer.deserialize(this.payload, "PaymentMethodRequestRemovedNotificationRequest");
}
/**
* Deserialize the webhook payload into a PaymentMethodScheduledForRemovalNotificationRequest
*
* @returns Deserialized PaymentMethodScheduledForRemovalNotificationRequest object.
*/
public getPaymentMethodScheduledForRemovalNotificationRequest(): managementWebhooks.PaymentMethodScheduledForRemovalNotificationRequest {
return managementWebhooks.ObjectSerializer.deserialize(this.payload, "PaymentMethodScheduledForRemovalNotificationRequest");
}
/**
* Deserialize the webhook payload into a TerminalBoardingNotificationRequest
*
* @returns Deserialized TerminalBoardingNotificationRequest object.
*/
public getTerminalBoardingNotificationRequest(): managementWebhooks.TerminalBoardingNotificationRequest {
return managementWebhooks.ObjectSerializer.deserialize(this.payload, "TerminalBoardingNotificationRequest");
}
/**
* Deserialize the webhook payload into a TerminalSettingsNotificationRequest
*
* @returns Deserialized TerminalSettingsNotificationRequest object.
*/
public getTerminalSettingsNotificationRequest(): managementWebhooks.TerminalSettingsNotificationRequest {
return managementWebhooks.ObjectSerializer.deserialize(this.payload, "TerminalSettingsNotificationRequest");
}
}