@n3oltd/umbraco-payments-opayo-client 9.0.0-beta-77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts ADDED
@@ -0,0 +1,469 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ //----------------------
4
+ // <auto-generated>
5
+ // Generated using the NSwag toolchain v13.15.5.0 (NJsonSchema v10.6.6.0 (Newtonsoft.Json v9.0.0.0)) (http://NSwag.org)
6
+ // </auto-generated>
7
+ //----------------------
8
+ // ReSharper disable InconsistentNaming
9
+
10
+ export class OpayoClient {
11
+ private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
12
+ private baseUrl: string;
13
+ protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
14
+
15
+ constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
16
+ this.http = http ? http : <any>window;
17
+ this.baseUrl = baseUrl !== undefined && baseUrl !== null ? baseUrl : "https://localhost:5001";
18
+ }
19
+
20
+ getMerchantSessionKey(): Promise<void> {
21
+ let url_ = this.baseUrl + "/umbraco/api/Opayo/merchantSessionKey";
22
+ url_ = url_.replace(/[?&]$/, "");
23
+
24
+ let options_ = <RequestInit>{
25
+ method: "GET",
26
+ headers: {
27
+ }
28
+ };
29
+
30
+ return this.http.fetch(url_, options_).then((_response: Response) => {
31
+ return this.processGetMerchantSessionKey(_response);
32
+ });
33
+ }
34
+
35
+ protected processGetMerchantSessionKey(response: Response): Promise<void> {
36
+ const status = response.status;
37
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
38
+ if (status === 200) {
39
+ return response.text().then((_responseText) => {
40
+ return;
41
+ });
42
+ } else if (status === 400) {
43
+ return response.text().then((_responseText) => {
44
+ let result400: any = null;
45
+ result400 = _responseText === "" ? null : <ProblemDetails>JSON.parse(_responseText, this.jsonParseReviver);
46
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
47
+ });
48
+ } else if (status === 500) {
49
+ return response.text().then((_responseText) => {
50
+ return throwException("A server side error occurred.", status, _responseText, _headers);
51
+ });
52
+ } else if (status !== 200 && status !== 204) {
53
+ return response.text().then((_responseText) => {
54
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
55
+ });
56
+ }
57
+ return Promise.resolve<void>(<any>null);
58
+ }
59
+
60
+ process(flowId: string, req: OpayoPaymentReq): Promise<PaymentFlowResOfOpayoPayment> {
61
+ let url_ = this.baseUrl + "/umbraco/api/Opayo/{flowId}/payment/process";
62
+ if (flowId === undefined || flowId === null)
63
+ throw new Error("The parameter 'flowId' must be defined.");
64
+ url_ = url_.replace("{flowId}", encodeURIComponent("" + flowId));
65
+ url_ = url_.replace(/[?&]$/, "");
66
+
67
+ const content_ = JSON.stringify(req);
68
+
69
+ let options_ = <RequestInit>{
70
+ body: content_,
71
+ method: "POST",
72
+ headers: {
73
+ "Content-Type": "application/json",
74
+ "Accept": "application/json"
75
+ }
76
+ };
77
+
78
+ return this.http.fetch(url_, options_).then((_response: Response) => {
79
+ return this.processProcess(_response);
80
+ });
81
+ }
82
+
83
+ protected processProcess(response: Response): Promise<PaymentFlowResOfOpayoPayment> {
84
+ const status = response.status;
85
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
86
+ if (status === 200) {
87
+ return response.text().then((_responseText) => {
88
+ let result200: any = null;
89
+ result200 = _responseText === "" ? null : <PaymentFlowResOfOpayoPayment>JSON.parse(_responseText, this.jsonParseReviver);
90
+ return result200;
91
+ });
92
+ } else if (status === 400) {
93
+ return response.text().then((_responseText) => {
94
+ let result400: any = null;
95
+ result400 = _responseText === "" ? null : <ProblemDetails>JSON.parse(_responseText, this.jsonParseReviver);
96
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
97
+ });
98
+ } else if (status === 500) {
99
+ return response.text().then((_responseText) => {
100
+ return throwException("A server side error occurred.", status, _responseText, _headers);
101
+ });
102
+ } else if (status !== 200 && status !== 204) {
103
+ return response.text().then((_responseText) => {
104
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
105
+ });
106
+ }
107
+ return Promise.resolve<PaymentFlowResOfOpayoPayment>(<any>null);
108
+ }
109
+
110
+ authorize(flowId: string, cRes: string | null | undefined, threeDsSessionData: string | null | undefined): Promise<ThreeDSecureStatus> {
111
+ let url_ = this.baseUrl + "/umbraco/api/Opayo/{flowId}/authorize";
112
+ if (flowId === undefined || flowId === null)
113
+ throw new Error("The parameter 'flowId' must be defined.");
114
+ url_ = url_.replace("{flowId}", encodeURIComponent("" + flowId));
115
+ url_ = url_.replace(/[?&]$/, "");
116
+
117
+ const content_ = new FormData();
118
+ if (cRes !== null && cRes !== undefined)
119
+ content_.append("CRes", cRes.toString());
120
+ if (threeDsSessionData !== null && threeDsSessionData !== undefined)
121
+ content_.append("ThreeDsSessionData", threeDsSessionData.toString());
122
+
123
+ let options_ = <RequestInit>{
124
+ body: content_,
125
+ method: "POST",
126
+ headers: {
127
+ "Accept": "application/json"
128
+ }
129
+ };
130
+
131
+ return this.http.fetch(url_, options_).then((_response: Response) => {
132
+ return this.processAuthorize(_response);
133
+ });
134
+ }
135
+
136
+ protected processAuthorize(response: Response): Promise<ThreeDSecureStatus> {
137
+ const status = response.status;
138
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
139
+ if (status === 200) {
140
+ return response.text().then((_responseText) => {
141
+ let result200: any = null;
142
+ result200 = _responseText === "" ? null : <ThreeDSecureStatus>JSON.parse(_responseText, this.jsonParseReviver);
143
+ return result200;
144
+ });
145
+ } else if (status === 400) {
146
+ return response.text().then((_responseText) => {
147
+ let result400: any = null;
148
+ result400 = _responseText === "" ? null : <ProblemDetails>JSON.parse(_responseText, this.jsonParseReviver);
149
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
150
+ });
151
+ } else if (status === 500) {
152
+ return response.text().then((_responseText) => {
153
+ return throwException("A server side error occurred.", status, _responseText, _headers);
154
+ });
155
+ } else if (status !== 200 && status !== 204) {
156
+ return response.text().then((_responseText) => {
157
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
158
+ });
159
+ }
160
+ return Promise.resolve<ThreeDSecureStatus>(<any>null);
161
+ }
162
+
163
+ findPaymentMethods(req: PaymentMethodCriteria): Promise<PaymentMethodRes[]> {
164
+ let url_ = this.baseUrl + "/umbraco/api/Opayo/paymentMethods/find";
165
+ url_ = url_.replace(/[?&]$/, "");
166
+
167
+ const content_ = JSON.stringify(req);
168
+
169
+ let options_ = <RequestInit>{
170
+ body: content_,
171
+ method: "POST",
172
+ headers: {
173
+ "Content-Type": "application/json",
174
+ "Accept": "application/json"
175
+ }
176
+ };
177
+
178
+ return this.http.fetch(url_, options_).then((_response: Response) => {
179
+ return this.processFindPaymentMethods(_response);
180
+ });
181
+ }
182
+
183
+ protected processFindPaymentMethods(response: Response): Promise<PaymentMethodRes[]> {
184
+ const status = response.status;
185
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
186
+ if (status === 200) {
187
+ return response.text().then((_responseText) => {
188
+ let result200: any = null;
189
+ result200 = _responseText === "" ? null : <PaymentMethodRes[]>JSON.parse(_responseText, this.jsonParseReviver);
190
+ return result200;
191
+ });
192
+ } else if (status === 400) {
193
+ return response.text().then((_responseText) => {
194
+ let result400: any = null;
195
+ result400 = _responseText === "" ? null : <ProblemDetails>JSON.parse(_responseText, this.jsonParseReviver);
196
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
197
+ });
198
+ } else if (status === 500) {
199
+ return response.text().then((_responseText) => {
200
+ return throwException("A server side error occurred.", status, _responseText, _headers);
201
+ });
202
+ } else if (status !== 200 && status !== 204) {
203
+ return response.text().then((_responseText) => {
204
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
205
+ });
206
+ }
207
+ return Promise.resolve<PaymentMethodRes[]>(<any>null);
208
+ }
209
+
210
+ getLookupPaymentMethods(): Promise<PaymentMethodRes[]> {
211
+ let url_ = this.baseUrl + "/umbraco/api/Opayo/lookups/paymentMethods";
212
+ url_ = url_.replace(/[?&]$/, "");
213
+
214
+ let options_ = <RequestInit>{
215
+ method: "GET",
216
+ headers: {
217
+ "Accept": "application/json"
218
+ }
219
+ };
220
+
221
+ return this.http.fetch(url_, options_).then((_response: Response) => {
222
+ return this.processGetLookupPaymentMethods(_response);
223
+ });
224
+ }
225
+
226
+ protected processGetLookupPaymentMethods(response: Response): Promise<PaymentMethodRes[]> {
227
+ const status = response.status;
228
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
229
+ if (status === 200) {
230
+ return response.text().then((_responseText) => {
231
+ let result200: any = null;
232
+ result200 = _responseText === "" ? null : <PaymentMethodRes[]>JSON.parse(_responseText, this.jsonParseReviver);
233
+ return result200;
234
+ });
235
+ } else if (status === 400) {
236
+ return response.text().then((_responseText) => {
237
+ let result400: any = null;
238
+ result400 = _responseText === "" ? null : <ProblemDetails>JSON.parse(_responseText, this.jsonParseReviver);
239
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
240
+ });
241
+ } else if (status === 500) {
242
+ return response.text().then((_responseText) => {
243
+ return throwException("A server side error occurred.", status, _responseText, _headers);
244
+ });
245
+ } else if (status !== 200 && status !== 204) {
246
+ return response.text().then((_responseText) => {
247
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
248
+ });
249
+ }
250
+ return Promise.resolve<PaymentMethodRes[]>(<any>null);
251
+ }
252
+
253
+ getAllLookups(criteria: LookupsCriteria): Promise<PaymentsLookupsRes> {
254
+ let url_ = this.baseUrl + "/umbraco/api/Opayo/lookups/all";
255
+ url_ = url_.replace(/[?&]$/, "");
256
+
257
+ const content_ = JSON.stringify(criteria);
258
+
259
+ let options_ = <RequestInit>{
260
+ body: content_,
261
+ method: "POST",
262
+ headers: {
263
+ "Content-Type": "application/json",
264
+ "Accept": "application/json"
265
+ }
266
+ };
267
+
268
+ return this.http.fetch(url_, options_).then((_response: Response) => {
269
+ return this.processGetAllLookups(_response);
270
+ });
271
+ }
272
+
273
+ protected processGetAllLookups(response: Response): Promise<PaymentsLookupsRes> {
274
+ const status = response.status;
275
+ let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
276
+ if (status === 200) {
277
+ return response.text().then((_responseText) => {
278
+ let result200: any = null;
279
+ result200 = _responseText === "" ? null : <PaymentsLookupsRes>JSON.parse(_responseText, this.jsonParseReviver);
280
+ return result200;
281
+ });
282
+ } else if (status === 400) {
283
+ return response.text().then((_responseText) => {
284
+ let result400: any = null;
285
+ result400 = _responseText === "" ? null : <ProblemDetails>JSON.parse(_responseText, this.jsonParseReviver);
286
+ return throwException("A server side error occurred.", status, _responseText, _headers, result400);
287
+ });
288
+ } else if (status === 500) {
289
+ return response.text().then((_responseText) => {
290
+ return throwException("A server side error occurred.", status, _responseText, _headers);
291
+ });
292
+ } else if (status !== 200 && status !== 204) {
293
+ return response.text().then((_responseText) => {
294
+ return throwException("An unexpected server error occurred.", status, _responseText, _headers);
295
+ });
296
+ }
297
+ return Promise.resolve<PaymentsLookupsRes>(<any>null);
298
+ }
299
+ }
300
+
301
+ export interface ProblemDetails {
302
+ type?: string | undefined;
303
+ title?: string | undefined;
304
+ status?: number | undefined;
305
+ detail?: string | undefined;
306
+ instance?: string | undefined;
307
+ }
308
+
309
+ export interface PaymentFlowResOfOpayoPayment {
310
+ flowRevision?: number;
311
+ result?: OpayoPayment | undefined;
312
+ }
313
+
314
+ export interface OpayoPayment {
315
+ type?: PaymentObjectType | undefined;
316
+ declineReason?: string | undefined;
317
+ isDeclined?: boolean;
318
+ isPaid?: boolean;
319
+ isFailed?: boolean;
320
+ requireThreeDSecure?: boolean;
321
+ /** A well formed guid */
322
+ id?: string | undefined;
323
+ status?: PaymentObjectStatus | undefined;
324
+ transactionId?: string | undefined;
325
+ opayoErrorCode?: number | undefined;
326
+ opayoErrorMessage?: string | undefined;
327
+ opayoStatusDetail?: string | undefined;
328
+ opayoRetrievalReference?: number | undefined;
329
+ bankAuthorisationCode?: string | undefined;
330
+ threeDSecureUrl?: string | undefined;
331
+ acsTransId?: string | undefined;
332
+ cReq?: string | undefined;
333
+ callbackUrl?: string | undefined;
334
+ threeDSecureCompleted?: boolean;
335
+ method?: string | undefined;
336
+ }
337
+
338
+ /** One of 'credential', 'payment' */
339
+ export enum PaymentObjectType {
340
+ Credential = "credential",
341
+ Payment = "payment",
342
+ }
343
+
344
+ /** One of 'complete', 'failed', 'inProgress' */
345
+ export enum PaymentObjectStatus {
346
+ Complete = "complete",
347
+ Failed = "failed",
348
+ InProgress = "inProgress",
349
+ }
350
+
351
+ export interface OpayoPaymentReq {
352
+ cardIdentifier?: string | undefined;
353
+ merchantSessionKey?: string | undefined;
354
+ value?: MoneyReq | undefined;
355
+ callbackUrl?: string | undefined;
356
+ browserParameters?: BrowserParametersReq | undefined;
357
+ challengeWindowSize?: ChallengeWindowSize | undefined;
358
+ }
359
+
360
+ export interface MoneyReq {
361
+ amount?: number | undefined;
362
+ currency?: string | undefined;
363
+ }
364
+
365
+ export interface IPublishedContent {
366
+ id?: number;
367
+ name?: string | undefined;
368
+ urlSegment?: string | undefined;
369
+ sortOrder?: number;
370
+ level?: number;
371
+ path?: string | undefined;
372
+ templateId?: number | undefined;
373
+ creatorId?: number;
374
+ createDate?: Date;
375
+ writerId?: number;
376
+ updateDate?: Date;
377
+ cultures?: { [key: string]: PublishedCultureInfo; } | undefined;
378
+ itemType?: PublishedItemType;
379
+ parent?: IPublishedContent | undefined;
380
+ children?: IPublishedContent[] | undefined;
381
+ childrenForAllCultures?: IPublishedContent[] | undefined;
382
+ }
383
+
384
+ export interface PublishedCultureInfo {
385
+ culture?: string | undefined;
386
+ name?: string | undefined;
387
+ urlSegment?: string | undefined;
388
+ date?: Date;
389
+ }
390
+
391
+ export enum PublishedItemType {
392
+ Unknown = 0,
393
+ Element = 1,
394
+ Content = 2,
395
+ Media = 3,
396
+ Member = 4,
397
+ }
398
+
399
+ export interface BrowserParametersReq {
400
+ colourDepth?: number | undefined;
401
+ javaEnabled?: boolean | undefined;
402
+ javaScriptEnabled?: boolean | undefined;
403
+ screenHeight?: number | undefined;
404
+ screenWidth?: number | undefined;
405
+ utcOffsetMinutes?: number | undefined;
406
+ }
407
+
408
+ /** One of 'small', 'medium', 'large', 'extraLarge', 'fullScreen' */
409
+ export enum ChallengeWindowSize {
410
+ Small = "small",
411
+ Medium = "medium",
412
+ Large = "large",
413
+ ExtraLarge = "extraLarge",
414
+ FullScreen = "fullScreen",
415
+ }
416
+
417
+ export interface ThreeDSecureStatus {
418
+ completed?: boolean;
419
+ success?: boolean;
420
+ }
421
+
422
+ export interface PaymentMethodRes {
423
+ name?: string | undefined;
424
+ id?: string | undefined;
425
+ }
426
+
427
+ export interface PaymentMethodCriteria {
428
+ country?: string | undefined;
429
+ currency?: string | undefined;
430
+ }
431
+
432
+ export interface PaymentsLookupsRes {
433
+ paymentMethods?: PaymentMethodRes[] | undefined;
434
+ }
435
+
436
+ export interface LookupsCriteria {
437
+ types?: string[] | undefined;
438
+ }
439
+
440
+ export class ApiException extends Error {
441
+ message: string;
442
+ status: number;
443
+ response: string;
444
+ headers: { [key: string]: any; };
445
+ result: any;
446
+
447
+ constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) {
448
+ super();
449
+
450
+ this.message = message;
451
+ this.status = status;
452
+ this.response = response;
453
+ this.headers = headers;
454
+ this.result = result;
455
+ }
456
+
457
+ protected isApiException = true;
458
+
459
+ static isApiException(obj: any): obj is ApiException {
460
+ return obj.isApiException === true;
461
+ }
462
+ }
463
+
464
+ function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any {
465
+ if (result !== null && result !== undefined)
466
+ throw result;
467
+ else
468
+ throw new ApiException(message, status, response, headers, null);
469
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "es6",
4
+ "moduleResolution": "node",
5
+ "strict": true,
6
+ "target": "es5",
7
+ "sourceMap": true,
8
+ "declarationMap": true,
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "lib": ["es6", "dom"],
13
+ "declaration": true,
14
+ "outDir": "./esm",
15
+ "importHelpers": false,
16
+ "noEmitHelpers": false,
17
+ "rootDir": "src"
18
+ },
19
+ "include": ["./src/**/*.ts"],
20
+ "exclude": ["node_modules"]
21
+ }