question

geomichel avatar image
geomichel asked David Marginian Deactivated edited

Cannot read property 'postData' of undefined at WebSocketCloudCloverTransport.obtainWebSocketUrlAndSendPushAlert

Hi !

I am trying to convert the Nodejs Example ExampleCLI.js to server side code.TI am using the same configuration.

But in my Program

the WebSocketCloudCloverDeviceConfiguration having webSocketImplClass: [Function (anonymous)]

but the ExampleCLI.js giving webSocketImplClass: [Function: get]


for both of them the config parameters for

ExampleWebSocketDeviceConnectionConfiguration.create(connectionConfiguration, true);

and

connectionConfiguration =

{

remoteApplicationId: 'appid'

webSocketLibrary: 'nodejs-websocket',

connectorType: 'Cloud',

cloverServer: 'https://sandbox.dev.clover.com/',

merchantId: 'mid',

deviceId: 'did',

accessToken: 'at',

friendlyId: 'Register_1',

action: 'Sale'

}

but for my server side code its not working.I am getting

error TypeError: Cannot read property 'postData' of undefined

at WebSocketCloudCloverTransport.obtainWebSocketUrlAndSendPushAlert (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:102:26)

at WebSocketCloudCloverTransport.initialize (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:79:22)

at new WebSocketCloudCloverTransport (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:53:15)

at WebSocketCloudCloverDeviceConfiguration.getCloverTransport (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\device\WebSocketCloudCloverDeviceConfiguration.js:74:25)

at WebsocketCloudCloverDevice.DefaultCloverDevice [as constructor] (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\device\DefaultCloverDevice.js:34:92)

at new WebsocketCloudCloverDevice (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\device\WebsocketCloudCloverDevice.js:25:23)

at Function.CloverDeviceFactory.get (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\device\CloverDeviceFactory.js:24:28)

at CloverConnector.initialize (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\CloverConnector.js:44:65)

at CloverConnector.initializeConnection (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\CloverConnector.js:51:18)

at C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\lib\CloverCloudPAyAPI.js:68:29

Trace

at Logger.toConsole (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\util\Logger.js:46:29)

at Logger.emit (events.js:376:20)

at Function.CloverDeviceFactory.get (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\device\CloverDeviceFactory.js:27:38)

at CloverConnector.initialize (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\CloverConnector.js:44:65)

at CloverConnector.initializeConnection (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\CloverConnector.js:51:18)

at C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\lib\CloverCloudPAyAPI.js:68:29

at Layer.handle [as handle_request] (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\express\lib\router\layer.js:95:5)

at next (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\express\lib\router\route.js:137:13)

at Route.dispatch (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\express\lib\router\route.js:112:3)

at Layer.handle [as handle_request] (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\express\lib\router\layer.js:95:5)

error.

I would appreciate any help on this.


https://clover.github.io/remote-pay-cloud/4.0.2/classes/_remote_client_device_websocketcloudcloverdeviceconfiguration_.websocketcloudcloverdeviceconfiguration.html


here I found the below lines

For Browser implementations, this can be BrowserWebSocketImpl.createInstance. For NodeJS implementations, this will be defined differently.


May I know how to define differently for nodejs?


Thanks

Ambika

Remote Pay Cloud
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated edited

Please take a look at the readme in the Node example for implementation notes - https://github.com/clover/remote-pay-cloud-examples/tree/master/remote-pay-cloud-nodejs-example. This is a very simple example and is not a robust POS system, it is not meant to simply be copied. Our non-Node starter is a bit more robust and will give you an idea of some of the things you will need to implement - https://github.com/clover/remote-pay-cloud-examples/blob/master/remote-pay-cloud-starter/public/index.js.. I would also, strongly encourage you to look at a client approach where you maintain a connection to the device if at all possible. Server implementations are more complicated and error prone. Regardess, please read and implement our best practices - https://docs.clover.com/docs/remote-pay-sdk-best-practices.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

geomichel avatar image
geomichel answered

Hi David!

Actually we need to implement this feature in server side. Is there any way I will get the Clover connect configuration parameters for server side web socket implementation.

const cloudConfigurationBuilder = new clover.WebSocketCloudCloverDeviceConfigurationBuilder( "applicationId " , // applicationId "deviceId" , // deviceId "merchantId" , // merchantId "accessToken" , // accessToken );
const cloudConfiguration = cloudConfigurationBuilder.setCloverServer( "https://sandbox.dev.clover.com" ) .setFriendlyId( "Register_1" ).setHttpSupport( new clover.HttpSupport(XMLHttpRequest)) .build();


this configuration throwing

error connect, connectionError ReferenceError: WebSocket is not defined

at BrowserWebSocketImpl.createWebSocket (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\websocket\BrowserWebSocketImpl.js:37:9)

at BrowserWebSocketImpl.CloverWebSocketInterface.connect (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\websocket\CloverWebSocketInterface.js:27:31)

at CloverWebSocketClient.connect (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\CloverWebSocketClient.js:32:25)

at WebSocketCloudCloverTransport.WebSocketCloverTransport.initializeWithUri (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloverTransport.js:133:36)

at WebSocketCloudCloverTransport.afterOptionsCall (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:188:44)

at C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:149:90

at HttpSupport.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\util\HttpSupport.js:27:29)

at XMLHttpRequest.dispatchEvent (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:622:25)

at setState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:641:14)

at IncomingMessage.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:480:13)

Trace

at Logger.toConsole (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\util\Logger.js:46:29)

at Logger.emit (events.js:376:20)

at CloverWebSocketClient.connect (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\CloverWebSocketClient.js:35:25)

at WebSocketCloudCloverTransport.WebSocketCloverTransport.initializeWithUri (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloverTransport.js:133:36)

at WebSocketCloudCloverTransport.afterOptionsCall (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:188:44)

at C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:149:90

at HttpSupport.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\util\HttpSupport.js:27:29)

at XMLHttpRequest.dispatchEvent (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:622:25)

at setState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:641:14)

at IncomingMessage.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:480:13)

> Device Disconnected!

deviceError: WebSocket is not defined

error https://sandbox.dev.clover.com/H5J4BN45T6B71/support/remote_pay/cs?token=C043UQ00250508&friendlyId=Register_1&forceConnect=false TypeError: Cannot read property 'readyState' of undefined

at BrowserWebSocketImpl.CloverWebSocketInterface.getReadyState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\websocket\CloverWebSocketInterface.js:155:31)

at CloverWebSocketClient.getWebSocketState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\CloverWebSocketClient.js:18:44)

at WebSocketCloudCloverTransport.afterOptionsCall (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:184:70)

at C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:149:90

at HttpSupport.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\util\HttpSupport.js:27:29)

at XMLHttpRequest.dispatchEvent (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:622:25)

at setState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:641:14)

at IncomingMessage.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:480:13)

at IncomingMessage.emit (events.js:388:22)

at endReadableNT (internal/streams/readable.js:1336:12)

Trace

at Logger.toConsole (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\util\Logger.js:46:29)

at Logger.emit (events.js:376:20)

at HttpSupport.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\util\HttpSupport.js:31:37)

at XMLHttpRequest.dispatchEvent (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:622:25)

at setState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:641:14)

at IncomingMessage.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:480:13)

at IncomingMessage.emit (events.js:388:22)

at endReadableNT (internal/streams/readable.js:1336:12)

at processTicksAndRejections (internal/process/task_queues.js:82:21)

C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\websocket\CloverWebSocketInterface.js:155

return this.webSocket.readyState;

^


TypeError: Cannot read property 'readyState' of undefined

at BrowserWebSocketImpl.CloverWebSocketInterface.getReadyState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\websocket\CloverWebSocketInterface.js:155:31)

at CloverWebSocketClient.getWebSocketState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\CloverWebSocketClient.js:18:44)

at WebSocketCloudCloverTransport.afterOptionsCall (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:184:70)

at C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\remote\client\transport\websocket\WebSocketCloudCloverTransport.js:149:90

at HttpSupport.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\remote-pay-cloud\dist\com\clover\util\HttpSupport.js:33:29)

at XMLHttpRequest.dispatchEvent (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:622:25)

at setState (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:641:14)

at IncomingMessage.<anonymous> (C:\LocalRep\Clover\remote-pay-cloud-nodejs-example\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:480:13)

at IncomingMessage.emit (events.js:388:22)

at endReadableNT (internal/streams/readable.js:1336:12)



Could you please suggest how to set configuration for server side implentation?


Thnaks and Regards

Ambika

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated edited

As I previously posted, you need to read the readme in the NodeJS example as it explains what is required to use Node - https://github.com/clover/remote-pay-cloud-examples/tree/master/remote-pay-cloud-nodejs-example#implementation-notes.. When using the SDK in the browser the browser provides certain dependencies, when using Node on the server you need to provide them.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community