99 * and the API as published by Ubiquiti:
1010 * https://www.ubnt.com/downloads/unifi/5.2.9/unifi_sh_api
1111 *
12- * VERSION: 1.0.8
12+ * VERSION: 1.0.9
1313 *
1414 * NOTES:
1515 * - this Class will only work with UniFi Controller versions 4.x and higher. There are no checks to prevent
2727 *
2828 */
2929
30- define ('API_CLASS_VERSION ' , '1.0.8 ' );
30+ define ('API_CLASS_VERSION ' , '1.0.9 ' );
3131
3232class unifiapi {
3333 public $ user = '' ;
@@ -921,27 +921,26 @@ public function list_hotspotop() {
921921 /**
922922 * Create voucher(s)
923923 * -----------------
924- * returns an array of vouchers codes (NOTE: without the "-" in the middle) by calling the stat_voucher method
924+ * returns an array of voucher codes (NOTE: without the "-" in the middle) by calling the stat_voucher method
925925 * required parameter <minutes> = minutes the voucher is valid after activation
926- * required parameter <number_of_vouchers_to_create>
926+ * optional parameter <number_of_vouchers_to_create> = number of vouchers to create, default value is 1
927+ * optional parameter <quota> = single-use or multi-use vouchers, string value '0' is for multi-use, '1' is for single-use
927928 * optional parameter <note> = note text to add to voucher when printing
928929 * optional parameter <up> = upload speed limit in kbps
929930 * optional parameter <down> = download speed limit in kbps
930931 * optional parameter <MBytes> = data transfer limit in MB
931932 */
932- public function create_voucher ($ minutes , $ number_of_vouchers_to_create = 1 , $ note = NULL , $ up = NULL , $ down = NULL , $ MBytes = NULL ) {
933+ public function create_voucher ($ minutes , $ number_of_vouchers_to_create = 1 , $ quota = ' 0 ' , $ note = NULL , $ up = NULL , $ down = NULL , $ MBytes = NULL ) {
933934 if (!$ this ->is_loggedin ) return FALSE ;
934935 $ return = array ();
935- $ json = array ('cmd ' => 'create-voucher ' , 'expire ' => $ minutes , 'n ' => $ number_of_vouchers_to_create );
936-
936+ $ json = array ('cmd ' => 'create-voucher ' , 'expire ' => $ minutes , 'n ' => $ number_of_vouchers_to_create , 'quota ' => $ quota );
937937 /**
938938 * if we have received values for note/up/down/MBytes we append them to the payload array to be submitted
939939 */
940940 if (isset ($ note )) $ json ['note ' ] = trim ($ note );
941941 if (isset ($ up )) $ json ['up ' ] = $ up ;
942942 if (isset ($ down )) $ json ['down ' ] = $ down ;
943943 if (isset ($ MBytes )) $ json ['bytes ' ] = $ MBytes ;
944-
945944 $ json = json_encode ($ json );
946945 $ content_decoded = json_decode ($ this ->exec_curl ($ this ->baseurl .'/api/s/ ' .$ this ->site .'/cmd/hotspot ' ,'json= ' .$ json ));
947946 if ($ content_decoded ->meta ->rc == 'ok ' ) {
@@ -955,6 +954,25 @@ public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $not
955954 return $ return ;
956955 }
957956
957+ /**
958+ * Revoke voucher
959+ * --------------
960+ * return TRUE on success
961+ * required parameter <voucher_id> = _id of the voucher to revoke
962+ */
963+ public function revoke_voucher ($ voucher_id ) {
964+ if (!$ this ->is_loggedin ) return FALSE ;
965+ $ return = FALSE ;
966+ $ json = json_encode (array ('_id ' => $ voucher_id , 'cmd ' => 'delete-voucher ' ));
967+ $ content_decoded = json_decode ($ this ->exec_curl ($ this ->baseurl .'/api/s/ ' .$ this ->site .'/cmd/hotspot ' ,'json= ' .$ json ));
968+ if (isset ($ content_decoded ->meta ->rc )) {
969+ if ($ content_decoded ->meta ->rc == 'ok ' ) {
970+ $ return = TRUE ;
971+ }
972+ }
973+ return $ return ;
974+ }
975+
958976 /**
959977 * List port forwarding stats
960978 * --------------------------
0 commit comments