Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
Created February 18, 2016 20:47
Show Gist options
  • Select an option

  • Save ScottDeLuzio/04a4f21febeac0d66cb3 to your computer and use it in GitHub Desktop.

Select an option

Save ScottDeLuzio/04a4f21febeac0d66cb3 to your computer and use it in GitHub Desktop.
Software Licensing for Excel Add-In Check License Status
'json response from Software Licensing in the following format
'{"success":true,"license":"valid","item_name":"Download Product Name","expires":"lifetime","payment_id":"54224","customer_name":"John Doe","customer_email":"john@sample.com","license_limit":1,"site_count":1,"activations_left":0}
Sub httpRequestCheck()
'use to check license once when workbook opens
Dim oRequest As Object
Const cUrl As String = "https://yoursite.com/?edd_action=check_license&item_name=Name of the Download Product&license="
URL = cUrl & ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", URL
oRequest.Send
ThisWorkbook.Worksheets("Sheet1").Range("A2:A4").ClearContents
ThisWorkbook.Worksheets("Sheet1").Range("A2").Value = oRequest.ResponseText
'The MID and FIND functions allow for searching through the json object for certain terms (license and activations_left) then return a certain number of characters after it.
'MID will start at the first character of the word in FIND, offset a number of characters (10 for license), then return a number of characters after (8 for the word inactive, 5 for valid, etc.).
'2x Double quotes are needed to enter formulas this way, so "license" wouldn't work but ""license"" will.
ThisWorkbook.Worksheets("Sheet1").Range("A3").Formula = "=IF(MID($A$2,FIND(""license"",$A$2,1)+10,8)=""inactive"",""inactive"",IF(MID($A$2,FIND(""license"",$A$2,1)+10,5)=""valid"",""valid"",IF(MID($A$2,FIND(""license"",$A$2,1)+10,7)=""invalid"",""invalid"","""")))"
ThisWorkbook.Worksheets("Sheet1").Range("A4").Formula = "=MID($A$2,FIND(""activations_left"",$A$2,1)+18,1)"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment