Automatic upload of the payments to ASTPP

Updated by Emin Gabrielyan on 2021-03-31

Created by Emin Gabrielyan on 2021-03-31

 

Table of Contents

Table of content. 1

Introduction. 1

How.. 1

Further improvement. 1

How to use. 2

Comments. 2

The code. 2

Bug. 3

Acronyms. 4

END.. 4

 

Introduction

The ASTPP 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.

How

Fortunately, the individual user credit or debit can be submitted via a simple and accurate HTML POST method. In the suggested bypass solution, the post method is initiated from the html file, which is provided, to be opened within your browser (tested with Microsoft Edge), where the first authentication as administrator must be carried out manually. The further automatization of the process is done by a JavaScript which reads the records, creates the HTML form for each record, and submits them to the administrator interface of the billing via POST methods.

The records must be inserted directly into the HTML file (as a JavaScript array) in the following format. 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, the 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],

Further improvement

The JavaScript can be improved such that it can also

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.

Another, a better version, would be a development of a solution that is not dependent on a browser and can do all steps in a standalone mode, for example running from a server. Such a version can be written in python. It must take care of the login into the administrator interface without the browser. I do not know this technology and I do not know how it can be done.

How to use

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.

Once the upload of all records is completed, the page will not upload more records if you click on [Upload one] or [Upload all], unless if you reload the HTML, in which case the counter will be set to 0 and the upload of the same credits (or debits) will be repeated (which, normally, is not what you would want).

Comments

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 code

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 have almost no experience with HTML.

The HTML file in text, html, and zipped formats are provided:

2.html,

2.zip,

3.txt

Bug

I am not sure if it is a bug in the billing, but the credit increases not the balance, but the absolute value of the balance. This is true, even if you do the refund using the native web GUI. I realize that the meaning of the sign of the balance can be different for postpaid account versus prepaid account (whether it is the positive or the negative balance that represents the amount in favor of the customer, while the opposite sign represents the amount in favor of the billing). The cases I have seen concern all prepaid accounts. When a prepaid account with a positive balance of 10.00 CHF is refunded for an amount of 1.00 CHF, the balance changes to 11.00 CHF. When a prepaid account with a negative balance of -10.00 CHF is refunded for an amount of 1.00 CHF, the balance does not change to -9.00 CHF but to -11.00 CHF.

Acronyms

CDR, Call Data Records

ASTPP, A Smart Tele-Phony Platform

VoIP, Voice over IP

IP, Internet Protocol

GUI, Graphical User Interface

END

***

© 4z.com