Automatic upload of the payments to ASTPP
By Emin Gabrielyan on 2021-03-31
The VoIP telephony system that was recently installed lacks the possibility to upload the user payments or charges via a file. This document suggests a bypass to this problem.
Fortunately, the data can be submitted via a simple and accurate HTML POST method. The post method is initiated from the html file, which is provided, to be opened within your browser (tested with Microsoft Edge), where also the first authentication as administrator must be carried out manually by the administrator. The rest automatization is done by JavaScript which reads the records, creates the HTML form for each record, and submits via POST method.
The records must be inserted directly into the HTML file in the following format, where the first column represents the user ID in the billing, the second column represents the type of the update (credit or debit), and the last, third column represents the amount.
[65, 0, 0.1],
[64, 0, 0.2],
[60, 0, 0.3],
[58, 0, 0.4],
[36, 0, 0.5],
The JavaScript can be improved such that it can
Read the input from a CSV file,
carry out the sanity checks related to the format of the file,
consider the possible error codes returned from the server,
consider the logged in logged out status of the browser.
All the above said is not done in this version.
Create the list of users and payments.
Open the HTML file with text editor and insert your list (in exactly the same format).
Open the HTML file with your browser.
Click on [Send this] to send the empty form, which will invite you to login into the billing.
You can then fill in some data (user ID, type 0 if payment and 1 if charge, and an amount) and double check in the billing that it works.
Do not close the tab of the HTML file
as well as the additional tab that it will add and which will contain the confirmation of successful submission.
If you click on [Upload one], it will load a record one record from the records that you saved in the HTML file in text format.
If you click on [Upload all], it will submit all records one by one.
The most important disadvantage of this version is that it sends the records blindly without reading the message returned by the billing. If this system will be used in production, you must control your uploads in the database (design queries that compare what you wanted to upload and what is actually uploaded, and in case of discrepancy, create a new list of missing uploads).
Another is an improvement of the code that can read the return from the billing.
The HTML file context is shown below.
<script>
var x=[
[65, 0, 0.1],
[64, 0, 0.2],
[60, 0, 0.3],
[58, 0, 0.4],
[36, 0, 0.5],
];
var i=0;
pay = function(){
if(i<x.length)
{
document.getElementById("userid").value = x[i][0];
document.getElementById("ptype").value = x[i][1];
document.getElementById("credit").value = x[i][2];
i++;
document.getElementById("pay").submit();
document.getElementById("p1").innerHTML="Uploaded "+i+" of "+x.length+" records";
document.title=i+" of "+x.length+" submitted";
}
}
superpay = function() {
pay();
if(i<x.length){
window.setTimeout("superpay()", 1000);
}
}
</script>
<p><form id="pay" action="https://astpp.4z.com/accounts/customer_payment_save/" method="POST" target="tab1">
<p><input name="id" value="" id="userid"/> id</p>
<p><input name="payment_type" value="" id="ptype"/> type</p>
<p><input name="credit" value="" id="credit"/> amount</p>
<p><button>Send this</button><p>
</form><p>
<p><input type="button" value="Upload one" onclick="pay()" /></p>
<p><input type="button" value="Upload all" onclick="superpay()" /></p>
<p id="p1"></p>
<p>(by e-gabrielyan at 4z.com)<p>
If this will go to a developer, then I must be excused for the style, considering that I never touched JavaScript before and do not had almost no experience with HTML.
The HTML file in text, html, and zipped formats are provided