Skip to content

Commit 39827c3

Browse files
authored
Merge pull request #1567 from Adyen/export-enums
Export EnvironmentEnum and RegionEnum
2 parents e629f8d + ffd95cf commit 39827c3

File tree

9 files changed

+275
-242
lines changed

9 files changed

+275
-242
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ Alternatively, you can use the `Types` included in this module for Typescript an
254254
#### Deserializing JSON Strings
255255
In some setups you might need to deserialize JSON strings to request objects. For example, when using the libraries in combination with [Dropin/Components](https://github.com/Adyen/adyen-web). Please use the built-in deserialization functions:
256256
``` typescript
257-
// Import the required model class
258-
import { checkout } from "../typings";
257+
// Import the models
258+
import { Types } from "@adyen/api-library";
259259

260260
// Deserialize using built-in ObjectSerializer class
261261
const requestJson: JSON = JSON.parse(`YOUR_JSON_STRING`);
262-
const paymentRequest: checkout.PaymentRequest = await checkout.ObjectSerializer.deserialize(requestJson,"PaymentRequest");
262+
const paymentRequest: Types.checkout.PaymentRequest = await Types.checkout.ObjectSerializer.deserialize(requestJson,"PaymentRequest");
263263
```
264264

265265
### Custom HTTP client configuration
@@ -299,8 +299,11 @@ const client = new Client({
299299
### Parsing and Authenticating Banking Webhooks
300300
Parse an AccountHolderNotificationRequest webhook;
301301
``` typescript
302+
// import models
303+
import { Types, ConfigurationWebhooksHandler } from "@adyen/api-library";
304+
302305
const configurationWebhooksHandler = new ConfigurationWebhooksHandler(YOUR_BANKING_WEBHOOK);
303-
const accountHolderNotificationRequest: AccountHolderNotificationRequest = configurationWebhooksHandler.getAccountHolderNotificationRequest();
306+
const accountHolderNotificationRequest: Types.configurationWebhooks.AccountHolderNotificationRequest = configurationWebhooksHandler.getAccountHolderNotificationRequest();
304307
```
305308
You can also parse the webhook with a generic type, in case you do not know the webhook type in advance. In this case you can check the instance of the webhook in order to parse it to the respective type (or just use it dynamically);
306309
``` typescript
@@ -331,7 +334,7 @@ To configure a proxy connection, set the `proxy` property of your `HttpURLConnec
331334
For example:
332335

333336
``` javascript
334-
const {HttpURLConnectionClient, Client, Config} = require('@adyen/api-library');
337+
const {HttpURLConnectionClient, Client, Config, EnvironmentEnum} = require('@adyen/api-library');
335338
// ... more code
336339
const client = new Client({apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST});
337340
const httpClient = new HttpURLConnectionClient();
@@ -494,7 +497,7 @@ const paymentRequest: SaleToPOIRequest = {
494497
}
495498

496499
// Step 6: Make the request
497-
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest, securityKey);
500+
const terminalApiResponse: Types.terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest, securityKey);
498501
```
499502
## Using the Local Terminal API Integration without Encryption (Only on TEST)
500503
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.
@@ -517,15 +520,15 @@ const paymentRequest: SaleToPOIRequest = {
517520
}
518521

519522
// Step 5: Make the request
520-
const terminalApiResponse: terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest);
523+
const terminalApiResponse: Types.terminal.TerminalApiResponse = await terminalLocalAPI.request(paymentRequest);
521524
```
522525
### Using the Cloud Terminal API Integration (async)
523526
If you choose to integrate [Terminal API over Cloud](https://docs.adyen.com/point-of-sale/design-your-integration/choose-your-architecture/cloud/) **asynchronously**, you need to follow similar steps to initialize the client and prepare the request object. However the response will be asynchronous:
524527
* a successful request will return `200` status code and `ok` as response body. Make sure to setup the [event notifications](https://docs.adyen.com/point-of-sale/design-your-integration/notifications/event-notifications/)
525528
* a request that fails will return `200` status code and the `TerminalApiResponse` as response body
526529
``` typescript
527530
// Step 1: Require the parts of the module you want to use
528-
const {Client, TerminalCloudAPI} from "@adyen/api-library";
531+
const {Client, TerminalCloudAPI, EnvironmentEnum} from "@adyen/api-library";
529532

530533
// Step 2: Initialize the client object
531534
const client = new Client({apiKey: "YOUR_API_KEY", environment: EnvironmentEnum.TEST});

src/__tests__/balanceControl.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import nock from "nock";
22
import { createClient } from "../__mocks__/base";
33
import { BalanceControlAPI } from "../services";
44
import Client from "../client";
5-
import { BalanceTransferRequest } from "../typings/balanceControl/balanceTransferRequest";
6-
import { BalanceTransferResponse } from "../typings/balanceControl/balanceTransferResponse";
5+
import { Types } from "..";
76
import HttpClientException from "../httpClient/httpClientException";
87

98
let client: Client,
@@ -39,13 +38,13 @@ describe("Balance Control", (): void => {
3938
"pspReference": "8816080397613514",
4039
"status": "transferred"
4140
};
42-
const request: BalanceTransferRequest = new BalanceTransferRequest;
41+
const request = new Types.balanceControl.BalanceTransferRequest();
4342

4443
scope.post("/balanceTransfer")
4544
.reply(200, expected);
4645

47-
const response: BalanceTransferResponse = await balanceService.BalanceControlApi.balanceTransfer(request);
48-
expect(response.status).toEqual(BalanceTransferResponse.StatusEnum.Transferred);
46+
const response: Types.balanceControl.BalanceTransferResponse = await balanceService.BalanceControlApi.balanceTransfer(request);
47+
expect(response.status).toEqual(Types.balanceControl.BalanceTransferResponse.StatusEnum.Transferred);
4948
});
5049

5150
test("Should return correct Validation error", async (): Promise<void> => {
@@ -55,7 +54,7 @@ describe("Balance Control", (): void => {
5554
"message": "Merchant account code is invalid or missing",
5655
"errorType": "validation"
5756
};
58-
const request: BalanceTransferRequest = new BalanceTransferRequest;
57+
const request = new Types.balanceControl.BalanceTransferRequest();
5958

6059
try {
6160
scope.post("/balanceTransfer")

0 commit comments

Comments
 (0)