Skip to content

Commit e23bd0b

Browse files
Add Support For Local Unencrypted TAPI (#1244)
* add support for local unencrypted tapi and test with terminal * Update README.md Co-authored-by: Michael Paul <michael.paul@adyen.com> --------- Co-authored-by: Michael Paul <michael.paul@adyen.com>
1 parent e67afe6 commit e23bd0b

File tree

3 files changed

+81
-7
lines changed

3 files changed

+81
-7
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,30 @@ const paymentRequest: SaleToPOIRequest = {
456456
// Step 6: Make the request
457457
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest, securityKey);
458458
```
459+
## Using the Local Terminal API Integration without Encryption (Only on TEST)
460+
If you wish to develop the Local Terminal API integration parallel to your encryption implementation, you can opt for the unencrypted version. Be sure to remove any encryption details from the CA terminal config page.
461+
```javascript
462+
// Step 1: Require the parts of the module you want to use
463+
const {Client, TerminalLocalAPIUnencrypted} from "@adyen/api-library";
464+
465+
// Step 2: Add your Merchant Account, Certificate Path and Local Endpoint to the config path. Install the certificate and save it in your project folder as "cert.cer"
466+
const config: Config = new Config();
467+
config.merchantAccount = "Your merchant account";
468+
config.terminalApiLocalEndpoint = "The IP of your terminal (eg https://192.168.47.169)";
469+
config.apiKey = "YOUR_API_KEY_HERE";
459470

471+
// Step 3 Initialize the client and the API objects
472+
client = new Client({ config });
473+
const terminalLocalAPI = new TerminalLocalAPIUnencrypted(client);
474+
475+
// Step 4: Create the request object
476+
const paymentRequest: SaleToPOIRequest = {
477+
// Similar to the saleToPOIRequest used for Cloud API
478+
}
460479

480+
// Step 5: Make the request
481+
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest);
482+
```
461483
## Feedback
462484
We value your input! Help us enhance our API Libraries and improve the integration experience by providing your feedback. Please take a moment to fill out [our feedback form](https://forms.gle/A4EERrR6CWgKWe5r9) to share your thoughts, suggestions or ideas.
463485

src/httpClient/httpURLConnectionClient.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ import { URL, URLSearchParams } from "url";
2626
import Client from "../client";
2727
import Config from "../config";
2828
import HttpClientException from "./httpClientException";
29-
import checkServerIdentity from "../helpers/checkServerIdentity";
29+
3030
import { ApiError } from "../typings/apiError";
3131
import ApiException from "../services/exception/apiException";
3232
import ClientInterface from "./clientInterface";
3333
import { ApiConstants } from "../constants/apiConstants";
3434
import { IRequest } from "../typings/requestOptions";
35+
import checkServerIdentity from "../helpers/checkServerIdentity";
3536

3637
class HttpURLConnectionClient implements ClientInterface {
3738
private static CHARSET = "utf-8";
@@ -194,12 +195,17 @@ class HttpURLConnectionClient implements ClientInterface {
194195

195196
private installCertificateVerifier(terminalCertificatePath: string): void | Promise<HttpClientException> {
196197
try {
197-
const certificateInput = fs.readFileSync(terminalCertificatePath);
198-
199-
this.agentOptions = {
200-
ca: certificateInput,
201-
checkServerIdentity,
202-
};
198+
if (terminalCertificatePath == "unencrypted"){
199+
this.agentOptions = {
200+
rejectUnauthorized: false
201+
}
202+
} else {
203+
const certificateInput = fs.readFileSync(terminalCertificatePath);
204+
this.agentOptions = {
205+
ca: certificateInput,
206+
checkServerIdentity,
207+
};
208+
}
203209

204210
} catch (e) {
205211
const message = e instanceof Error ? e.message: "undefined";
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Service from "../service";
2+
import Client from "../client";
3+
import getJsonResponse from "../helpers/getJsonResponse";
4+
import LocalRequest from "./resource/terminal/local/localRequest";
5+
import {
6+
ObjectSerializer,
7+
TerminalApiRequest,
8+
TerminalApiResponse,
9+
} from "../typings/terminal/models";
10+
11+
class TerminalLocalAPIUnencrypted extends Service {
12+
private readonly localRequest: LocalRequest;
13+
14+
/**
15+
* @summary This is the unencrypted local terminal API (only works in TEST).
16+
* Use this for testing your local integration parallel to the encryption setup.
17+
* Be sure to remove all encryption details in your CA terminal config page.
18+
* @param client {@link Client }
19+
*/
20+
public constructor(client: Client) {
21+
super(client);
22+
this.apiKeyRequired = true;
23+
this.localRequest = new LocalRequest(this);
24+
client.config.certificatePath = "unencrypted";
25+
}
26+
27+
public async request(
28+
terminalApiRequest: TerminalApiRequest
29+
): Promise<TerminalApiResponse> {
30+
const request = ObjectSerializer.serialize(terminalApiRequest, "TerminalApiRequest");
31+
32+
const jsonResponse = await getJsonResponse<TerminalApiRequest, TerminalApiResponse>(
33+
this.localRequest,
34+
request
35+
);
36+
37+
// Catch an empty jsonResponse (i.e. Abort Request)
38+
if(!jsonResponse) {
39+
return new TerminalApiResponse();
40+
} else {
41+
return ObjectSerializer.deserialize(jsonResponse, "TerminalApiResponse");
42+
}
43+
}
44+
}
45+
46+
export default TerminalLocalAPIUnencrypted;

0 commit comments

Comments
 (0)