Toggle navigation
Wialon Playground
Add library
jQuery latest
Bootstrap 3.3.1
Wialon Javascript SDK
Run
Get code
Fork
Save
Examples
Login
Get units
Change unit icon
Get messages
Get sensors
Edit sensors
Commands
Monitoring notification
Track layer
Get resources
Resources and accounts
Account parameters
Do payment
Management Driver
Create notification
Get geofences
Geofence parameters
Create geofence
Gurtam map
Units on map
Unit trace
Create report template
Execute report
Execute custom report
Create driver
Bind driver to unit
Unit edit fields
Import fillings
Token login for site
Advanced authorization form
Token usage in app
Account hierarchy
Nearest units
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Wialon Playground - Do payment</title> <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript" src="//hst-api.wialon.host/wsdk/script/wialon.js"></script> </head> <body> Select resource: <select id="res"><option></option></select> <input type="button" id="pay_btn" value="Do payment"/> <div id="log"></div> </body> </html>
HTML
CSS
// Print message to log function msg(text) { $("#log").prepend(text + "<br/>"); }; function init() { // Execute after login succeed var sess = wialon.core.Session.getInstance(); // get instance of current Session // flags to specify what kind of data should be returned var flags = wialon.item.Item.dataFlag.base | wialon.item.Item.dataFlag.billingProps; sess.loadLibrary("resourceAccounts"); // load Accounts Library sess.updateDataFlags( // load items to current session [{type: "type", data: "avl_resource", flags: flags, mode: 0}], // Items specification function (code) { // updateDataFlags callback if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code var res = sess.getItems("avl_resource"); // get loaded 'avl_resource' items if (!res || !res.length){ msg("No resources found"); return; } // check if resources found for (var i=0; i<res.length; i++) // construct Select list using found resources $("#res").append("<option value='" + res[i].getId() + "'>" + res[i].getName() + "</option>"); }); }; function doPayment(){ // try to do a payment to account var sess = wialon.core.Session.getInstance(); // get instance of current Session var res_id = $("#res").val(); // get selected resource id if(!res_id) {msg("Select resource"); return; } // check if resources selected var res = sess.getItem(res_id); // get Resource by id var usr = sess.getCurrUser(); // get current user var is_acc = (res.getId() == res.getAccountId()); // if resouce is account var is_it_you = (res.getCreatorId() == usr.getId()); // if current user is resource creator if( !is_acc ) { // exit if resource is not account msg("Can not do payment: '"+ res.getName() +"' is <b>not</b> account"); return; } if(is_it_you) { // exit if selected account is yours msg("Can not do payment for your account"); return; } res.doPayment(1,1,"AutoPay", // try to do payment to selected account function(code){ // do payment callback if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code else { msg("Payment registered successfully"); // print payment succed message $("#res").val(""); // reset resource select } }); } // execute when DOM ready $(document).ready(function () { $("#pay_btn").click(doPayment); // bind action to button click wialon.core.Session.getInstance().initSession("https://hst-api.wialon.host"); // init session // For more info about how to generate token check // http://sdk.wialon.host/playground/demo/app_auth_token wialon.core.Session.getInstance().loginToken("5dce19710a5e26ab8b7b8986cb3c49e58C291791B7F0A7AEB8AFBFCEED7DC03BC48FF5F8", "", // try to login function (code) { // login callback if (code){ msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code msg("Logged successfully"); init(); // when login suceed then run init() function }); });
JS
Result
Source code of example
Close ✕
×
Source code