Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 2bb6312

Browse files
IngenicoEPaymentsjenkins
authored andcommitted
Release 4.0.0.
1 parent 1ad80cf commit 2bb6312

File tree

259 files changed

+8044
-2588
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

+8044
-2588
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.md]
11+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
/docs
3+
/lib
4+
/schemas

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
node_modules
2+
/lib
3+
/docs
24
logfile.txt
35
.vscode
46
.idea
7+
8+
# For testing
9+
__tests__/config.json
10+
junit*.xml

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
/docs
3+
/lib
4+
/schemas

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ See the [Ingenico ePayments Developer Hub](https://epayments.developer-ingenico.
1414

1515
## Structure of this repository
1616

17-
This repository consists out of one main component:
17+
This repository consists out of three main components:
1818

19-
1. The source code of the SDK itself: `/`
19+
1. The source code of the SDK itself: `/src`
20+
2. The JSON schemas used to validate requests: `/schemas`
21+
3. Unit and integration tests: `/__tests__`
2022

2123
## Requirements
2224

@@ -30,6 +32,28 @@ From the folder where your `package.json` is located, run the following command
3032

3133
## Building the repository
3234

33-
From the root of the project install all dependencies:
35+
From the root of the project install all dependencies, then compile the code:
3436

3537
npm install
38+
npm run build
39+
40+
## Testing
41+
42+
There are two types of tests:
43+
44+
1. Unit tests. These will work out-of-the-box.
45+
Run these tests as follows:
46+
47+
```
48+
npm run test:unit
49+
```
50+
2. Integration tests. Before you can run these, you first need to copy file `__tests__/config.json.dist` to `__tests__/config.json` and replace all values as needed.
51+
Run these tests as follows:
52+
53+
```
54+
npm run test:integration
55+
```
56+
57+
You can also run both types of tests together as follows:
58+
59+
npm run test

__tests__/config.json.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"merchantId": "MERCHANT_ID",
3+
"apiKeyId": "API_KEY_ID",
4+
"secretApiKey": "API_SECRET",
5+
"apiEndpoint": {
6+
"host": "API_ENDPOINT_HOST",
7+
"scheme": "https",
8+
"port": 443
9+
},
10+
"integrator": "INTEGRATOR",
11+
"enableLogging": false
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2+
3+
import { ConvertAmount } from "../../src/model/domain/services";
4+
import connectSdk, { config } from "./init";
5+
6+
/**
7+
* @group integration
8+
*/
9+
describe("convertAmount", () => {
10+
test("called successfully", done => {
11+
const query = {
12+
source: "EUR",
13+
target: "USD",
14+
amount: 100
15+
};
16+
17+
connectSdk.services.convertAmount(config.merchantId, query, (error, response) => {
18+
expect(error).toBeNull();
19+
20+
expect(response).not.toBeNull();
21+
expect(response!.status).toBe(200);
22+
expect(response!.body).not.toBeNull();
23+
24+
const responseBody = response!.body as ConvertAmount;
25+
expect(responseBody.convertedAmount).not.toBeNull();
26+
27+
done();
28+
});
29+
});
30+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2+
3+
import * as uuid from "uuid";
4+
import { CreatePaymentResponse } from "../../src/model/domain/payment";
5+
import connectSdk, { config } from "./init";
6+
7+
/**
8+
* @group integration
9+
*/
10+
describe("Idempotence", () => {
11+
test("causes second request to be idempotent", done => {
12+
const body = {
13+
order: {
14+
amountOfMoney: {
15+
currencyCode: "EUR",
16+
amount: 100
17+
},
18+
customer: {
19+
locale: "en_GB",
20+
billingAddress: {
21+
countryCode: "NL"
22+
}
23+
}
24+
},
25+
redirectPaymentMethodSpecificInput: {
26+
returnUrl: "http://example.com/",
27+
paymentProductId: 809,
28+
paymentProduct809SpecificInput: {
29+
issuerId: "INGBNL2A"
30+
}
31+
}
32+
};
33+
34+
const idemPotenceKey = uuid.v4();
35+
const paymentContext = {
36+
idemPotence: {
37+
key: idemPotenceKey
38+
}
39+
};
40+
41+
connectSdk.payments.create(config.merchantId, body, paymentContext, (error, response) => {
42+
expect(error).toBeNull();
43+
44+
expect(response).not.toBeNull();
45+
expect(response!.status).toBe(201);
46+
expect(response!.body).not.toBe(null);
47+
48+
const responseBody = response!.body as CreatePaymentResponse;
49+
expect(responseBody.payment).not.toBe(null);
50+
expect(responseBody.payment!.id).not.toBe(null);
51+
expect(paymentContext.idemPotence.key).toBe(idemPotenceKey);
52+
expect(connectSdk.context.getIdempotenceRequestTimestamp()).toBeUndefined();
53+
54+
connectSdk.payments.create(config.merchantId, body, paymentContext, (error2, response2) => {
55+
expect(error2).toBeNull();
56+
57+
expect(response2).not.toBeNull();
58+
expect(response2!.status).toBe(201);
59+
expect(response2!.body).not.toBe(null);
60+
61+
const responseBody2 = response2!.body as CreatePaymentResponse;
62+
expect(responseBody2.payment).not.toBe(null);
63+
expect(responseBody2.payment!.id).toBe(responseBody.payment!.id);
64+
expect(paymentContext.idemPotence.key).toBe(idemPotenceKey);
65+
expect(connectSdk.context.getIdempotenceRequestTimestamp()).not.toBeUndefined();
66+
expect(connectSdk.context.getIdempotenceRequestTimestamp()).not.toBeNull();
67+
68+
done();
69+
});
70+
});
71+
});
72+
});

__tests__/integration/init.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as connectSdk from "../../src";
2+
3+
// eslint-disable-next-line @typescript-eslint/no-var-requires
4+
export const config = require("../config.json");
5+
6+
jest.setTimeout(60 * 1000);
7+
8+
connectSdk.init({
9+
host: config.apiEndpoint.host,
10+
scheme: config.apiEndpoint.scheme,
11+
port: config.apiEndpoint.port,
12+
enableLogging: config.enableLogging, // defaults to false
13+
apiKeyId: config.apiKeyId,
14+
secretApiKey: config.secretApiKey,
15+
integrator: "Integration tests"
16+
});
17+
18+
export default connectSdk;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2+
3+
import { Readable } from "stream";
4+
import * as connectSdk from "../../src";
5+
import * as communicator from "../../src/utils/communicator";
6+
7+
// eslint-disable-next-line @typescript-eslint/no-var-requires
8+
const config = require("../config.json");
9+
10+
connectSdk.init({
11+
host: "httpbin.org",
12+
scheme: "http",
13+
port: 80,
14+
enableLogging: config.enableLogging, // defaults to false
15+
apiKeyId: config.apiKeyId,
16+
secretApiKey: config.secretApiKey,
17+
integrator: "Integration tests"
18+
});
19+
20+
jest.setTimeout(60 * 1000);
21+
22+
function toReadable(str: string): Readable {
23+
const result = new Readable();
24+
result.push(str);
25+
result.push(null);
26+
return result;
27+
}
28+
29+
interface HttpBinResponse {
30+
form: { [key: string]: string | undefined };
31+
files: { [key: string]: string | undefined };
32+
}
33+
34+
/**
35+
* @group integration
36+
*/
37+
describe("multipart", () => {
38+
test("POST", done => {
39+
const body = {
40+
value: "Hello World",
41+
file: {
42+
content: toReadable("This is the contents of a file"),
43+
fileName: "file.txt",
44+
contentType: "text/plain"
45+
}
46+
};
47+
48+
communicator.multipart({
49+
method: "POST",
50+
modulePath: "/post",
51+
body: body,
52+
paymentContext: null,
53+
cb: (error, response) => {
54+
expect(error).toBeNull();
55+
56+
expect(response).not.toBeNull();
57+
expect(response!.status).toBe(200);
58+
expect(response!.body).not.toBeNull();
59+
60+
const responseBody = response!.body as HttpBinResponse;
61+
expect(responseBody.files).not.toBeNull();
62+
expect(responseBody.files.file).toBe("This is the contents of a file");
63+
expect(responseBody.form).not.toBeNull();
64+
expect(responseBody.form.value).toBe("Hello World");
65+
66+
done();
67+
}
68+
});
69+
});
70+
71+
test("PUT", done => {
72+
const body = {
73+
value: "Hello World",
74+
file: {
75+
content: toReadable("This is the contents of a file"),
76+
fileName: "file.txt",
77+
contentType: "text/plain"
78+
}
79+
};
80+
81+
communicator.multipart({
82+
method: "PUT",
83+
modulePath: "/put",
84+
body: body,
85+
paymentContext: null,
86+
cb: (error, response) => {
87+
expect(error).toBeNull();
88+
89+
expect(response).not.toBeNull();
90+
expect(response!.status).toBe(200);
91+
expect(response!.body).not.toBeNull();
92+
93+
const responseBody = response!.body as HttpBinResponse;
94+
expect(responseBody.files).not.toBeNull();
95+
expect(responseBody.files.file).toBe("This is the contents of a file");
96+
expect(responseBody.form).not.toBeNull();
97+
expect(responseBody.form.value).toBe("Hello World");
98+
99+
done();
100+
}
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)