This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| 2021:rd_topup [2021/10/10 20:23] – created admin | 2021:rd_topup [2021/11/09 07:44] (current) – admin | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| ===== Overview Of Top-Up System ===== | ===== Overview Of Top-Up System ===== | ||
| + | {{ : | ||
| + | |||
| + | * There are three types of Top-Up transactions | ||
| + | * Time | ||
| + | * Data | ||
| + | * Days to use | ||
| + | * A Top-Up transaction can only be one of the three available types. | ||
| + | * Each Top-Up transaction has to be associated with an existing Permanent User. | ||
| + | * Each Top-Up transaction is owned by an Access Provider. | ||
| + | * Top-Up transactions can be done by: | ||
| + | * The Top-Up Manager applet which can be found under the Users section of RADIUSdesk. | ||
| + | * Any 3rd Party System using the API | ||
| + | * Every **Create**, **Update** and **Delete** transaction on the top-ups table will have a ripple effect to adjust the corresponding FreeRADIUS attribute of the associated Permanent User. Let us take a practical example: | ||
| + | * A 3rd Party system creates a Permanent User with a profile for data Top-Ups. | ||
| + | * The Rd-Total-Data attribute will be missing since there is no Top-Up loaded for this user. | ||
| + | * The 3rd Party system add the first free Top-Up of 20Mb. | ||
| + | * Rd-Total-Data will now have a value of 20971520 (20*1024*1024). | ||
| + | * The user then purchase 1Gb of data through the 3rd Party CC Payment Gateway. | ||
| + | * Rd-Total-Data will now have a value of 1094713344 (1073741824+20971520). | ||
| + | |||
| + | ===== Profile Requirements For The Top-Up System ===== | ||
| + | |||
| + | * The Top-Up system can only support one specific type of top up. | ||
| + | * Data Top-Up for Permanent Users who have a data based counter. | ||
| + | * Time Top-Up for Permanent Users who have a time based counter. | ||
| + | * Days to use for Permanent Users who have a set expiry date some time in the future. | ||
| + | * To implement a Data and Time Top-Up you have to assign the Permanent User to a profile with profile component containing a **never reset** counter. | ||
| + | * This **never reset** counter will have the **Rd-Total-Time / Rd-Total-Data** attribute missing since it will be assigned to the specific Permanent User as a private attribute. | ||
| + | * With the latest RADIUSdesk it is very simple to create such a profile. | ||
| + | * See the following screenshot | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | * See the Profile Component which was automatically created for us when when we save the Profile | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | ===== Top-Up Manager Applet ===== | ||
| + | * RADIUSdesk includes an applet that allows you to manually manage Top-Ups. | ||
| + | * You can do the standard CRUD (Create Read Update and Delete) functions on the listed Top-Ups. | ||
| + | * The applet has two tabs. The **Home** tab is used to do the standard CRUD. | ||
| + | * There is also a **Transaction History** tab which can be used for audit purposes. | ||
| + | {{: | ||
| + | * **Transaction History** tab | ||
| + | {{: | ||
| + | |||
| + | ===== API For Third Party Systems ===== | ||
| + | * If you have a 3rd party system which will interact with RADIUSdesk to add Top-Ups then this section is for you. | ||
| + | * | ||
| + | <file php add_top_up.php> | ||
| + | <? | ||
| + | |||
| + | print(" | ||
| + | /* | ||
| + | |||
| + | * = required | ||
| + | |||
| + | == Adding a 1Gb Data top-up == | ||
| + | |||
| + | comment | ||
| + | *data_unit | ||
| + | *permanent_user_id 187 (alternatively you can use ' | ||
| + | *token | ||
| + | *type | ||
| + | *value | ||
| + | *user_id | ||
| + | |||
| + | == Adding a 50 minutes Time top-up == | ||
| + | |||
| + | comment | ||
| + | *time_unit | ||
| + | *permanent_user_id | ||
| + | *sel_language | ||
| + | *token | ||
| + | *type | ||
| + | *value | ||
| + | *user_id | ||
| + | |||
| + | */ | ||
| + | |||
| + | $comment | ||
| + | $data_unit | ||
| + | $permanent_user_id | ||
| + | $permanent_user | ||
| + | $token | ||
| + | $user_id | ||
| + | $type = ' | ||
| + | $value | ||
| + | |||
| + | $url = ' | ||
| + | |||
| + | // The data to send to the API | ||
| + | $postData = array( | ||
| + | ' | ||
| + | ' | ||
| + | //' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | |||
| + | // Setup cURL | ||
| + | $ch = curl_init($url); | ||
| + | curl_setopt_array($ch, | ||
| + | |||
| + | CURLOPT_POST | ||
| + | CURLOPT_RETURNTRANSFER | ||
| + | CURLOPT_HTTPHEADER => array( | ||
| + | ' | ||
| + | ), | ||
| + | CURLOPT_POSTFIELDS => json_encode($postData) | ||
| + | )); | ||
| + | |||
| + | // Send the request | ||
| + | $response = curl_exec($ch); | ||
| + | |||
| + | // Check for errors | ||
| + | if($response === FALSE){ | ||
| + | die(curl_error($ch)); | ||
| + | } | ||
| + | |||
| + | // Decode the response | ||
| + | $responseData = json_decode($response, | ||
| + | print_r($responseData); | ||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||