I'm fairly new to Node, and I'm trying to connect to a Clover Mini device through a websocket using the API provided by Clover.
I've tried modifying the example code below to work using only node, but when I open it in node nothing happens. (No errors, just nothing happens at all)
It works in Chrome just fine, so what's missing?
https://github.com/clover/remote-pay-cloud
var $ = require('jQuery');
var clover = require("remote-pay-cloud");
var log = clover.Logger.create();
var connector = new clover.CloverConnectorFactory().createICloverConnector({
"oauthToken": "1e7a9007-141a-293d-f41d-f603f0842139",
"merchantId": "BBFF8NBCXEMDV",
"clientId": "3RPTN642FHXTX",
"remoteApplicationId": "com.yourname.yourapplication:1.0.0-beta1",
"deviceSerialId": "C031UQ52340015",
"domain": "https://sandbox.dev.clover.com/"
});
var ExampleCloverConnectorListener = function(cloverConnector) {
clover.remotepay.ICloverConnectorListener.call(this);
this.cloverConnector = cloverConnector;
};
ExampleCloverConnectorListener.prototype = Object.create(clover.remotepay.ICloverConnectorListener.prototype);
ExampleCloverConnectorListener.prototype.constructor = ExampleCloverConnectorListener;
ExampleCloverConnectorListener.prototype.onReady = function (merchantInfo) {
var saleRequest = new clover.remotepay.SaleRequest();
saleRequest.setExternalId(clover.CloverID.getNewId());
saleRequest.setAmount(10000);
this.cloverConnector.sale(saleRequest);
};
ExampleCloverConnectorListener.prototype.onVerifySignatureRequest = function (request) {
log.info(request);
this.cloverConnector.acceptSignature(request);
};
ExampleCloverConnectorListener.prototype.onConfirmPaymentRequest = function (request) {
this.cloverConnector.acceptPayment(request.payment);
};
ExampleCloverConnectorListener.prototype.onSaleResponse = function (response) {
log.info(response);
connector.dispose();
if(!response.getIsSale()) {
console.error("Response is not an sale!");
console.error(response);
}
};
var connectorListener = new ExampleCloverConnectorListener(connector);
connector.addCloverConnectorListener(connectorListener);
connector.initializeConnection();
After getting into contact with the developers at clover, their documentation had some errors. For other users sake here is the link to that issue on their gitub as well as some example code.
link to github issue
const endpoint = "ws://yourip:yourport/remote_pay";
var webSocketFactory = function () {
let webSocketOverrides = {
createWebSocket: function () {
// To support self-signed certificates you must pass rejectUnauthorized = false.
// https://github.com/websockets/ws/blob/master/examples/ssl.js
let sslOptions = {
rejectUnauthorized: false
};
// Use the ws library by default.
return new WebSocket(endpoint, sslOptions);
}
}
return Object.assign(new clover.CloverWebSocketInterface(endpoint), webSocketOverrides);
};
var ExampleWebsocketPairedCloverDeviceConfiguration = function () {
clover.WebSocketPairedCloverDeviceConfiguration.call(this,
endpoint, // endpoint
"com.cloverconnector.javascript.simple.sample:1.4", // Application Id
"Javascript Simple Sample", // posName
"Register_1", // serialNumber
null, // authToken().get(
webSocketFactory,
new clover.ImageUtil());
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With