Skip to content

Commit 1702cda

Browse files
authored
Merge pull request #1505 from Adyen/typescript-openapi-generator
WIP Typescript OpenAPI Generator v7
2 parents 00eec6f + 23dd113 commit 1702cda

File tree

371 files changed

+15812
-7705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

371 files changed

+15812
-7705
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/src/typings/**/*.ts
21
/examples

.eslintrc.js

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
1-
const path = require('path');
1+
const path = require("path");
22

33
module.exports = {
44
parser: "@typescript-eslint/parser",
55
plugins: ["@typescript-eslint", "unused-imports"],
66
env: {
77
es6: true,
8-
node: true
8+
node: true,
99
},
1010
parserOptions: {
1111
ecmaVersion: 6,
1212
sourceType: "module",
1313
ecmaFeatures: {
14-
modules: true
14+
modules: true,
1515
},
1616
project: path.resolve(__dirname, "./tsconfig.json"),
17-
tsconfigRootDir: __dirname
18-
},
19-
extends: [
20-
"eslint:recommended",
21-
"plugin:@typescript-eslint/recommended"
22-
],
23-
rules: {
24-
quotes: ["error", "double"],
25-
semi: ["error", "always"],
26-
"@typescript-eslint/no-non-null-assertion": 0,
27-
"@typescript-eslint/ban-types": [
28-
"error",
29-
{
30-
"extendDefaults": true,
31-
"types": {
32-
"{}": false
33-
}
34-
}
35-
],
36-
"unused-imports/no-unused-imports": "warn",
17+
tsconfigRootDir: __dirname,
3718
},
3819
overrides: [
20+
// Override for src/typings/**/*.ts — only unused-imports
3921
{
40-
files: ["*.ts"],
22+
files: ["src/typings/**/*.ts"],
4123
rules: {
42-
"no-dupe-class-members": "off"
43-
}
44-
}
45-
]
46-
}
24+
"unused-imports/no-unused-imports": "warn",
25+
},
26+
},
27+
// Default rule set for everything else
28+
{
29+
files: ["*.ts", "**/*.ts"],
30+
excludedFiles: ["src/typings/**/*.ts"],
31+
rules: {
32+
quotes: ["error", "double"],
33+
semi: ["error", "always"],
34+
"@typescript-eslint/no-non-null-assertion": 0,
35+
"@typescript-eslint/ban-types": [
36+
"error",
37+
{
38+
extendDefaults: true,
39+
types: {
40+
"{}": false,
41+
},
42+
},
43+
],
44+
"unused-imports/no-unused-imports": "warn",
45+
"no-dupe-class-members": "off",
46+
},
47+
},
48+
],
49+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* ######
3+
* ######
4+
* ############ ####( ###### #####. ###### ############ ############
5+
* ############# #####( ###### #####. ###### ############# #############
6+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
7+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
9+
* ############# ############# ############# ############# ##### ######
10+
* ############ ############ ############# ############ ##### ######
11+
* ######
12+
* #############
13+
* ############
14+
* Adyen NodeJS API Library
15+
* Copyright (c) 2020 Adyen B.V.
16+
* This file is open source and available under the MIT license.
17+
* See the LICENSE file for more info.
18+
*/
19+
20+
/* tslint:disable */
21+
export const payments3DS2NativeAction = JSON.stringify({
22+
action:{
23+
type:"threeDS2",
24+
subtype: "fingerprint",
25+
paymentData:"Ab02b4c0!BQABAgCuZFJrQOjSslzt+...",
26+
paymentMethodType:"scheme",
27+
authorisationToken : "Ab02b4c0!BQABAgAvrX03p...",
28+
token:"eyJ0aHJlZURTTWV0aG9kTm90aWZpY..."
29+
},
30+
pspReference: "JLCMPCQ8HXSKGK82",
31+
resultCode:"IdentifyShopper",
32+
}, null, 2);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* ######
3+
* ######
4+
* ############ ####( ###### #####. ###### ############ ############
5+
* ############# #####( ###### #####. ###### ############# #############
6+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
7+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
9+
* ############# ############# ############# ############# ##### ######
10+
* ############ ############ ############# ############ ##### ######
11+
* ######
12+
* #############
13+
* ############
14+
* Adyen NodeJS API Library
15+
* Copyright (c) 2020 Adyen B.V.
16+
* This file is open source and available under the MIT license.
17+
* See the LICENSE file for more info.
18+
*/
19+
20+
/* tslint:disable */
21+
export const paymentsRedirectAction = JSON.stringify({
22+
additionalData: {
23+
"cardSummary": "5454",
24+
"threeds2.threeDS2ResponseData.messageVersion": "2.1.0",
25+
"threeds2.threeDS2Token": "R5CZ2NWPJTGV9D82...",
26+
"threeds2.threeDSServerTransID": "8835538461311270...",
27+
"cardBin": "545454",
28+
"threeds2.cardEnrolled": "true",
29+
"paymentMethod": "mc",
30+
"cardPaymentMethod": "mc",
31+
"fundingSource": "CREDIT",
32+
"merchantReference": "Your order number",
33+
"issuerBin": "54545454",
34+
"threeds2.threeDSMethodURL": "https://pal-test.adyen.com/threeds2simulator/acs/startMethod.shtml",
35+
"cardIssuingCountry": "PL"
36+
},
37+
pspReference: "JLCMPCQ8HXSKGK82",
38+
resultCode: "RedirectShopper",
39+
action: {
40+
paymentMethodType: "scheme",
41+
url: "https://checkoutshopper-test.adyen.com/checkoutshopper/threeDS/redirect...",
42+
method: "GET",
43+
type: "redirect"
44+
}
45+
}, null, 2);

src/__tests__/binLookup.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nock from "nock";
22
import { createClient } from "../__mocks__/base";
3-
import BinLookup from "../services/binLookupApi";
3+
import { BinLookupAPI } from "../services";
44
import Client from "../client";
55
import HttpClientException from "../httpClient/httpClientException";
66
import { binlookup } from "../typings";
@@ -15,15 +15,15 @@ const threeDSAvailabilitySuccess = {
1515
};
1616

1717
let client: Client;
18-
let binLookupService: BinLookup;
18+
let binLookupService: BinLookupAPI;
1919
let scope: nock.Scope;
2020

2121
beforeEach((): void => {
2222
if (!nock.isActive()) {
2323
nock.activate();
2424
}
2525
client = createClient();
26-
binLookupService = new BinLookup(client);
26+
binLookupService = new BinLookupAPI(client);
2727
scope = nock("https://pal-test.adyen.com/pal/servlet/BinLookup/v54");
2828
});
2929

@@ -42,7 +42,7 @@ describe("Bin Lookup", function (): void {
4242
scope.post("/get3dsAvailability")
4343
.reply(200, threeDSAvailabilitySuccess);
4444

45-
const response = await binLookupService.get3dsAvailability(threeDSAvailabilityRequest);
45+
const response = await binLookupService.BinLookupApi.get3dsAvailability(threeDSAvailabilityRequest);
4646

4747
expect(response).toEqual< binlookup.ThreeDSAvailabilityResponse>(threeDSAvailabilitySuccess);
4848
});
@@ -58,7 +58,7 @@ describe("Bin Lookup", function (): void {
5858
.reply(403, JSON.stringify({status: 403, message: "Invalid Merchant Account", errorCode: "901", errorType: "security"}));
5959

6060
try {
61-
await binLookupService.get3dsAvailability(threeDSAvailabilityRequest as unknown as binlookup.ThreeDSAvailabilityRequest);
61+
await binLookupService.BinLookupApi.get3dsAvailability(threeDSAvailabilityRequest as unknown as binlookup.ThreeDSAvailabilityRequest);
6262
fail("Expected request to fail");
6363
} catch (e) {
6464
expect(e instanceof HttpClientException).toBeTruthy();
@@ -101,7 +101,7 @@ describe("Bin Lookup", function (): void {
101101
scope.post("/getCostEstimate")
102102
.reply(200, expected);
103103

104-
const response = await binLookupService.getCostEstimate(costEstimateRequest);
104+
const response = await binLookupService.BinLookupApi.getCostEstimate(costEstimateRequest);
105105

106106
expect(response).toEqual(expected);
107107
});

src/__tests__/checkout.spec.ts

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import nock from "nock";
22
import {createClient} from "../__mocks__/base";
33
import {paymentMethodsSuccess} from "../__mocks__/checkout/paymentMethodsSuccess";
44
import {paymentsSuccess} from "../__mocks__/checkout/paymentsSuccess";
5+
import {paymentsRedirectAction} from "../__mocks__/checkout/paymentsRedirectAction";
56
import {paymentDetailsSuccess} from "../__mocks__/checkout/paymentsDetailsSuccess";
67
// import {paymentSessionSuccess} from "../__mocks__/checkout/paymentSessionSucess";
78
import {originKeysSuccess} from "../__mocks__/checkout/originkeysSuccess";
@@ -14,6 +15,7 @@ import HttpClientException from "../httpClient/httpClientException";
1415
import { checkout } from "../typings";
1516
import { IRequest } from "../typings/requestOptions";
1617
import { SessionResultResponse } from "../typings/checkout/sessionResultResponse";
18+
import { payments3DS2NativeAction } from "../__mocks__/checkout/payments3DS2NativeAction";
1719

1820
const merchantAccount = process.env.ADYEN_MERCHANT!;
1921
const reference = "Your order number";
@@ -79,8 +81,11 @@ function getPaymentLinkSuccess(expiresAt: Date): checkout.PaymentLinkResponse {
7981
url: "PaymentLinkResponse.url",
8082
id: "mocked_id",
8183
merchantAccount,
82-
status: checkout.PaymentLinkResponse.StatusEnum.Active
83-
};
84+
status: checkout.PaymentLinkResponse.StatusEnum.Active,
85+
requiredShopperFields: [
86+
checkout.PaymentLinkResponse.RequiredShopperFieldsEnum.BillingAddress,
87+
checkout.PaymentLinkResponse.RequiredShopperFieldsEnum.ShopperEmail]
88+
};
8489
}
8590

8691
function createPaymentLinkRequest(): checkout.PaymentLinkRequest {
@@ -108,7 +113,10 @@ function createPaymentLinkRequest(): checkout.PaymentLinkRequest {
108113
country: "BR",
109114
stateOrProvince: "SP"
110115
},
111-
reference
116+
reference,
117+
requiredShopperFields: [
118+
checkout.PaymentLinkRequest.RequiredShopperFieldsEnum.BillingAddress,
119+
checkout.PaymentLinkRequest.RequiredShopperFieldsEnum.ShopperEmail]
112120
};
113121
}
114122

@@ -154,7 +162,7 @@ describe("Checkout", (): void => {
154162
"returnUrl": "https://your-company.com/...",
155163
"merchantAccount": "YOUR_MERCHANT_ACCOUNT"
156164
}`);
157-
const paymentRequest: checkout.PaymentRequest = await checkout.ObjectSerializer.deserialize(requestJson,"PaymentRequest");
165+
const paymentRequest: checkout.PaymentRequest = await checkout.ObjectSerializer.deserialize(requestJson, "PaymentRequest", "");
158166
expect(paymentRequest.returnUrl).toEqual("https://your-company.com/...");
159167
expect(paymentRequest.amount.value).toBe(1000);
160168
const paymentMethodDetails: checkout.ApplePayDetails = paymentRequest.paymentMethod as checkout.ApplePayDetails;
@@ -239,7 +247,6 @@ describe("Checkout", (): void => {
239247

240248
});
241249

242-
243250
test("should make a payment.", async (): Promise<void> => {
244251
scope.post("/payments")
245252
.reply(200, paymentsSuccess);
@@ -311,7 +318,7 @@ describe("Checkout", (): void => {
311318
}
312319
});
313320

314-
test("should have valid payment link", async (): Promise<void> => {
321+
test("should create valid payment link", async (): Promise<void> => {
315322
const expiresAt = "2019-12-17T10:05:29Z";
316323
const paymentLinkSuccess: checkout.PaymentLinkResponse = getPaymentLinkSuccess(new Date(expiresAt));
317324

@@ -321,6 +328,28 @@ describe("Checkout", (): void => {
321328
expect(paymentSuccessLinkResponse).toBeTruthy();
322329
});
323330

331+
test("should create valid payment link with installmentOptions", async (): Promise<void> => {
332+
const expiresAt = "2019-12-17T10:05:29Z";
333+
const paymentLinkSuccess: checkout.PaymentLinkResponse = getPaymentLinkSuccess(new Date(expiresAt));
334+
335+
scope.post("/paymentLinks").reply(200, paymentLinkSuccess);
336+
337+
const request : checkout.PaymentLinkRequest = createPaymentLinkRequest();
338+
request.installmentOptions = {
339+
card: {
340+
plans: [
341+
checkout.CheckoutSessionInstallmentOption.PlansEnum.Bonus,
342+
checkout.CheckoutSessionInstallmentOption.PlansEnum.BuynowPaylater
343+
]
344+
}
345+
};
346+
const paymentSuccessLinkResponse = await checkoutService.PaymentLinksApi.paymentLinks(request);
347+
expect(paymentSuccessLinkResponse).toBeTruthy();
348+
expect(paymentSuccessLinkResponse.id).toBeTruthy();
349+
expect(paymentSuccessLinkResponse.id).toBe("mocked_id");
350+
expect(paymentSuccessLinkResponse.requiredShopperFields?.length).toBe(2);
351+
});
352+
324353
test("should get payment link", async (): Promise<void> => {
325354
const expiresAt = "2019-12-17T10:05:29Z";
326355
const paymentLinkSuccess: checkout.PaymentLinkResponse = getPaymentLinkSuccess(new Date(expiresAt));
@@ -401,6 +430,46 @@ describe("Checkout", (): void => {
401430
expect(paymentsResponse.additionalData).toBeTruthy();
402431
});
403432

433+
test("should return shopper redirect with a card payment.", async (): Promise<void> => {
434+
scope.post("/payments")
435+
.reply(200, paymentsRedirectAction);
436+
437+
const paymentsRequest: checkout.PaymentRequest = createPaymentsCheckoutRequest();
438+
const paymentsResponse: checkout.PaymentResponse = await checkoutService.PaymentsApi.payments(paymentsRequest);
439+
440+
expect(paymentsResponse.pspReference).toBeTruthy();
441+
expect(paymentsResponse.resultCode).toBeTruthy();
442+
expect(paymentsResponse.resultCode).toEqual("RedirectShopper");
443+
expect(paymentsResponse.action).toBeTruthy();
444+
// check type redirect
445+
expect(paymentsResponse.action?.type).toBeTruthy();
446+
expect(paymentsResponse.action?.type).toEqual("redirect");
447+
// TODO check action is polymorphic
448+
//expect(paymentsResponse.action).toBeInstanceOf(CheckoutRedirectAction);
449+
//expect(paymentsResponse.action?.url).toBe("https://checkoutshopper-test.adyen.com/checkoutshopper/threeDS/redirect...");
450+
451+
});
452+
453+
test("should return Native 3DS2 with a card payment.", async (): Promise<void> => {
454+
scope.post("/payments")
455+
.reply(200, payments3DS2NativeAction);
456+
457+
const paymentsRequest: checkout.PaymentRequest = createPaymentsCheckoutRequest();
458+
const paymentsResponse: checkout.PaymentResponse = await checkoutService.PaymentsApi.payments(paymentsRequest);
459+
460+
expect(paymentsResponse.pspReference).toBeTruthy();
461+
expect(paymentsResponse.resultCode).toBeTruthy();
462+
expect(paymentsResponse.resultCode).toEqual("IdentifyShopper");
463+
expect(paymentsResponse.action).toBeTruthy();
464+
// check type threeDS2
465+
expect(paymentsResponse.action?.type).toBeTruthy();
466+
expect(paymentsResponse.action?.type).toEqual("threeDS2");
467+
// TODO check action is polymorphic
468+
//expect(paymentsResponse.action).toBeInstanceOf(CheckoutThreeDS2Action);
469+
//expect(paymentsResponse.action?.subtype).toEqual("threeDS2");
470+
471+
});
472+
404473
test("should get origin keys", async (): Promise<void> => {
405474
const checkoutUtility = new CheckoutAPI(client);
406475
const originKeysRequest: checkout.UtilityRequest = {
@@ -508,6 +577,25 @@ describe("Checkout", (): void => {
508577
expect(sessionsResponse.expiresAt.getFullYear()).toBeGreaterThan(0);
509578
});
510579

580+
test("should create a session with installmentOptions.", async (): Promise<void> => {
581+
scope.post("/sessions")
582+
.reply(200, sessionsSuccess);
583+
584+
const sessionsRequest: checkout.CreateCheckoutSessionRequest = createSessionRequest();
585+
sessionsRequest.installmentOptions = {
586+
card: {
587+
plans: [
588+
checkout.CheckoutSessionInstallmentOption.PlansEnum.Bonus,
589+
checkout.CheckoutSessionInstallmentOption.PlansEnum.BuynowPaylater
590+
]
591+
}
592+
};
593+
const sessionsResponse: checkout.CreateCheckoutSessionResponse = await checkoutService.PaymentsApi.sessions(sessionsRequest);
594+
expect(sessionsResponse.sessionData).toBeTruthy();
595+
expect(sessionsResponse.expiresAt).toBeInstanceOf(Date);
596+
expect(sessionsResponse.expiresAt.getFullYear()).toBeGreaterThan(0);
597+
});
598+
511599
test("Should get card details", async (): Promise<void> => {
512600
scope.post("/cardDetails")
513601
.reply(200, {

0 commit comments

Comments
 (0)