Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support For Local Unencrypted TAPI #1244

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,30 @@ const paymentRequest: SaleToPOIRequest = {
// Step 6: Make the request
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest, securityKey);
```
## Using the Local Terminal API Integration without Encryption (Only on TEST)
In case you would like to develop the Local Terminal API integration parallel to you encryption implementation, you can opt for the unencrypted version. Be sure to remove any encryption details from the CA terminal config page.
jillingk marked this conversation as resolved.
Show resolved Hide resolved
```javascript
// Step 1: Require the parts of the module you want to use
const {Client, TerminalLocalAPIUnencrypted} from "@adyen/api-library";

// 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"
const config: Config = new Config();
config.merchantAccount = "Your merchant account";
config.terminalApiLocalEndpoint = "The IP of your terminal (eg https://192.168.47.169)";
config.apiKey = "YOUR_API_KEY_HERE";

// Step 3 Initialize the client and the API objects
client = new Client({ config });
const terminalLocalAPI = new TerminalLocalAPIUnencrypted(client);

// Step 4: Create the request object
const paymentRequest: SaleToPOIRequest = {
// Similar to the saleToPOIRequest used for Cloud API
}

// Step 5: Make the request
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest);
```
## Feedback
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.

Expand Down
20 changes: 13 additions & 7 deletions src/httpClient/httpURLConnectionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import { URL, URLSearchParams } from "url";
import Client from "../client";
import Config from "../config";
import HttpClientException from "./httpClientException";
import checkServerIdentity from "../helpers/checkServerIdentity";

import { ApiError } from "../typings/apiError";
import ApiException from "../services/exception/apiException";
import ClientInterface from "./clientInterface";
import { ApiConstants } from "../constants/apiConstants";
import { IRequest } from "../typings/requestOptions";
import checkServerIdentity from "../helpers/checkServerIdentity";

class HttpURLConnectionClient implements ClientInterface {
private static CHARSET = "utf-8";
Expand Down Expand Up @@ -194,12 +195,17 @@ class HttpURLConnectionClient implements ClientInterface {

private installCertificateVerifier(terminalCertificatePath: string): void | Promise<HttpClientException> {
try {
const certificateInput = fs.readFileSync(terminalCertificatePath);

this.agentOptions = {
ca: certificateInput,
checkServerIdentity,
};
if (terminalCertificatePath == "unencrypted"){
this.agentOptions = {
rejectUnauthorized: false

Check failure

Code scanning / CodeQL

Disabling certificate validation

Disabling certificate validation is strongly discouraged.
}
} else {
const certificateInput = fs.readFileSync(terminalCertificatePath);
this.agentOptions = {
ca: certificateInput,
checkServerIdentity,
};
}

} catch (e) {
const message = e instanceof Error ? e.message: "undefined";
Expand Down
46 changes: 46 additions & 0 deletions src/services/terminalLocalAPIUnencrypted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Service from "../service";
import Client from "../client";
import getJsonResponse from "../helpers/getJsonResponse";
import LocalRequest from "./resource/terminal/local/localRequest";
import {
ObjectSerializer,
TerminalApiRequest,
TerminalApiResponse,
} from "../typings/terminal/models";

class TerminalLocalAPIUnencrypted extends Service {
private readonly localRequest: LocalRequest;

/**
* @summary This is the unencrypted local terminal API (only works in TEST).
* Use this for testing your local integration parallel to the encryption setup.
* Be sure to remove all encryption details in your CA terminal config page.
* @param client {@link Client }
*/
public constructor(client: Client) {
super(client);
this.apiKeyRequired = true;
this.localRequest = new LocalRequest(this);
client.config.certificatePath = "unencrypted";
}

public async request(
terminalApiRequest: TerminalApiRequest
): Promise<TerminalApiResponse> {
const request = ObjectSerializer.serialize(terminalApiRequest, "TerminalApiRequest");

const jsonResponse = await getJsonResponse<TerminalApiRequest, TerminalApiResponse>(
this.localRequest,
request
);

// Catch an empty jsonResponse (i.e. Abort Request)
if(!jsonResponse) {
return new TerminalApiResponse();
} else {
return ObjectSerializer.deserialize(jsonResponse, "TerminalApiResponse");
}
}
}

export default TerminalLocalAPIUnencrypted;