Skip to content

Commit aca5105

Browse files
committed
Add decryptNotification
1 parent 30035b0 commit aca5105

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

src/__tests__/cloudDevice/cloudDeviceAPI.spec.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe("Cloud device API", (): void => {
139139
cloudDeviceApiRequest.SaleToPOIRequest.MessageHeader.ServiceID = id;
140140
const saleToAcquirerData: cloudDevice.SaleToAcquirerData = new cloudDevice.SaleToAcquirerData();
141141
saleToAcquirerData.currency = "EUR";
142-
cloudDeviceApiRequest.SaleToPOIRequest.ReversalRequest!.SaleData!.SaleToAcquirerData = saleToAcquirerData;
142+
cloudDeviceApiRequest.SaleToPOIRequest.ReversalRequest!.SaleData!.SaleToAcquirerData = saleToAcquirerData;
143143

144144
const merchantAccount = "TestMerchantAccount";
145145
const deviceId = "P400Plus-123456789";
@@ -202,7 +202,7 @@ describe("Cloud device API", (): void => {
202202

203203
expect(response).toBeDefined();
204204
expect(response).toEqual("ok");
205-
});
205+
});
206206

207207
test("should make an encrypted sync request", async (): Promise<void> => {
208208
scope.post("/merchants/TestMerchantAccount/devices/MX915-284251016/sync").reply(200, syncEncryptedResponse);
@@ -228,7 +228,7 @@ describe("Cloud device API", (): void => {
228228
// verify deviceId is set on request
229229
expect(cloudDeviceApiSecuredRequest.SaleToPOIRequest.MessageHeader.POIID).toBe(deviceId);
230230

231-
});
231+
});
232232

233233
test("should throw CloudDeviceApiError when request fails", async (): Promise<void> => {
234234
scope.post("/merchants/TestMerchantAccount/devices/P400Plus-123456789/sync").replyWithError("timeout");
@@ -259,24 +259,24 @@ describe("Cloud device API", (): void => {
259259

260260
describe("should build the expected CloudDeviceAPI endpoints", () => {
261261

262-
it("should return the sync endpoint", () => {
263-
const endpoint = cloudDeviceAPI.getSyncEndpoint("TestMerchantAccount", "P400Plus-123456789");
264-
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/devices/P400Plus-123456789/sync");
265-
});
266-
267-
it("should return the async endpoint", () => {
268-
const endpoint = cloudDeviceAPI.getAsyncEndpoint("TestMerchantAccount", "P400Plus-123456789");
269-
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/devices/P400Plus-123456789/async");
270-
});
271-
272-
it("should return the connected devices endpoint", () => {
273-
const endpoint = cloudDeviceAPI.getConnectedDevicesEndpoint("TestMerchantAccount");
274-
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/connectedDevices");
275-
});
276-
277-
it("should return the device status endpoint", () => {
278-
const endpoint = cloudDeviceAPI.getDeviceStatusEndpoint("TestMerchantAccount", "P400Plus-123456789");
279-
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/devices/P400Plus-123456789/status");
280-
});
281-
262+
it("should return the sync endpoint", () => {
263+
const endpoint = cloudDeviceAPI.getSyncEndpoint("TestMerchantAccount", "P400Plus-123456789");
264+
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/devices/P400Plus-123456789/sync");
265+
});
266+
267+
it("should return the async endpoint", () => {
268+
const endpoint = cloudDeviceAPI.getAsyncEndpoint("TestMerchantAccount", "P400Plus-123456789");
269+
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/devices/P400Plus-123456789/async");
270+
});
271+
272+
it("should return the connected devices endpoint", () => {
273+
const endpoint = cloudDeviceAPI.getConnectedDevicesEndpoint("TestMerchantAccount");
274+
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/connectedDevices");
275+
});
276+
277+
it("should return the device status endpoint", () => {
278+
const endpoint = cloudDeviceAPI.getDeviceStatusEndpoint("TestMerchantAccount", "P400Plus-123456789");
279+
expect(endpoint).toBe("https://device-api-test.adyen.com/v1/merchants/TestMerchantAccount/devices/P400Plus-123456789/status");
280+
});
281+
282282
});

src/services/cloudDevice/cloudDeviceApi.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,22 @@ class CloudDeviceAPI extends Service {
300300
return ObjectSerializer.deserialize(response, "DeviceStatusResponse");
301301
}
302302

303+
/**
304+
* Decrypt event notification
305+
* @param payload Event notification in JSON string format
306+
* @param encryptionCredentialDetails The details of the encryption credential used for decrypting the payload (nexoBlob)
307+
* @returns
308+
*/
309+
public decryptNotification(payload: string, encryptionCredentialDetails: EncryptionCredentialDetails) : String {
310+
311+
const decryptedMessage = ObjectSerializer.deserialize(JSON.parse(payload), "CloudDeviceApiSecuredResponse");
312+
313+
return NexoSecurityManager.decrypt(
314+
decryptedMessage.SaleToPOIResponse,
315+
encryptionCredentialDetails,
316+
);
317+
}
318+
303319
/**
304320
* Get Device API /sync endpoint
305321
* @param merchantAccount The unique identifier of the merchant account.

0 commit comments

Comments
 (0)