Skip to content

Commit a037fa6

Browse files
committed
Generate PaymentsAppApi
1 parent 0b4bd0d commit a037fa6

File tree

10 files changed

+585
-209
lines changed

10 files changed

+585
-209
lines changed

src/__tests__/paymentsAppApi.spec.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import nock from "nock";
2+
import { createClient } from "../__mocks__/base";
3+
import PaymentsAppApi from "../services/paymentsApp";
4+
import Client from "../client";
5+
import { PaymentsAppResponse } from "../typings/paymentsApp/models";
6+
7+
let client: Client;
8+
let paymentsAppApi: PaymentsAppApi;
9+
let scope: nock.Scope;
10+
11+
beforeEach((): void => {
12+
if (!nock.isActive()) {
13+
nock.activate();
14+
}
15+
client = createClient();
16+
paymentsAppApi = new PaymentsAppApi(client);
17+
scope = nock("https://management-test.adyen.com/v1");
18+
});
19+
20+
afterEach(() => {
21+
nock.cleanAll();
22+
});
23+
24+
describe("PaymentsAppApi", (): void => {
25+
test("should generate boarding token for merchant", async (): Promise<void> => {
26+
const mockResponse = {
27+
boardingToken: "mockedBoardingToken",
28+
installationId: "mockedInstallationId"
29+
};
30+
31+
scope.post("/merchants/testMerchant/generatePaymentsAppBoardingToken")
32+
.reply(200, mockResponse);
33+
34+
const request = {
35+
boardingRequestToken: "mockedRequestToken"
36+
};
37+
38+
const result = await paymentsAppApi.PaymentsAppApi.generatePaymentsAppBoardingTokenForMerchant("testMerchant", request);
39+
40+
expect(result).toBeTruthy();
41+
expect(result.boardingToken).toBe("mockedBoardingToken");
42+
expect(result.installationId).toBe("mockedInstallationId");
43+
});
44+
45+
test("should generate boarding token for store", async (): Promise<void> => {
46+
const mockResponse = {
47+
boardingToken: "mockedBoardingTokenStore",
48+
installationId: "mockedInstallationIdStore"
49+
};
50+
51+
scope.post("/merchants/testMerchant/stores/testStore/generatePaymentsAppBoardingToken")
52+
.reply(200, mockResponse);
53+
54+
const request = {
55+
boardingRequestToken: "mockedRequestTokenStore"
56+
};
57+
58+
const result = await paymentsAppApi.PaymentsAppApi.generatePaymentsAppBoardingTokenForStore("testMerchant", "testStore", request);
59+
60+
expect(result).toBeTruthy();
61+
expect(result.boardingToken).toBe("mockedBoardingTokenStore");
62+
expect(result.installationId).toBe("mockedInstallationIdStore");
63+
});
64+
65+
test("should list payments apps for merchant", async (): Promise<void> => {
66+
const mockResponse: PaymentsAppResponse = {
67+
paymentsApps: [
68+
{ installationId: "app1", merchantAccountCode: "merchantAccountCode", status: "BOARDED" },
69+
{ installationId: "app2", merchantAccountCode: "merchantAccountCode", status: "BOARDING" }
70+
]
71+
};
72+
73+
scope.get("/merchants/testMerchant/paymentsApps")
74+
.reply(200, mockResponse);
75+
76+
const result = await paymentsAppApi.PaymentsAppApi.listPaymentsAppForMerchant("testMerchant");
77+
78+
expect(result).toBeTruthy();
79+
expect(result.paymentsApps.length).toBe(2);
80+
expect(result.paymentsApps[0].installationId).toBe("app1");
81+
});
82+
83+
test("should list payments apps for store", async (): Promise<void> => {
84+
const mockResponse: PaymentsAppResponse = {
85+
paymentsApps: [
86+
{ installationId: "app3", merchantAccountCode: "merchantAccountCode", status: "REVOKED" }
87+
]
88+
};
89+
90+
scope.get("/merchants/testMerchant/stores/testStore/paymentsApps")
91+
.reply(200, mockResponse);
92+
93+
const result = await paymentsAppApi.PaymentsAppApi.listPaymentsAppForStore("testMerchant", "testStore");
94+
95+
expect(result).toBeTruthy();
96+
expect(result.paymentsApps.length).toBe(1);
97+
expect(result.paymentsApps[0].installationId).toBe("app3");
98+
});
99+
100+
test("should revoke payments app", async (): Promise<void> => {
101+
scope.post("/merchants/testMerchant/paymentsApps/installation123/revoke")
102+
.reply(200);
103+
104+
await expect(
105+
paymentsAppApi.PaymentsAppApi.revokePaymentsApp("testMerchant", "installation123")
106+
).resolves.toBeUndefined();
107+
});
108+
});

src/services/paymentsApp/paymentsAppApi.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
* Do not edit this class manually.
88
*/
99

10+
1011
import getJsonResponse from "../../helpers/getJsonResponse";
1112
import Service from "../../service";
1213
import Client from "../../client";
13-
import {
14-
BoardingTokenRequest,
15-
BoardingTokenResponse,
16-
PaymentsAppResponse,
17-
ObjectSerializer
18-
} from "../../typings/paymentsApp/models";
1914
import { IRequest } from "../../typings/requestOptions";
2015
import Resource from "../resource";
2116

17+
import { ObjectSerializer } from "../../typings/paymentsApp/objectSerializer";
18+
import { BoardingTokenRequest } from "../../typings/paymentsApp/models";
19+
import { BoardingTokenResponse } from "../../typings/paymentsApp/models";
20+
import { PaymentsAppResponse } from "../../typings/paymentsApp/models";
21+
22+
/**
23+
* API handler for PaymentsAppApi
24+
*/
2225
export class PaymentsAppApi extends Service {
2326

2427
private readonly API_BASEPATH: string = "https://management-live.adyen.com/v1";
@@ -40,13 +43,15 @@ export class PaymentsAppApi extends Service {
4043
const endpoint = `${this.baseUrl}/merchants/{merchantId}/generatePaymentsAppBoardingToken`
4144
.replace("{" + "merchantId" + "}", encodeURIComponent(String(merchantId)));
4245
const resource = new Resource(this, endpoint);
43-
const request: BoardingTokenRequest = ObjectSerializer.serialize(boardingTokenRequest, "BoardingTokenRequest");
46+
47+
const request: BoardingTokenRequest = ObjectSerializer.serialize(boardingTokenRequest, "BoardingTokenRequest", "");
4448
const response = await getJsonResponse<BoardingTokenRequest, BoardingTokenResponse>(
4549
resource,
4650
request,
4751
{ ...requestOptions, method: "POST" }
4852
);
49-
return ObjectSerializer.deserialize(response, "BoardingTokenResponse");
53+
54+
return ObjectSerializer.deserialize(response, "BoardingTokenResponse", "");
5055
}
5156

5257
/**
@@ -62,20 +67,22 @@ export class PaymentsAppApi extends Service {
6267
.replace("{" + "merchantId" + "}", encodeURIComponent(String(merchantId)))
6368
.replace("{" + "storeId" + "}", encodeURIComponent(String(storeId)));
6469
const resource = new Resource(this, endpoint);
65-
const request: BoardingTokenRequest = ObjectSerializer.serialize(boardingTokenRequest, "BoardingTokenRequest");
70+
71+
const request: BoardingTokenRequest = ObjectSerializer.serialize(boardingTokenRequest, "BoardingTokenRequest", "");
6672
const response = await getJsonResponse<BoardingTokenRequest, BoardingTokenResponse>(
6773
resource,
6874
request,
6975
{ ...requestOptions, method: "POST" }
7076
);
71-
return ObjectSerializer.deserialize(response, "BoardingTokenResponse");
77+
78+
return ObjectSerializer.deserialize(response, "BoardingTokenResponse", "");
7279
}
7380

7481
/**
7582
* @summary Get a list of Payments Apps - merchant level
7683
* @param merchantId {@link string } The unique identifier of the merchant account.
7784
* @param requestOptions {@link IRequest.Options }
78-
* @param statuses {@link string } The status of the Payments App. Comma-separated list of one or more values. If no value is provided, the list returns all statuses. Possible values: * **BOARDED** * **REVOKED**
85+
* @param statuses {@link string } The status of the Payments App. Comma-separated list of one or more values. If no value is provided, the list returns all statuses. Possible values: * **BOARDING** * **BOARDED** * **REVOKED**
7986
* @param limit {@link number } The number of items to return.
8087
* @param offset {@link number } The number of items to skip.
8188
* @return {@link PaymentsAppResponse }
@@ -84,6 +91,7 @@ export class PaymentsAppApi extends Service {
8491
const endpoint = `${this.baseUrl}/merchants/{merchantId}/paymentsApps`
8592
.replace("{" + "merchantId" + "}", encodeURIComponent(String(merchantId)));
8693
const resource = new Resource(this, endpoint);
94+
8795
const hasDefinedQueryParams = statuses ?? limit ?? offset;
8896
if(hasDefinedQueryParams) {
8997
if(!requestOptions) requestOptions = {};
@@ -97,15 +105,16 @@ export class PaymentsAppApi extends Service {
97105
"",
98106
{ ...requestOptions, method: "GET" }
99107
);
100-
return ObjectSerializer.deserialize(response, "PaymentsAppResponse");
108+
109+
return ObjectSerializer.deserialize(response, "PaymentsAppResponse", "");
101110
}
102111

103112
/**
104113
* @summary Get a list of Payments Apps - store level
105114
* @param merchantId {@link string } The unique identifier of the merchant account.
106115
* @param storeId {@link string } The unique identifier of the store.
107116
* @param requestOptions {@link IRequest.Options }
108-
* @param statuses {@link string } The status of the Payments App. Comma-separated list of one or more values. If no value is provided, the list returns all statuses. Possible values: * **BOARDED** * **REVOKED**
117+
* @param statuses {@link string } The status of the Payments App. Comma-separated list of one or more values. If no value is provided, the list returns all statuses. Possible values: * **BOARDING** * **BOARDED** * **REVOKED**
109118
* @param limit {@link number } The number of items to return.
110119
* @param offset {@link number } The number of items to skip.
111120
* @return {@link PaymentsAppResponse }
@@ -115,6 +124,7 @@ export class PaymentsAppApi extends Service {
115124
.replace("{" + "merchantId" + "}", encodeURIComponent(String(merchantId)))
116125
.replace("{" + "storeId" + "}", encodeURIComponent(String(storeId)));
117126
const resource = new Resource(this, endpoint);
127+
118128
const hasDefinedQueryParams = statuses ?? limit ?? offset;
119129
if(hasDefinedQueryParams) {
120130
if(!requestOptions) requestOptions = {};
@@ -128,24 +138,28 @@ export class PaymentsAppApi extends Service {
128138
"",
129139
{ ...requestOptions, method: "GET" }
130140
);
131-
return ObjectSerializer.deserialize(response, "PaymentsAppResponse");
141+
142+
return ObjectSerializer.deserialize(response, "PaymentsAppResponse", "");
132143
}
133144

134145
/**
135146
* @summary Revoke Payments App instance authentication
136147
* @param merchantId {@link string } The unique identifier of the merchant account.
137148
* @param installationId {@link string } The unique identifier of the Payments App instance on a device.
138149
* @param requestOptions {@link IRequest.Options }
150+
* @return {@link void }
139151
*/
140152
public async revokePaymentsApp(merchantId: string, installationId: string, requestOptions?: IRequest.Options): Promise<void> {
141153
const endpoint = `${this.baseUrl}/merchants/{merchantId}/paymentsApps/{installationId}/revoke`
142154
.replace("{" + "merchantId" + "}", encodeURIComponent(String(merchantId)))
143155
.replace("{" + "installationId" + "}", encodeURIComponent(String(installationId)));
144156
const resource = new Resource(this, endpoint);
157+
145158
await getJsonResponse<string, void>(
146159
resource,
147160
"",
148161
{ ...requestOptions, method: "POST" }
149162
);
150163
}
164+
151165
}

src/typings/paymentsApp/boardingTokenRequest.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@ export class BoardingTokenRequest {
1414
*/
1515
'boardingRequestToken': string;
1616

17-
static discriminator: string | undefined = undefined;
17+
static readonly discriminator: string | undefined = undefined;
1818

19-
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
19+
static readonly mapping: {[index: string]: string} | undefined = undefined;
20+
21+
static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
2022
{
2123
"name": "boardingRequestToken",
2224
"baseName": "boardingRequestToken",
23-
"type": "string"
25+
"type": "string",
26+
"format": ""
2427
} ];
2528

2629
static getAttributeTypeMap() {
2730
return BoardingTokenRequest.attributeTypeMap;
2831
}
32+
33+
public constructor() {
34+
}
2935
}
3036

src/typings/paymentsApp/boardingTokenResponse.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,29 @@ export class BoardingTokenResponse {
1818
*/
1919
'installationId': string;
2020

21-
static discriminator: string | undefined = undefined;
21+
static readonly discriminator: string | undefined = undefined;
2222

23-
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
23+
static readonly mapping: {[index: string]: string} | undefined = undefined;
24+
25+
static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
2426
{
2527
"name": "boardingToken",
2628
"baseName": "boardingToken",
27-
"type": "string"
29+
"type": "string",
30+
"format": ""
2831
},
2932
{
3033
"name": "installationId",
3134
"baseName": "installationId",
32-
"type": "string"
35+
"type": "string",
36+
"format": ""
3337
} ];
3438

3539
static getAttributeTypeMap() {
3640
return BoardingTokenResponse.attributeTypeMap;
3741
}
42+
43+
public constructor() {
44+
}
3845
}
3946

src/typings/paymentsApp/defaultErrorResponseEntity.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
* Do not edit this class manually.
88
*/
99

10-
import { InvalidField } from './invalidField';
10+
import { InvalidField } from './models';
1111

1212
/**
1313
* Standardized error response following RFC-7807 format
1414
*/
15+
16+
1517
export class DefaultErrorResponseEntity {
1618
/**
1719
* A human-readable explanation specific to this occurrence of the problem.
@@ -46,52 +48,65 @@ export class DefaultErrorResponseEntity {
4648
*/
4749
'type'?: string;
4850

49-
static discriminator: string | undefined = undefined;
51+
static readonly discriminator: string | undefined = undefined;
52+
53+
static readonly mapping: {[index: string]: string} | undefined = undefined;
5054

51-
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
55+
static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
5256
{
5357
"name": "detail",
5458
"baseName": "detail",
55-
"type": "string"
59+
"type": "string",
60+
"format": ""
5661
},
5762
{
5863
"name": "errorCode",
5964
"baseName": "errorCode",
60-
"type": "string"
65+
"type": "string",
66+
"format": ""
6167
},
6268
{
6369
"name": "instance",
6470
"baseName": "instance",
65-
"type": "string"
71+
"type": "string",
72+
"format": ""
6673
},
6774
{
6875
"name": "invalidFields",
6976
"baseName": "invalidFields",
70-
"type": "Array<InvalidField>"
77+
"type": "Array<InvalidField>",
78+
"format": ""
7179
},
7280
{
7381
"name": "requestId",
7482
"baseName": "requestId",
75-
"type": "string"
83+
"type": "string",
84+
"format": ""
7685
},
7786
{
7887
"name": "status",
7988
"baseName": "status",
80-
"type": "number"
89+
"type": "number",
90+
"format": "int32"
8191
},
8292
{
8393
"name": "title",
8494
"baseName": "title",
85-
"type": "string"
95+
"type": "string",
96+
"format": ""
8697
},
8798
{
8899
"name": "type",
89100
"baseName": "type",
90-
"type": "string"
101+
"type": "string",
102+
"format": ""
91103
} ];
92104

93105
static getAttributeTypeMap() {
94106
return DefaultErrorResponseEntity.attributeTypeMap;
95107
}
108+
109+
public constructor() {
110+
}
96111
}
97112

0 commit comments

Comments
 (0)