-
Notifications
You must be signed in to change notification settings - Fork 62
/
terminalCloudAPI.ts
71 lines (61 loc) · 2.93 KB
/
terminalCloudAPI.ts
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
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* Adyen NodeJS API Library
* Copyright (c) 2021 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
import Service from "../service";
import Client from "../client";
import getJsonResponse from "../helpers/getJsonResponse";
import Async from "./resource/terminal/cloud/async";
import Sync from "./resource/terminal/cloud/sync";
import mergeDeep from "../utils/mergeDeep";
import { ApplicationInfo } from "../typings/applicationInfo";
import { ObjectSerializer, TerminalApiRequest, TerminalApiResponse } from "../typings/terminal/models";
class TerminalCloudAPI extends Service {
private readonly terminalApiAsync: Async;
private readonly terminalApiSync: Sync;
public constructor(client: Client) {
super(client);
this.apiKeyRequired = true;
this.terminalApiAsync = new Async(this);
this.terminalApiSync = new Sync(this);
}
private static setApplicationInfo(request: TerminalApiRequest): TerminalApiRequest {
if (request.SaleToPOIRequest.PaymentRequest) {
const applicationInfo = new ApplicationInfo();
const saleToAcquirerData = {applicationInfo};
const saleData = {saleToAcquirerData};
const paymentRequest = {saleData};
const saleToPOIRequest = {paymentRequest};
const reqWithAppInfo = {saleToPOIRequest};
mergeDeep(request, reqWithAppInfo);
}
return ObjectSerializer.serialize(request, "TerminalApiRequest");
}
public async(terminalApiRequest: TerminalApiRequest): Promise<string> {
const request = TerminalCloudAPI.setApplicationInfo(terminalApiRequest);
return getJsonResponse<TerminalApiRequest>(this.terminalApiAsync, request);
}
public async sync(terminalApiRequest: TerminalApiRequest): Promise<TerminalApiResponse> {
const request = TerminalCloudAPI.setApplicationInfo(terminalApiRequest);
const response = await getJsonResponse<TerminalApiRequest, TerminalApiResponse>(
this.terminalApiSync,
request,
);
return ObjectSerializer.deserialize(response, "TerminalApiResponse");
}
}
export default TerminalCloudAPI;