Skip to content

Commit

Permalink
PW-6668: POS Terminal Management API (#922)
Browse files Browse the repository at this point in the history
* PW-6668: Add resources

* PW-6668: Add models

* PW-6668: Add service

* PW-6668: Add unit tests

* PW-6668: Update readme

* PW-6668: Import models from models.ts

* PW-6668: Deserialize terminal management responses
  • Loading branch information
michaelpaul committed Aug 4, 2022
1 parent dd9eca1 commit 1b636e9
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The Library supports all APIs under the following services:
* [Local/Cloud-based Terminal API](https://docs.adyen.com/point-of-sale/terminal-api-reference): Our point-of-sale integration.
* [BIN lookup API](https://docs.adyen.com/api-explorer/#/BinLookup/v50/overview): The BIN Lookup API provides endpoints for retrieving information based on a given BIN. Current supported version: **v50**
* [Stored Value API](https://docs.adyen.com/payment-methods/gift-cards/stored-value-api): Manage both online and point-of-sale gift cards and other stored-value cards. Current supported version: **v46**
* [POS Terminal Management API](https://docs.adyen.com/api-explorer/#/postfmapi/v1/overview): Endpoints for managing your point-of-sale payment terminals **v1**

In addition it supports the following type collections:

Expand Down
1 change: 1 addition & 0 deletions src/__mocks__/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const createClient = (apiKey = process.env.ADYEN_API_KEY): Client => {
config.apiKey = apiKey;
config.paymentEndpoint = Client.PAYMENT_API_ENDPOINT_TEST;
config.storedValueEndpoint = Client.STOREDVALUE_API_ENDPOINT_TEST;
config.terminalManagementEndpoint = Client.TERMINAL_MANAGEMENT_API_ENDPOINT_TEST;
config.managementEndpoint = Client.MANAGEMENT_API_ENDPOINT_TEST;

return new Client({ config });
Expand Down
157 changes: 157 additions & 0 deletions src/__tests__/terminalManagement.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import nock from "nock";
import Client from "../client";
import { createClient } from "../__mocks__/base";
import TerminalManagement from "../services/terminalManagement";
import {
AssignTerminalsRequest,
AssignTerminalsResponse,
FindTerminalRequest,
FindTerminalResponse,
GetStoresUnderAccountRequest,
GetStoresUnderAccountResponse,
GetTerminalDetailsRequest,
GetTerminalDetailsResponse,
GetTerminalsUnderAccountRequest,
GetTerminalsUnderAccountResponse
} from "../typings/terminalManagement/models";

let client: Client;
let terminalManagement: TerminalManagement;
let scope: nock.Scope;

beforeEach((): void => {
if (!nock.isActive()) {
nock.activate();
}
client = createClient();
scope = nock(`${client.config.terminalManagementEndpoint}/${Client.TERMINAL_MANAGEMENT_API_VERSION}`);
terminalManagement = new TerminalManagement(client);
});

afterEach(() => {
nock.cleanAll();
});

describe("POS Terminal Management API", (): void => {
test("Should support /assignTerminals", async (): Promise<void> => {
scope.post("/assignTerminals")
.reply(200, {
"results": {
"P400Plus-275479597": "RemoveConfigScheduled"
}
});
const request: AssignTerminalsRequest = {
"companyAccount": "YOUR_COMPANY_ACCOUNT",
"terminals": [
"P400Plus-275479597"
]
};

const response: AssignTerminalsResponse = await terminalManagement.assignTerminals(request);

expect(response.results["P400Plus-275479597"]).toEqual("RemoveConfigScheduled");
});

test("Should support /findTerminal", async (): Promise<void> => {
scope.post("/findTerminal")
.reply(200, {
"companyAccount": "YOUR_COMPANY_ACCOUNT",
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
"merchantInventory": false,
"terminal": "P400Plus-275479597"
});
const request: FindTerminalRequest = {
"terminal": "P400Plus-275479597"
};

const response: FindTerminalResponse = await terminalManagement.findTerminal(request);

expect(response.terminal).toEqual("P400Plus-275479597");
});

test("Should support /getStoresUnderAccount", async (): Promise<void> => {
scope.post("/getStoresUnderAccount")
.reply(200, {
"stores": [
{
"store": "YOUR_STORE",
"description": "YOUR_STORE",
"address": {
"city": "The City",
"countryCode": "NL",
"postalCode": "1234",
"streetAddress": "The Street"
},
"status": "Active",
"merchantAccountCode": "YOUR_MERCHANT_ACCOUNT"
}
]
});
const request: GetStoresUnderAccountRequest = {
"companyAccount": "YOUR_COMPANY_ACCOUNT"
};

const response: GetStoresUnderAccountResponse = await terminalManagement.getStoresUnderAccount(request);

expect(response.stores).toHaveLength(1);
expect(response.stores![0].status).toEqual("Active");
expect(response.stores![0].address?.countryCode).toEqual("NL");
});

test("Should support /getTerminalDetails", async (): Promise<void> => {
scope.post("/getTerminalDetails")
.reply(200, {
"companyAccount": "YOUR_COMPANY_ACCOUNT",
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
"merchantInventory": false,
"terminal": "P400Plus-275479597",
"deviceModel": "P400Plus",
"serialNumber": "275-479-597",
"permanentTerminalId": "75479597",
"terminalStatus": "ReAssignToInventoryPending",
"firmwareVersion": "Verifone_VOS 1.57.6",
"country": "NETHERLANDS",
"dhcpEnabled": false
});
const request: GetTerminalDetailsRequest = {
"terminal": "P400Plus-275479597"
};

const response: GetTerminalDetailsResponse = await terminalManagement.getTerminalDetails(request);

expect(response.deviceModel).toBe("P400Plus");
});


test("Should support /getTerminalsUnderAccount", async (): Promise<void> => {
scope.post("/getTerminalsUnderAccount")
.reply(200, {
"companyAccount": "YOUR_COMPANY_ACCOUNT",
"merchantAccounts": [
{
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
"inStoreTerminals": [
"P400Plus-275479597"
],
"stores": [
{
"store": "YOUR_STORE",
"inStoreTerminals": [
"M400-401972715"
]
}
]
}
]
});
const request: GetTerminalsUnderAccountRequest = {
"companyAccount": "YOUR_COMPANY_ACCOUNT"
};

const response: GetTerminalsUnderAccountResponse = await terminalManagement.getTerminalsUnderAccount(request);

expect(response.merchantAccounts).toHaveLength(1);
expect(response.merchantAccounts![0].stores).toHaveLength(1);
expect(response.merchantAccounts![0].stores![0].inStoreTerminals).toEqual(["M400-401972715"]);
});
});
6 changes: 5 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Client {
public static MARKETPAY_NOTIFICATION_CONFIGURATION_API_VERSION = "v6";
public static PAYMENT_API_VERSION = "v68";
public static STOREDVALUE_API_VERSION = "v46";
public static TERMINAL_MANAGEMENT_API_VERSION = "v1";
public static MANAGEMENT_API_VERSION = "v1";
public static LIB_NAME = "adyen-node-api-library";
public static LIB_VERSION: string = version;
Expand All @@ -76,10 +77,11 @@ class Client {
public static PAYMENT_API_ENDPOINT_LIVE = "https://pal-live.adyen.com/pal/servlet/Payment";
public static STOREDVALUE_API_ENDPOINT_TEST = "https://pal-test.adyen.com/pal/servlet/StoredValue";
public static STOREDVALUE_API_ENDPOINT_LIVE = "https://pal-live.adyen.com/pal/servlet/StoredValue";
public static TERMINAL_MANAGEMENT_API_ENDPOINT_TEST = "https://postfmapi-test.adyen.com/postfmapi/terminal";
public static TERMINAL_MANAGEMENT_API_ENDPOINT_LIVE = "https://postfmapi-live.adyen.com/postfmapi/terminal";
public static MANAGEMENT_API_ENDPOINT_TEST = "https://management-test.adyen.com";
public static MANAGEMENT_API_ENDPOINT_LIVE = "https://management-live.adyen.com";


private _httpClient!: ClientInterface;
public config: Config;

Expand Down Expand Up @@ -119,6 +121,7 @@ class Client {
this.config.terminalApiCloudEndpoint = Client.TERMINAL_API_ENDPOINT_TEST;
this.config.paymentEndpoint = Client.PAYMENT_API_ENDPOINT_TEST;
this.config.storedValueEndpoint = Client.STOREDVALUE_API_ENDPOINT_TEST;
this.config.terminalManagementEndpoint = Client.TERMINAL_MANAGEMENT_API_ENDPOINT_TEST;
this.config.managementEndpoint = Client.MANAGEMENT_API_ENDPOINT_TEST;
} else if (environment === "LIVE") {
this.config.endpoint = Client.ENDPOINT_LIVE;
Expand All @@ -127,6 +130,7 @@ class Client {
this.config.terminalApiCloudEndpoint = Client.TERMINAL_API_ENDPOINT_LIVE;
this.config.paymentEndpoint = Client.PAYMENT_API_ENDPOINT_LIVE;
this.config.storedValueEndpoint = Client.STOREDVALUE_API_ENDPOINT_LIVE;
this.config.terminalManagementEndpoint = Client.TERMINAL_MANAGEMENT_API_ENDPOINT_LIVE;
this.config.managementEndpoint = Client.MANAGEMENT_API_ENDPOINT_LIVE;

if (liveEndpointUrlPrefix) {
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface ConfigConstructor {
terminalApiLocalEndpoint?: string;
paymentEndpoint?: string;
storedValueEndpoint?: string;
terminalManagementEndpoint?: string;
managementEndpoint?: string;
}

Expand Down Expand Up @@ -63,6 +64,7 @@ class Config {

public paymentEndpoint?: string;
public storedValueEndpoint?: string;
public terminalManagementEndpoint?: string;
public managementEndpoint?: string;

public constructor(options: ConfigConstructor = {}) {
Expand All @@ -85,8 +87,8 @@ class Config {
if (options.terminalApiLocalEndpoint) this.terminalApiLocalEndpoint = options.terminalApiLocalEndpoint;
if (options.paymentEndpoint) this.paymentEndpoint = options.paymentEndpoint;
if (options.storedValueEndpoint) this.storedValueEndpoint = options.storedValueEndpoint;
if (options.terminalManagementEndpoint) this.terminalManagementEndpoint = options.terminalManagementEndpoint;
if (options.managementEndpoint) this.managementEndpoint = options.managementEndpoint;

}

public set checkoutEndpoint(checkoutEndpoint: string | undefined) {
Expand Down
3 changes: 2 additions & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export { default as BinLookup } from "./binLookup";
export { default as Payout } from "./payout";
export { default as Platforms } from "./platforms";
export { default as StoredValue} from "./storedValue";
export { default as Management } from "./management";
export { default as TerminalManagement} from "./terminalManagement";
export { default as Management } from "./management";
14 changes: 14 additions & 0 deletions src/services/resource/terminalManagement/assignTerminals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Client from "../../../client";
import Service from "../../../service";
import Resource from "../../resource";

class AssignTerminals extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.terminalManagementEndpoint}/${Client.TERMINAL_MANAGEMENT_API_VERSION}/assignTerminals`
);
}
}

export default AssignTerminals;
14 changes: 14 additions & 0 deletions src/services/resource/terminalManagement/findTerminal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Client from "../../../client";
import Service from "../../../service";
import Resource from "../../resource";

class FindTerminal extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.terminalManagementEndpoint}/${Client.TERMINAL_MANAGEMENT_API_VERSION}/findTerminal`
);
}
}

export default FindTerminal;
14 changes: 14 additions & 0 deletions src/services/resource/terminalManagement/getStoresUnderAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Client from "../../../client";
import Service from "../../../service";
import Resource from "../../resource";

class GetStoresUnderAccount extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.terminalManagementEndpoint}/${Client.TERMINAL_MANAGEMENT_API_VERSION}/getStoresUnderAccount`
);
}
}

export default GetStoresUnderAccount;
14 changes: 14 additions & 0 deletions src/services/resource/terminalManagement/getTerminalDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Client from "../../../client";
import Service from "../../../service";
import Resource from "../../resource";

class GetTerminalDetails extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.terminalManagementEndpoint}/${Client.TERMINAL_MANAGEMENT_API_VERSION}/getTerminalDetails`
);
}
}

export default GetTerminalDetails;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Client from "../../../client";
import Service from "../../../service";
import Resource from "../../resource";

class GetTerminalsUnderAccount extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.terminalManagementEndpoint}/${Client.TERMINAL_MANAGEMENT_API_VERSION}/getTerminalsUnderAccount`
);
}
}

export default GetTerminalsUnderAccount;
Loading

0 comments on commit 1b636e9

Please sign in to comment.