11import Client from "../../client" ;
22import CloudDeviceAPI from "../../services/cloudDevice/cloudDeviceApi" ;
3- import { createCloudDeviceApiRequest } from "../../__mocks__/cloudDeviceApi/baseCloudDeviceApi" ;
43import { EnvironmentEnum } from "../../config" ;
5- import { CloudDeviceApiRequest , DeviceStatusResponse , ConnectedDevicesResponse , CloudDeviceApiResponse } from "../../typings/cloudDevice/models" ;
4+ import { CloudDeviceApiRequest , DeviceStatusResponse , ConnectedDevicesResponse , CloudDeviceApiResponse , MessageHeader , MessageCategoryType , MessageClassType , PaymentRequest } from "../../typings/cloudDevice/models" ;
65import { EncryptionCredentialDetails } from "../../security/encryptionCredentialDetails" ;
76import { MessageType } from "../../typings/terminal/messageType" ;
87
@@ -36,7 +35,7 @@ const { ADYEN_API_KEY, ADYEN_MERCHANT_ACCOUNT, ADYEN_TERMINAL_DEVICE_ID } = proc
3635const { ADYEN_TERMINAL_DEVICE_KEY_IDENTIFIER , ADYEN_TERMINAL_DEVICE_PASSPHRASE } = process . env ;
3736
3837const hasEnv = ! ! ( ADYEN_API_KEY && ADYEN_MERCHANT_ACCOUNT && ADYEN_TERMINAL_DEVICE_ID ) ;
39- ( enableTerminalTest && hasEnv ? describe : describe . skip ) ( "Cloud Device API Testing with Terminal" , ( ) => {
38+ ( enableTerminalTest && hasEnv ? describe : describe . skip ) ( "Cloud Device API Testing with Terminal" , ( ) => {
4039 let client : Client ;
4140 let cloudDeviceAPI : CloudDeviceAPI ;
4241
@@ -61,12 +60,10 @@ const hasEnv = !!(ADYEN_API_KEY && ADYEN_MERCHANT_ACCOUNT && ADYEN_TERMINAL_DEVI
6160 const merchantAccount = ADYEN_MERCHANT_ACCOUNT ! ;
6261 const deviceId = ADYEN_TERMINAL_DEVICE_ID ! ;
6362
64- const cloudDeviceApiRequest : CloudDeviceApiRequest = createCloudDeviceApiRequest ( ) ;
65-
6663 const response = await cloudDeviceAPI . sendSync (
6764 merchantAccount ,
6865 deviceId ,
69- cloudDeviceApiRequest
66+ testCloudDeviceApiRequest ( deviceId )
7067 ) ;
7168
7269 // Log outcome
@@ -87,12 +84,10 @@ const hasEnv = !!(ADYEN_API_KEY && ADYEN_MERCHANT_ACCOUNT && ADYEN_TERMINAL_DEVI
8784 const merchantAccount = ADYEN_MERCHANT_ACCOUNT ! ;
8885 const deviceId = ADYEN_TERMINAL_DEVICE_ID ! ;
8986
90- const cloudDeviceApiRequest : CloudDeviceApiRequest = createCloudDeviceApiRequest ( ) ;
91-
9287 const response = await cloudDeviceAPI . sendAsync (
9388 merchantAccount ,
9489 deviceId ,
95- cloudDeviceApiRequest
90+ testCloudDeviceApiRequest ( deviceId )
9691 ) ;
9792
9893 // Log outcome
@@ -139,25 +134,23 @@ const hasEnv = !!(ADYEN_API_KEY && ADYEN_MERCHANT_ACCOUNT && ADYEN_TERMINAL_DEVI
139134 const merchantAccount = ADYEN_MERCHANT_ACCOUNT ! ;
140135 const deviceId = ADYEN_TERMINAL_DEVICE_ID ! ;
141136
142- const cloudDeviceApiRequest = createCloudDeviceApiRequest ( ) ;
143-
144137 // IMPORTANT: Encryption credentials must match the Terminal configuration on CA
145138 const encryptionCredentialDetails : EncryptionCredentialDetails = {
146- AdyenCryptoVersion : 1 ,
147- KeyIdentifier : ADYEN_TERMINAL_DEVICE_KEY_IDENTIFIER ?? "n/a" ,
148- KeyVersion : 1 ,
149- Passphrase : ADYEN_TERMINAL_DEVICE_PASSPHRASE ?? "n/a" ,
139+ AdyenCryptoVersion : 1 ,
140+ KeyIdentifier : ADYEN_TERMINAL_DEVICE_KEY_IDENTIFIER ?? "n/a" ,
141+ KeyVersion : 1 ,
142+ Passphrase : ADYEN_TERMINAL_DEVICE_PASSPHRASE ?? "n/a" ,
150143 } ;
151144
152145 const response : CloudDeviceApiResponse = await cloudDeviceAPI . sendEncryptedSync (
153146 merchantAccount ,
154147 deviceId ,
155- cloudDeviceApiRequest ,
148+ testCloudDeviceApiRequest ( deviceId ) ,
156149 encryptionCredentialDetails
157150 ) ;
158151
159152 // Log outcome
160- console . log ( "response:" , response ) ;
153+ console . log ( "response:" , response ) ;
161154
162155 expect ( response ) . toBeDefined ( ) ;
163156 // After decryption by the SDK, the response should be a standard CloudDeviceApiResponse
@@ -166,26 +159,24 @@ const hasEnv = !!(ADYEN_API_KEY && ADYEN_MERCHANT_ACCOUNT && ADYEN_TERMINAL_DEVI
166159 expect ( response . SaleToPOIResponse ?. MessageHeader . MessageType ) . toBe ( MessageType . Response ) ;
167160 expect ( response . SaleToPOIResponse ?. PaymentResponse ) . toBeDefined ( ) ;
168161 } ) ;
169-
162+
170163 // run with: npx jest cloudDeviceApi.terminal.spec.ts -t "should make an encrypted async payment request"
171164 test ( "should make an encrypted async payment request" , async ( ) => {
172165 const merchantAccount = ADYEN_MERCHANT_ACCOUNT ! ;
173166 const deviceId = ADYEN_TERMINAL_DEVICE_ID ! ;
174167
175- const cloudDeviceApiRequest = createCloudDeviceApiRequest ( ) ;
176-
177168 // IMPORTANT: Encryption credentials must match the Terminal configuration on CA
178169 const encryptionCredentialDetails : EncryptionCredentialDetails = {
179- AdyenCryptoVersion : 1 ,
180- KeyIdentifier : ADYEN_TERMINAL_DEVICE_KEY_IDENTIFIER ?? "n/a" ,
181- KeyVersion : 1 ,
182- Passphrase : ADYEN_TERMINAL_DEVICE_PASSPHRASE ?? "n/a" ,
170+ AdyenCryptoVersion : 1 ,
171+ KeyIdentifier : ADYEN_TERMINAL_DEVICE_KEY_IDENTIFIER ?? "n/a" ,
172+ KeyVersion : 1 ,
173+ Passphrase : ADYEN_TERMINAL_DEVICE_PASSPHRASE ?? "n/a" ,
183174 } ;
184175
185176 const response = await cloudDeviceAPI . sendEncryptedAsync (
186177 merchantAccount ,
187178 deviceId ,
188- cloudDeviceApiRequest ,
179+ testCloudDeviceApiRequest ( deviceId ) ,
189180 encryptionCredentialDetails
190181 ) ;
191182
@@ -194,4 +185,57 @@ const hasEnv = !!(ADYEN_API_KEY && ADYEN_MERCHANT_ACCOUNT && ADYEN_TERMINAL_DEVI
194185
195186 expect ( response ) . toBeDefined ( ) ;
196187 } ) ;
188+
189+ const testCloudDeviceApiRequest = function ( deviceId : string ) {
190+ const timestamp = ( ) : string => new Date ( ) . toISOString ( ) ;
191+ const id = Math . floor ( Math . random ( ) * Math . floor ( 10000000 ) ) . toString ( ) ;
192+
193+ const messageHeader : MessageHeader = {
194+ MessageCategory : MessageCategoryType . Payment ,
195+ MessageClass : MessageClassType . Service ,
196+ MessageType : MessageType . Request ,
197+ POIID : deviceId ,
198+ ProtocolVersion : "3.0" ,
199+ SaleID : id ,
200+ ServiceID : id ,
201+ } ;
202+
203+ const paymentRequest : PaymentRequest = {
204+ PaymentTransaction : {
205+ AmountsReq : {
206+ Currency : "EUR" ,
207+ RequestedAmount : 1 ,
208+ } ,
209+ } ,
210+ SaleData : {
211+ SaleTransactionID : {
212+ TimeStamp : timestamp ( ) ,
213+ TransactionID : id ,
214+ } ,
215+ SaleToAcquirerData : {
216+ applicationInfo : {
217+ merchantApplication : {
218+ version : "1" ,
219+ name : "test"
220+ }
221+ } ,
222+ metadata : {
223+ someMetaDataKey1 : "YOUR_VALUE" ,
224+ someMetaDataKey2 : "YOUR_VALUE"
225+ } ,
226+ }
227+ } ,
228+ } ;
229+
230+ const cloudDeviceApiRequest : CloudDeviceApiRequest = {
231+ SaleToPOIRequest : {
232+ MessageHeader : messageHeader ,
233+ PaymentRequest : paymentRequest ,
234+ } ,
235+ } ;
236+
237+ return cloudDeviceApiRequest
238+ }
239+
197240} ) ;
241+
0 commit comments