Skip to content

Commit 04747ce

Browse files
authored
Release v2.2.0
- Update: API type definitions (#176) - Feature: Adds paymentLinks service (#209)
2 parents 9f7d717 + ef269b7 commit 04747ce

File tree

259 files changed

+15270
-22635
lines changed

Some content is hidden

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

259 files changed

+15270
-22635
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Version](https://img.shields.io/npm/v/@adyen/api-library.svg)](https://www.npmjs.com/package/@adyen/api-library)
77
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Adyen_adyen-node-api-library&metric=alert_status)](https://sonarcloud.io/dashboard?id=Adyen_adyen-node-api-library)
88

9-
The Adyen API Library for NodeJS enables you to work with Adyen APIs and Hosted Payment Pages.
9+
The Adyen API Library for NodeJS enables you to work with Adyen APIs.
1010

1111
## Integration
1212
The Library supports all APIs under the following services:

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ module.exports = {
3333
],
3434
testMatch: [
3535
"**/__tests__/*.ts"
36+
],
37+
testPathIgnorePatterns : [
38+
"/node_modules",
39+
"/dist"
3640
]
3741
};

package-lock.json

Lines changed: 1015 additions & 1162 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@adyen/api-library",
3-
"version": "2.1.8",
4-
"description": "The Adyen API Library for NodeJS enables you to work with Adyen APIs and Hosted Payment Pages.",
3+
"version": "2.2.0",
4+
"description": "The Adyen API Library for NodeJS enables you to work with Adyen APIs.",
55
"main": "dist/lib/src/index.js",
66
"types": "dist/lib/src/index.d.ts",
77
"module": "dist/lib-esm/src/index.js",
@@ -38,32 +38,32 @@
3838
"author": "Ricardo Ambrogi",
3939
"license": "MIT",
4040
"devDependencies": {
41-
"@babel/core": "7.7.2",
42-
"@babel/plugin-proposal-class-properties": "7.7.0",
43-
"@babel/plugin-proposal-object-rest-spread": "7.6.2",
44-
"@babel/plugin-transform-runtime": "7.6.2",
45-
"@babel/plugin-transform-typescript": "^7.7.2",
46-
"@babel/preset-env": "7.7.1",
47-
"@babel/preset-typescript": "^7.7.2",
48-
"@babel/runtime": "7.7.2",
49-
"@types/jest": "^24.0.23",
41+
"@babel/core": "7.7.7",
42+
"@babel/plugin-proposal-class-properties": "7.7.4",
43+
"@babel/plugin-proposal-object-rest-spread": "7.7.7",
44+
"@babel/plugin-transform-runtime": "7.7.6",
45+
"@babel/plugin-transform-typescript": "7.7.4",
46+
"@babel/preset-env": "7.7.7",
47+
"@babel/preset-typescript": "7.7.7",
48+
"@babel/runtime": "7.7.7",
49+
"@types/jest": "24.0.25",
5050
"@types/nock": "10.0.3",
51-
"@types/node": "11.15.2",
52-
"@typescript-eslint/eslint-plugin": "2.8.0",
53-
"@typescript-eslint/parser": "2.8.0",
51+
"@types/node": "13.1.4",
52+
"@typescript-eslint/eslint-plugin": "2.15.0",
53+
"@typescript-eslint/parser": "2.15.0",
5454
"babel-loader": "8.0.6",
55-
"coveralls": "3.0.8",
56-
"eslint": "6.6.0",
55+
"coveralls": "3.0.9",
56+
"eslint": "6.8.0",
5757
"jest": "24.9.0",
58-
"nock": "11.7.0",
58+
"nock": "11.7.1",
5959
"release-it": "12.4.3",
60-
"ts-jest": "^24.1.0",
60+
"ts-jest": "24.3.0",
6161
"ts-loader": "6.2.1",
62-
"typescript": "3.7.2",
63-
"webpack": "4.41.2",
62+
"typescript": "3.7.4",
63+
"webpack": "4.41.5",
6464
"webpack-cli": "3.3.10"
6565
},
6666
"dependencies": {
67-
"https-proxy-agent": "3.0.1"
67+
"https-proxy-agent": "4.0.0"
6868
}
6969
}

src/__tests__/binLookup.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import nock from "nock";
2222
import {createMockClientFromResponse} from "../__mocks__/base";
2323
import BinLookup from "../services/binLookup";
24-
import {CostEstimateRequest, ThreeDSAvailabilityRequest} from "../typings/binLookup";
2524
import Client from "../client";
2625
import HttpClientException from "../httpClient/httpClientException";
2726

@@ -54,7 +53,7 @@ beforeEach((): void => {
5453

5554
describe("Bin Lookup", function (): void {
5655
it("should succeed on get 3ds availability", async function (): Promise<void> {
57-
const threeDSAvailabilityRequest: ThreeDSAvailabilityRequest = {
56+
const threeDSAvailabilityRequest: IBinLookup.ThreeDSAvailabilityRequest = {
5857
merchantAccount: "MOCK_MERCHANT_ACCOUNT",
5958
brands: ["randomBrand"],
6059
cardNumber: "4111111111111111"
@@ -79,7 +78,7 @@ describe("Bin Lookup", function (): void {
7978
.reply(403, JSON.stringify({status: 403, message: "fail", errorCode: "171"}));
8079

8180
try {
82-
await binLookup.get3dsAvailability(threeDSAvailabilityRequest as unknown as ThreeDSAvailabilityRequest);
81+
await binLookup.get3dsAvailability(threeDSAvailabilityRequest as unknown as IBinLookup.ThreeDSAvailabilityRequest);
8382
fail("Expected request to fail");
8483
} catch (e) {
8584
expect(e instanceof HttpClientException).toBeTruthy();
@@ -92,7 +91,7 @@ describe("Bin Lookup", function (): void {
9291
resultCode: "Unsupported",
9392
surchargeType: "ZERO"
9493
};
95-
const costEstimateRequest: CostEstimateRequest = {
94+
const costEstimateRequest: IBinLookup.CostEstimateRequest = {
9695
amount: { currency: "EUR", value: 1000 },
9796
assumptions: {
9897
assumeLevel3Data: true,
@@ -105,7 +104,7 @@ describe("Bin Lookup", function (): void {
105104
mcc: "7411",
106105
enrolledIn3DSecure: true
107106
},
108-
shopperInteraction: CostEstimateRequest.ShopperInteractionEnum.Ecommerce
107+
shopperInteraction: "Ecommerce"
109108
};
110109

111110
scope.post("/getCostEstimate")

src/__tests__/checkout.spec.ts

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,20 @@ import {paymentSessionSuccess} from "../__mocks__/checkout/paymentSessionSucess"
2828
import {paymentsResultMultibancoSuccess} from "../__mocks__/checkout/paymentsResultMultibancoSuccess";
2929
import {paymentsResultSuccess} from "../__mocks__/checkout/paymentsResultSucess";
3030
import Client from "../client";
31-
import { TYPE_SCHEME } from "../typings/constants/apiConstants";
3231
import Checkout from "../services/checkout";
33-
import {
34-
Amount,
35-
DetailsRequest,
36-
PaymentMethodsRequest,
37-
PaymentRequest,
38-
PaymentResponse,
39-
PaymentSetupRequest, PaymentVerificationRequest
40-
} from "../typings/checkout";
4132
import HttpClientException from "../httpClient/httpClientException";
4233

43-
function createAmountObject(currency: string, value: number): Amount {
34+
const merchantAccount = "MagentoMerchantTest";
35+
const reference = "Your order number";
36+
37+
function createAmountObject(currency: string, value: number): ICheckout.Amount {
4438
return {
4539
currency,
4640
value,
4741
};
4842
}
4943

50-
function createPaymentsDetailsRequest(): DetailsRequest {
44+
function createPaymentsDetailsRequest(): ICheckout.DetailsRequest {
5145
return {
5246
details: {
5347
MD: "mdValue",
@@ -57,31 +51,31 @@ function createPaymentsDetailsRequest(): DetailsRequest {
5751
};
5852
}
5953

60-
export function createPaymentsCheckoutRequest(): PaymentRequest {
54+
export function createPaymentsCheckoutRequest(): ICheckout.PaymentRequest {
6155
const paymentMethodDetails = {
6256
cvc: "737",
6357
expiryMonth: "10",
6458
expiryYear: "2018",
6559
holderName: "John Smith",
6660
number: "4111111111111111",
67-
type: TYPE_SCHEME,
61+
type: "scheme",
6862
};
6963

7064
return {
7165
amount: createAmountObject("USD", 1000),
72-
merchantAccount: "MagentoMerchantTest",
66+
merchantAccount,
7367
paymentMethod: paymentMethodDetails,
74-
reference: "Your order number",
68+
reference,
7569
returnUrl: "https://your-company.com/...",
7670
};
7771
}
7872

79-
function createPaymentSessionRequest(): PaymentSetupRequest {
73+
function createPaymentSessionRequest(): ICheckout.PaymentSetupRequest {
8074
return {
8175
amount: createAmountObject("USD", 1000),
8276
countryCode: "NL",
83-
merchantAccount: "MagentoMerchantTest",
84-
reference: "Your order number",
77+
merchantAccount,
78+
reference,
8579
returnUrl: "https://your-company.com/...",
8680
};
8781
}
@@ -101,8 +95,8 @@ describe("Checkout", (): void => {
10195
scope.post("/payments")
10296
.reply(200, paymentsSuccess);
10397

104-
const paymentsRequest: PaymentRequest = createPaymentsCheckoutRequest();
105-
const paymentsResponse: PaymentResponse = await checkout.payments(paymentsRequest);
98+
const paymentsRequest: ICheckout.PaymentRequest = createPaymentsCheckoutRequest();
99+
const paymentsResponse: ICheckout.PaymentResponse = await checkout.payments(paymentsRequest);
106100
expect(paymentsResponse.pspReference).toEqual("8535296650153317");
107101
});
108102

@@ -111,15 +105,15 @@ describe("Checkout", (): void => {
111105
scope.post("/payments")
112106
.reply(401);
113107

114-
const paymentsRequest: PaymentRequest = createPaymentsCheckoutRequest();
108+
const paymentsRequest: ICheckout.PaymentRequest = createPaymentsCheckoutRequest();
115109
await checkout.payments(paymentsRequest);
116110
} catch (e) {
117111
expect(e instanceof HttpClientException).toBeTruthy();
118112
}
119113
});
120114

121115
it("should have valid payment methods", async (): Promise<void> => {
122-
const paymentMethodsRequest: PaymentMethodsRequest = {merchantAccount: "MagentoMerchantTest"};
116+
const paymentMethodsRequest: ICheckout.PaymentMethodsRequest = {merchantAccount: "MagentoMerchantTest"};
123117

124118
scope.post("/paymentMethods")
125119
.reply(200, paymentMethodsSuccess);
@@ -133,6 +127,50 @@ describe("Checkout", (): void => {
133127
}
134128
});
135129

130+
it("should have valid payment link", async (): Promise<void> => {
131+
const amount = createAmountObject("BRL", 1000);
132+
const expiresAt = "2019-12-17T10:05:29Z";
133+
const paymentLinkRequest: ICheckout.CreatePaymentLinkRequest = {
134+
allowedPaymentMethods: ["scheme", "boletobancario"],
135+
amount,
136+
countryCode: "BR",
137+
merchantAccount,
138+
shopperReference: "shopperReference",
139+
shopperEmail: "test@email.com",
140+
shopperLocale: "pt_BR",
141+
billingAddress: {
142+
street: "Roque Petroni Jr",
143+
postalCode: "59000060",
144+
city: "São Paulo",
145+
houseNumberOrName: "999",
146+
country: "BR",
147+
stateOrProvince: "SP"
148+
},
149+
deliveryAddress: {
150+
street: "Roque Petroni Jr",
151+
postalCode: "59000060",
152+
city: "São Paulo",
153+
houseNumberOrName: "999",
154+
country: "BR",
155+
stateOrProvince: "SP"
156+
},
157+
expiresAt,
158+
reference
159+
};
160+
161+
const paymentLinkSuccess: ICheckout.CreatePaymentLinkResponse = {
162+
amount,
163+
expiresAt,
164+
reference,
165+
url: "paymentLinkResponse.url"
166+
};
167+
168+
scope.post("/paymentLinks").reply(200, paymentLinkSuccess);
169+
170+
const paymentSuccessLinkResponse = await checkout.paymentLinks(paymentLinkRequest);
171+
expect(paymentLinkSuccess).toEqual(paymentSuccessLinkResponse);
172+
});
173+
136174
it("should have payment details", async (): Promise<void> => {
137175
scope.post("/payments/details")
138176
.reply(200, paymentDetailsSuccess);
@@ -146,7 +184,7 @@ describe("Checkout", (): void => {
146184
scope.post("/paymentSession")
147185
.reply(200, paymentSessionSuccess);
148186
const checkout: Checkout = new Checkout(client);
149-
const paymentSessionRequest: PaymentSetupRequest = createPaymentSessionRequest();
187+
const paymentSessionRequest: ICheckout.PaymentSetupRequest = createPaymentSessionRequest();
150188
const paymentSessionResponse = await checkout.paymentSession(paymentSessionRequest);
151189
expect(paymentSessionResponse.paymentSession).not.toBeUndefined();
152190
});
@@ -156,7 +194,7 @@ describe("Checkout", (): void => {
156194
scope.post("/payments/result")
157195
.reply(200, paymentsResultSuccess);
158196
const checkout = new Checkout(client);
159-
const paymentResultRequest: PaymentVerificationRequest = {
197+
const paymentResultRequest: ICheckout.PaymentVerificationRequest = {
160198
payload: "This is a test payload",
161199
};
162200
const paymentResultResponse = await checkout.paymentResult(paymentResultRequest);
@@ -180,8 +218,8 @@ describe("Checkout", (): void => {
180218
.reply(200, paymentsResultMultibancoSuccess);
181219

182220
const checkout: Checkout = new Checkout(client);
183-
const paymentsRequest: PaymentRequest = createPaymentsCheckoutRequest();
184-
const paymentsResponse: PaymentResponse = await checkout.payments(paymentsRequest);
221+
const paymentsRequest: ICheckout.PaymentRequest = createPaymentsCheckoutRequest();
222+
const paymentsResponse: ICheckout.PaymentResponse = await checkout.payments(paymentsRequest);
185223
expect(paymentsResponse.pspReference).toEqual("8111111111111111");
186224

187225
if (paymentsResponse.additionalData) {

src/__tests__/checkoutUtility.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ import nock from "nock";
2323
import { createMockClientFromResponse } from "../__mocks__/base";
2424
import {originKeysSuccess} from "../__mocks__/checkoutUtility/originkeysSuccess";
2525
import CheckoutUtility from "../services/checkoutUtility";
26-
import {CheckoutUtilityRequest} from "../typings/checkoutUtility";
2726
import Client from "../client";
2827

2928
describe("Checkout Utility", (): void => {
3029
it("should get origin keys", async (): Promise<void> => {
3130
const client = createMockClientFromResponse();
3231
const checkoutUtility = new CheckoutUtility(client);
33-
const originKeysRequest: CheckoutUtilityRequest = {
32+
const originKeysRequest: ICheckoutUtility.CheckoutUtilityRequest = {
3433
originDomains: ["www.test.com", "https://www.your-domain2.com"],
3534
};
3635

@@ -39,7 +38,10 @@ describe("Checkout Utility", (): void => {
3938
.reply(200, originKeysSuccess);
4039

4140
const originKeysResponse = await checkoutUtility.originKeys(originKeysRequest);
42-
expect(originKeysResponse.originKeys["https://www.your-domain1.com"])
43-
.toEqual("pub.v2.7814286629520534.aHR0cHM6Ly93d3cueW91ci1kb21haW4xLmNvbQ.UEwIBmW9-c_uXo5wSEr2w8Hz8hVIpujXPHjpcEse3xI");
41+
if (originKeysResponse.originKeys) {
42+
return expect(originKeysResponse.originKeys["https://www.your-domain1.com"])
43+
.toEqual("pub.v2.7814286629520534.aHR0cHM6Ly93d3cueW91ci1kb21haW4xLmNvbQ.UEwIBmW9-c_uXo5wSEr2w8Hz8hVIpujXPHjpcEse3xI");
44+
}
45+
fail("Error: originKeysResponse.originKeys is empty");
4446
});
4547
});

src/__tests__/hmacValidator.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import HmacValidator from "../utils/hmacValidator";
22
import {NotificationRequestItem} from "../typings/notification";
3-
import {HMAC_SIGNATURE} from "../typings/constants/apiConstants";
3+
import {ApiConstants} from "../constants/apiConstants";
44

55
const key = "DFB1EB5485895CFA84146406857104ABB4CBCABDC8AAF103A624C8F6A3EAAB00";
66
const expectedSign = "ipnxGCaUZ4l8TUW75a71/ghd2Fe5ffvX0pV4TLTntIc=";
@@ -15,7 +15,7 @@ const notificationRequestItem: NotificationRequestItem = {
1515
paymentMethod: "VISA",
1616
reason: "reason",
1717
success: "true",
18-
additionalData: { [HMAC_SIGNATURE]: expectedSign },
18+
additionalData: { [ApiConstants.HMAC_SIGNATURE]: expectedSign },
1919
};
2020

2121
describe("HMAC Validator", function (): void {
@@ -52,7 +52,7 @@ describe("HMAC Validator", function (): void {
5252
it("should have invalid hmac", function (): void {
5353
const invalidNotification = {
5454
...notificationRequestItem,
55-
additionalData: { [HMAC_SIGNATURE]: "notValidSign" }
55+
additionalData: { [ApiConstants.HMAC_SIGNATURE]: "notValidSign" }
5656
};
5757
const hmacValidator = new HmacValidator();
5858
const result = hmacValidator.validateHMAC(invalidNotification, key);

src/__tests__/httpClient.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Checkout from "../services/checkout";
44
import ApiException from "../services/exception/apiException";
55
import {createPaymentsCheckoutRequest} from "./checkout.spec";
66
import HttpClientException from "../httpClient/httpClientException";
7-
import {Environment} from "../typings/enums/environment";
87

98
beforeEach((): void => {
109
nock.cleanAll();

0 commit comments

Comments
 (0)