@@ -79,11 +79,8 @@ class CloudDeviceAPI extends Service {
7979 * @returns A promise that resolves to "ok" if the request was successful, or a CloudDeviceApiResponse if there is an error.
8080 */
8181 public sendAsync ( merchantAccount : string , deviceId : string , cloudDeviceApiRequest : CloudDeviceApiRequest ) : Promise < string | CloudDeviceApiResponse > {
82- const endpoint = this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/async"
83- . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
84- . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
8582
86- const resource = new Resource ( this , endpoint ) ;
83+ const resource = new Resource ( this , this . getAsyncEndpoint ( merchantAccount , deviceId ) ) ;
8784
8885 const request = CloudDeviceAPI . setApplicationInfo ( cloudDeviceApiRequest , deviceId ) ;
8986
@@ -123,12 +120,7 @@ class CloudDeviceAPI extends Service {
123120
124121 try {
125122
126- const endpoint = this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/async"
127- . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
128- . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
129-
130- const resource = new Resource ( this , endpoint ) ;
131-
123+ const resource = new Resource ( this , this . getAsyncEndpoint ( merchantAccount , deviceId ) ) ;
132124 const request = CloudDeviceAPI . setApplicationInfo ( cloudDeviceApiRequest , deviceId ) ;
133125
134126 // extract the payload to encrypt (i.e. PaymentRequest)
@@ -183,12 +175,8 @@ class CloudDeviceAPI extends Service {
183175 * @returns A promise that resolves to a CloudDeviceApiResponse.
184176 */
185177 public async sendSync ( merchantAccount : string , deviceId : string , cloudDeviceApiRequest : CloudDeviceApiRequest ) : Promise < CloudDeviceApiResponse > {
186- const endpoint = this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/sync"
187- . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
188- . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
189-
190- const resource = new Resource ( this , endpoint ) ;
191178
179+ const resource = new Resource ( this , this . getSyncEndpoint ( merchantAccount , deviceId ) ) ;
192180 const request = CloudDeviceAPI . setApplicationInfo ( cloudDeviceApiRequest , deviceId ) ;
193181
194182 const response = await getJsonResponse < CloudDeviceApiRequest , CloudDeviceApiResponse > (
@@ -229,12 +217,7 @@ class CloudDeviceAPI extends Service {
229217
230218 try {
231219
232- const endpoint = this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/sync"
233- . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
234- . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
235-
236- const resource = new Resource ( this , endpoint ) ;
237-
220+ const resource = new Resource ( this , this . getSyncEndpoint ( merchantAccount , deviceId ) ) ;
238221 const request = CloudDeviceAPI . setApplicationInfo ( cloudDeviceApiRequest , deviceId ) ;
239222
240223 // extract the payload to encrypt (i.e. PaymentRequest)
@@ -282,10 +265,8 @@ class CloudDeviceAPI extends Service {
282265 * @returns A promise that resolves to a ConnectedDevicesResponse.
283266 */
284267 public async getConnectedDevices ( merchantAccount : string , store ?: string ) : Promise < ConnectedDevicesResponse > {
285- const endpoint = this . baseUrl + "/merchants/{merchantAccount}/connectedDevices"
286- . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) ) ;
287268
288- const resource = new Resource ( this , endpoint ) ;
269+ const resource = new Resource ( this , this . getConnectedDevicesEndpoint ( merchantAccount ) ) ;
289270
290271 let requestOptions : IRequest . Options = { } ;
291272 if ( store ) {
@@ -309,11 +290,8 @@ class CloudDeviceAPI extends Service {
309290 * @returns A promise that resolves to a DeviceStatusResponse.
310291 */
311292 public async getDeviceStatus ( merchantAccount : string , deviceId : string ) : Promise < DeviceStatusResponse > {
312- const endpoint = this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/status"
313- . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
314- . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
315293
316- const resource = new Resource ( this , endpoint ) ;
294+ const resource = new Resource ( this , this . getDeviceStatusEndpoint ( merchantAccount , deviceId ) ) ;
317295
318296 const response = await getJsonResponse < string , DeviceStatusResponse > (
319297 resource ,
@@ -343,6 +321,52 @@ class CloudDeviceAPI extends Service {
343321 return null ;
344322 }
345323
324+ /**
325+ * Get Device API /sync endpoint
326+ * @param merchantAccount The unique identifier of the merchant account.
327+ * @param deviceId The unique identifier of the payment device.
328+ * @returns
329+ */
330+ getSyncEndpoint ( merchantAccount : string , deviceId : string ) {
331+ return this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/sync"
332+ . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
333+ . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
334+ }
335+
336+ /**
337+ * Get Device API /async endpoint
338+ * @param merchantAccount The unique identifier of the merchant account.
339+ * @param deviceId The unique identifier of the payment device.
340+ * @returns
341+ */
342+ getAsyncEndpoint ( merchantAccount : string , deviceId : string ) {
343+ return this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/async"
344+ . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
345+ . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
346+ }
347+
348+ /**
349+ * Get Device API connectedDevices endpoint
350+ * @param merchantAccount The unique identifier of the merchant account.
351+ * @returns
352+ */
353+ getConnectedDevicesEndpoint ( merchantAccount : string ) {
354+ return this . baseUrl + "/merchants/{merchantAccount}/connectedDevices"
355+ . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) ) ;
356+ }
357+
358+ /**
359+ * Get Device API device status endpoint
360+ * @param merchantAccount The unique identifier of the merchant account.
361+ * @param deviceId The unique identifier of the payment device.
362+ * @returns
363+ */
364+ getDeviceStatusEndpoint ( merchantAccount : string , deviceId : string ) {
365+ return this . baseUrl + "/merchants/{merchantAccount}/devices/{deviceId}/status"
366+ . replace ( "{" + "merchantAccount" + "}" , encodeURIComponent ( String ( merchantAccount ) ) )
367+ . replace ( "{" + "deviceId" + "}" , encodeURIComponent ( String ( deviceId ) ) ) ;
368+ }
369+
346370}
347371
348372
0 commit comments