Guest User

Subscriber Module

a guest
Jun 19th, 2020
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. local subscriptions = {}
  2.  
  3. local DS = game:GetService("DataStoreService"):GetDataStore("SubscriptionStorage")
  4. local HTTP = game:GetService("HttpService")
  5.  
  6. --Authorization--
  7. local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  8.  
  9. function enc(data)
  10.     return ((data:gsub('.', function(x)
  11.         local r,b='',x:byte()
  12.         for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
  13.         return r;
  14.     end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
  15.         if (#x < 6) then return '' end
  16.         local c=0
  17.         for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
  18.         return b:sub(c+1,c+1)
  19.     end)..({ '', '==', '=' })[#data%3+1])
  20. end
  21.  
  22.  
  23. local userName = game:GetService("ServerStorage").SubscriptionsUsername.Value
  24. local password = game:GetService("ServerStorage").SubscriptionsPassword.Value
  25. local AuthorizationBase64String = enc(userName..":"..password)
  26.  
  27. --Main Functions--
  28.  
  29. --Create New Subscription--
  30. function subscriptions.Create(playerID, validFor, indentityName)   
  31.     local creationTable = {
  32.         plrID = playerID,
  33.         subscriptionName = indentityName,
  34.         validDays = validFor,
  35.         gameID = game.GameId,
  36.         Cancelled = false
  37.     }
  38.    
  39.     local jsonTableToSend = HTTP:JSONEncode(creationTable)
  40.    
  41.     local Status = HTTP:PostAsync("https://subscriber-roblox.herokuapp.com/create-subscription", jsonTableToSend, Enum.HttpContentType.ApplicationJson, false, { ["Authorization"] =  "Basic "..AuthorizationBase64String })
  42.     return Status
  43. end
  44.  
  45. --Retrieve A Subscription--
  46. function subscriptions.Retrieve(playerID, indentityName)
  47.     local gID = game.GameId
  48.    
  49.     local Status = HTTP:GetAsync("https://subscriber-roblox.herokuapp.com/retrieve-subscription/"..gID.."/"..indentityName.."/"..playerID, true, { ["Authorization"] =  "Basic "..AuthorizationBase64String })
  50.     return Status
  51. end
  52.  
  53. --Cancel A Subscription--
  54. function subscriptions.Cancel(playerID, indentityName) 
  55.     local creationTable = {
  56.         plrID = playerID,
  57.         subscriptionName = indentityName,
  58.         gameID = game.GameId,
  59.         Cancelled = true
  60.     }
  61.    
  62.     local jsonTableToSend = HTTP:JSONEncode(creationTable)
  63.    
  64.     local Status = HTTP:PostAsync("https://subscriber-roblox.herokuapp.com/cancel-subscription", jsonTableToSend, Enum.HttpContentType.ApplicationJson, false,{ ["Authorization"] =  "Basic "..AuthorizationBase64String })
  65.     return Status
  66. end
  67.  
  68. return subscriptions
Add Comment
Please, Sign In to add comment