1- Start Easypay service by clicking Connect button and then click Start, after service starting save the IP Address for later use and than click Running on background
2- Create WebSocketwherever you need:
Note: Easypay service will running on two ports (5000 insecure connection) and (9000 secure connection)
use below function for insecure connection:
// Create unsecure WebSocket connection.const socket = new WebSocket("ws://localhost:5000"); // use "localhost" for connection on same device or use "IP address" for connection from external device.
// Response formatsocket.onmessage= (event) => {var data =JSON.parse(event.data)if (data.method ==="WebSocketOpen"&&data.DeviceName !=='null') {// Initialize Success var deviceName = data.DeviceName // if the android device sdk ( printer & customer screen ) supported by Easypay it will return with device name.
}});
or use below function for secure connection:
// Create secure WebSocket connection.const socket = new WebSocket("wss://localhost:9000"); // use "localhost" for connection on same device or use "IP address" for connection from external device.
// Response formatsocket.onmessage= (event) => {var data =JSON.parse(event.data)if (data.method ==="WebSocketOpen"&&data.DeviceName !=='null') {// Initialize Success var deviceName = data.DeviceName // if the android device sdk ( printer & customer screen ) supported by Easypay it will return with device name.
}});
Purchase
Please note the amount should be entered like this 100 which means 1.00 SAR so 1455 will be 14.55 SAR & max length is 12 digits include exponent ( 123456789012 ) which will result in 1,234,567,890.12
You may pass Reference ID in customerReferenceNumber field to be attached to this transaction. or null otherwise.
socket.send(JSON.stringify({"method":"PURCHASE","amount":100,// [Required] ammount you want to set . "customerReferenceNumber": "1234" // [optional] any number you want to add as a refrence Any string as a reference number.
}));// Response formatsocket.onmessage= (event) => {var data =JSON.parse(event.data)if (data.method ==="PURCHASE") {if (data.error) {console.log("error",data.error) } elseif (data.message) {var response =JSON.parse(data.message)if (response.is_approved) {// Purchase Success } else {// Purchase Reject } }});
Refund
pass the transactionUuid of the transaction you want to refund
socket.send(JSON.stringify({"method":"REFUND", "transactionUuid": "f5079b9d-b61c-4180-8a4d-9780f7a9cd8f", // [Required] the orginal trnasaction uuid that you want to refund.
"amount":100,// [Required] ammount you want to set . "customerReferenceNumber": "1234" // [optional] any number you want to add as a refrence Any string as a reference number.
}));// Response formatsocket.onmessage= (event) => {var data =JSON.parse(event.data)if (data.method ==="PURCHASE") {if (data.error) {console.log("error",data.error) } elseif (data.message) {var response =JSON.parse(data.message)if (response.is_approved) {// Refund Success } else {// Refund Reject } }});
Print receipt
if (DeviceName !=='null') {socket.send(JSON.stringify({"method":"PrintLastResult" }));}
Open Cashbox
if (DeviceName !=='null') {socket.send(JSON.stringify({"method":"OpenDrawer" }));}
Easypay Customer Screen:
Open customer screen:
on app home screen click to Customer Screen button.
1- If you have your own customer screen you need just to send the Url link: