RADIUSdesk

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
2021:rd_topup [2021/10/10 21:19] – [Profile Requirements For The Top-Up System] admin2021:rd_topup [2021/11/09 07:44] (current) admin
Line 20: Line 20:
         * The Top-Up Manager applet which can be found under the Users section of RADIUSdesk.         * The Top-Up Manager applet which can be found under the Users section of RADIUSdesk.
         * Any 3rd Party System using the API         * 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:+  * 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.         * 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 Rd-Total-Data attribute will be missing since there is no Top-Up loaded for this user.
Line 45: Line 45:
 {{ :2021:profile_top_up2.png?nolink |}} {{ :2021:profile_top_up2.png?nolink |}}
  
 +
 +===== 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.
 +{{:2021:top_up1.png?nolink|}}
 +  * **Transaction History** tab
 +{{:2021:top_up2.png?nolink|}}
 +
 +===== 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>
 +<?php 
 +
 +print("RADIUSdesk API to Add a TopUp for a Permanent user");
 +/*
 + 
 +    * = required
 + 
 +    == Adding a 1Gb Data top-up ==
 + 
 +    comment             One Gb data (optional)
 +    *data_unit             gb (options 'mb' or 'gb')
 +    *permanent_user_id 187 (alternatively you can use 'permanent_user = <permanent user's username>' to avoid lookup for ID)
 +    *token             52190fff-a800-48eb-b1f2-478bc0a80167 (root user's token)
 +    *type             data (other options are 'time' or 'days_to_use')
 +    *value             1 (the amount of data/time or days_to_use)
 +    *user_id                0 (keep zero to make the owner the owner of the token)
 + 
 +    == Adding a 50 minutes Time top-up ==
 + 
 +    comment             50 minutes Time (optional)
 +    *time_unit             minutes (options 'minutes' or 'hours' or 'days')
 +    *permanent_user_id     187 (alternatively you can use 'permanent_user = <permanent user's username>' to avoid lookup for ID)
 +    *sel_language     4_4
 +    *token             52190fff-a800-48eb-b1f2-478bc0a80167 (root user's token)
 +    *type             time (other options are 'time' or 'days_to_use')
 +    *value             1 (the amount of data/time or days_to_use)
 +    *user_id                0 (keep zero to make the owner the owner of the token)
 + 
 +*/
 + 
 +$comment             = 'Two Gb data';
 +$data_unit             = 'gb'; 
 +$permanent_user_id   = 187; 
 +$permanent_user        = 'dvdwalt';
 +$token                     = '52190fff-a800-48eb-b1f2-478bc0a80167';
 +$user_id                      = 0; //The owner is the owner of the token
 +$type                           = 'data'; 
 +$value                     = 2;
 + 
 +$url                        = 'http://127.0.0.1/cake3/rd_cake/top-ups/add.json';
 + 
 +// The data to send to the API
 +$postData = array(
 +    'comment'               => $comment,
 +    'data_unit'             => $data_unit,
 +    //'permanent_user_id'     => $permanent_user_id,
 +    'permanent_user'        => $permanent_user,
 +    'token'                 => $token,
 +    'user_id'               => $user_id,
 +    'type'                  => $type,
 +    'value'                 => $value
 +);
 + 
 +// Setup cURL
 +$ch = curl_init($url);
 +curl_setopt_array($ch, array(
 + 
 +    CURLOPT_POST            => TRUE,
 +    CURLOPT_RETURNTRANSFER  => TRUE,
 +    CURLOPT_HTTPHEADER => array(
 +        'Content-Type: application/json'
 +    ),
 +    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, TRUE);
 +print_r($responseData);
 +
 +?>
 +</file>