Integration with woocomerce
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Integration with woocomerce
Hi
I am interested in integrating my AHK scripts to the woocommerce software license manager
they have web api listed at
https://woosoftwarelicense.com/document ... i-methods/
I have basic AutoHotKey scripting skills.
Initially I would just like to be able to check for a valid license every couple of months.
Cheers
Kevin
I am interested in integrating my AHK scripts to the woocommerce software license manager
they have web api listed at
https://woosoftwarelicense.com/document ... i-methods/
I have basic AutoHotKey scripting skills.
Initially I would just like to be able to check for a valid license every couple of months.
Cheers
Kevin
Re: Integration with woocomerce
Hi Kevin,
so you want to secure your (compiled) AHK scripts with this? Are you aware that it is not very complicated to extract the source code from a standard AHK-exe file and strip such license checks from it? (code compressors might make it more difficult but also might raise the likelihood of false positives from anti-virus software)
Anyway... I think, the provided code example is not unambigous or complete (they are using functions whose defintions are not shown). If they are using a URL Query String , the command URLDownloadToFile (or its user function cousin URLDownloadToVar) , used with the constructed URL string could be already enough to use the API.
But without the "[a]dditional code examples [..] included within the plugin download" it is just a guess, based on the vague description they provide. For handling the JSON response of the API call, there are a few functions available on this forum. I usually use Coco's JSON lib for parsing such API responses.
so you want to secure your (compiled) AHK scripts with this? Are you aware that it is not very complicated to extract the source code from a standard AHK-exe file and strip such license checks from it? (code compressors might make it more difficult but also might raise the likelihood of false positives from anti-virus software)
Anyway... I think, the provided code example is not unambigous or complete (they are using functions whose defintions are not shown). If they are using a URL Query String , the command URLDownloadToFile (or its user function cousin URLDownloadToVar) , used with the constructed URL string could be already enough to use the API.
But without the "[a]dditional code examples [..] included within the plugin download" it is just a guess, based on the vague description they provide. For handling the JSON response of the API call, there are a few functions available on this forum. I usually use Coco's JSON lib for parsing such API responses.
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
Hi Gregstar
Thanks for the input.
I had found this for a code obfuscator
https://github.com/davidmalia/autohotkey-obfuscator
AV false positives I will have to live with
Unless there is a better way... I will get the extension setup.
Thanks for the input.
I had found this for a code obfuscator
https://github.com/davidmalia/autohotkey-obfuscator
AV false positives I will have to live with
Unless there is a better way... I will get the extension setup.
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
Right, more reading...
Found AutoHotkey_H v2 Alpha and working my way through that
Found AutoHotkey_H v2 Alpha and working my way through that
Re: Integration with woocomerce
For "obfuscating" the code, use AHK source code Encryptor v1.6 By FeiYue:
https://autohotkey.com/boards/viewtopic ... or#p204668
https://autohotkey.com/boards/viewtopic ... or#p204668
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
Right, more reading...
Found AutoHotkey_H v2 Alpha and working my way through that... this is oo coding... wow
back to version1
Found AutoHotkey_H v2 Alpha and working my way through that... this is oo coding... wow
back to version1
Re: Integration with woocomerce
For anyone that may need it, here is a WooCommerce Software License API testing utility I developed.
Code: Select all
;--------------------------------------------------------------------------------------------------------------------
; WooCommerce Software Licence API test
; https://woosoftwarelicense.com/documentation/api-methods/
; AutoHotKey - https://www.autohotkey.com/ (free and open source software)
;
; activate
; This method allows a license key to be synchronized with your software for activation.
; woo_sl_action='activate'
; licence_key
; product_unique_id
; domain
;
; deactivate
; This method facilitate a licence key de-activation. Once de-activated a key is released from being set as used status, and it can be integrated with another domain / hash.
; woo_sl_action='deactivate'
; licence_key
; product_unique_id
; domain
;
; status-check
; The status-check API method allow a certain software key to be verified for being still active, valid, assigned to a certain domain.
; woo_sl_action='status-check'
; licence_key
; product_unique_id
; domain
;
; plugin_update
; The plugin_update API method return basic details regarding software update. The following arguments are required for a call:
; woo_sl_action='plugin_update'
; licence_key
; product_unique_id
; domain
; version
;--------------------------------------------------------------------------------------------------------------------
Global slURL :="http://YourDomainWhereSoftwareManagement.com/index.php"
Global woo_sl_action :=""
Global licence_key :=""
Global product_unique_id :=""
Global domain :=""
Global version :=""
Global Actions :="activate|deactivate|status-check|plugin_update|theme_update|plugin_information|code_version|key_delete"
Global Action# :=3
Global ResponseMsg :=""
Gui, API:+AlwaysOnTop -DPIScale
Gui, API:Color, 0x99CCFF
Gui, API:Add, Text, x025 y025 w080 h20 +0x200 , API Action:
Gui, API:Add, DropDownList, x100 y025 w120 AltSubmit Choose3 vAction# gCheckAction, %Actions%
Gui, API:Add, Text, x025 y050 w080 h20 +0x200 , URL:
Gui, API:Add, Edit, x100 y050 w250 h20 vslURL , %slURL%
Gui, API:Add, Text, x025 y075 w080 h20 +0x200 , Product ID:
Gui, API:Add, Edit, x100 y075 w250 h20 vproduct_unique_id , %product_unique_id%
Gui, API:Add, Text, x025 y100 w080 h20 +0x200 , Licence Key:
Gui, API:Add, Edit, x100 y100 w250 h20 vlicence_key , %licence_key%
Gui, API:Add, Text, x025 y125 w080 h20 +0x200 , Domain:
Gui, API:Add, Edit, x100 y125 w250 h20 vdomain , %domain%
Gui, API:Add, Text, x025 y150 w080 h20 +0x200 , Version:
Gui, API:Add, Edit, x100 y150 w250 h20 vversion , %Version%
GuiControl, API:Disable, version
Gui, API:Add, Edit, x025 y175 w500 h220 vResponseMsg , %ResponseMsg%
Gui, API:Add, Button, x225 y405 w80 h30 Default gAPIaction, GO
Gui, API:show, x100 y100 w550 h450, WooCommerce Software Licence API calls
return
CheckAction(){
GuiControlGet, Action#, API:
Switch Action#
{
Case 4, 5, 6: ; plugin_update, theme_update, plugin_information
GuiControl, API:Enable, licence_key
GuiControl, API:Enable, domain
GuiControl, API:Enable, version
Case 7: ; code_version
GuiControl, API:Disable, licence_key
GuiControl, API:Disable, domain
GuiControl, API:Disable, version
Case 8: ; key_delete
GuiControl, API:Enable, licence_key
GuiControl, API:Disable, domain
GuiControl, API:Disable, version
Default:
GuiControl, API:Enable, licence_key
GuiControl, API:Enable, domain
GuiControl, API:Disable, version
}
}
APIaction(){
GuiControlGet, apiURL, API:
GuiControlGet, Action#, API:
Switch Action#
{
Case (1): woo_sl_action := "activate"
Case (2): woo_sl_action := "deactivate"
Case (3): woo_sl_action := "status-check"
Case (4): woo_sl_action := "plugin_update"
Case (5): woo_sl_action := "theme_update"
Case (6): woo_sl_action := "plugin_information"
Case (7): woo_sl_action := "code_version"
Case (8): woo_sl_action := "key_delete"
}
GuiControlGet, licence_key, API:
GuiControlGet, product_unique_id, API:
GuiControlGet, domain, API:
GuiControlGet, version, API:
URL := slURL "?woo_sl_action=" woo_sl_action "&product_unique_id=" product_unique_id
Switch woo_sl_action
{
Case "activate", "deactivate", "status-check":
URL := URL "&licence_key=" licence_key "&domain=" domain
Case "plugin_update", "theme_update", "plugin_information":
URL := URL "&licence_key=" licence_key "&version=" version "&domain=" domain
Case "code_version":
Case "key_delete":
URL := URL "&licence_key=" licence_key
}
ResponseMsg := % URL
;MsgBox, % "URL:" URL
lObj := URLDownloadtoString(URL)
;MsgBox, % "LicenceObj: " lObj
if (lObj = "" or lObj = "[]")
ResponseMsg := ResponseMsg "`n`nNo response to API call"
else
FormatResponseMsg(lObj)
GuiControl, API:, ResponseMsg, %ResponseMsg%
return
APIGuiEscape:
APIGuiClose:
Gui, API:Destroy
ExitApp
return
}
ExitApp
FormatResponseMsg(lObj){
lObj := LTrim(lObj, OmitChars := " `[")
lObj := RTrim(lObj, OmitChars := " `]")
lr := JsonToAHK(lObj)
;lObj := JsonToAHK(URLDownloadtoVar(URL))
ResponseMsg := ResponseMsg "`n`nReturned: " lObj "`n`nStatus: " lr.status "`nStatus Code: " lr.status_code "`nMessage: " lr.message
Switch Action#
{
Case 1, 3: ; activate, status-check
ResponseMsg := ResponseMsg "`nLicence Status: " lr.licence_status "`nLicence Start: " lr.licence_start "`nLicence Expire: " lr.licence_expire
Case 2: ; deactivate
Case 4, 5: ; plugin_update, theme_update
ResponseMsg := ResponseMsg "`nNew Version: " lr.message.new_version "`nDate: " lr.message.date "`nPackage: " lr.message.package "`nUpgrade Notice: " lr.message.upgrade_notice "`nAuthor: " lr.message.author "`nTested: " lr.message.tested "`nHomepage: " lr.message.homepage "`nURL: " lr.message.url
Case 6: ; plugin_information
ResponseMsg := ResponseMsg "`nName: " lr.message.name "`nVersion: " lr.message.version "`nLast Update: " lr.message.last_updated "`nPackage: " lr.message.package "`nDownload Link: " lr.message.download_link "`nUpgrade Notice: " lr.message.upgrade_notice "`nAuthor: " lr.message.author "`nTested: " lr.message.tested "`nRequires: " lr.message.requires "`nHomepage: " lr.message.homepage "`nDescription: " lr.message.sections.description "`nBanners Low: " lr.message.sections.banners.low "`nBanners High: " lr.message.sections.banners.high
Case 7: ; code_version
ResponseMsg := ResponseMsg "`nName: " lr.message.name "`nVersion: " lr.message.version "`nLast Update: " lr.message.last_updated "`nUpgrade Notice: " lr.message.upgrade_notice "`nAuthor: " lr.message.author "`nTested: " lr.message.tested "`nRequires: " lr.message.requires "`nHomepage: " lr.message.homepage "`nDescription: " lr.message.sections.description "`nBanners Low: " lr.message.sections.banners.low "`nBanners High: " lr.message.sections.banners.high
Case 8: ; key_delete
}
}
URLDownloadtoString(url, encoding = "utf-8")
{
static a := "AutoHotkey/" A_AhkVersion
if (!DllCall("LoadLibrary", "str", "wininet") || !(h := DllCall("wininet\InternetOpen", "str", a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr")))
return 0
c := s := 0, o := ""
if (f := DllCall("wininet\InternetOpenUrl", "ptr", h, "str", url, "ptr", 0, "uint", 0, "uint", 0x80003000, "ptr", 0, "ptr"))
{
while (DllCall("wininet\InternetQueryDataAvailable", "ptr", f, "uint*", s, "uint", 0, "ptr", 0) && s > 0)
{
VarSetCapacity(b, s, 0)
DllCall("wininet\InternetReadFile", "ptr", f, "ptr", &b, "uint", s, "uint*", r)
o .= StrGet(&b, r >> (encoding = "utf-16" || encoding = "cp1200"), encoding)
}
DllCall("wininet\InternetCloseHandle", "ptr", f)
}
DllCall("wininet\InternetCloseHandle", "ptr", h)
return o
}
JsonToAHK(json, rec := false){
static doc := ComObjCreate("htmlfile")
, __ := doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
, JS := doc.parentWindow
if !rec
obj := JsonToAHK(JS.eval("(" . json . ")"), true)
else if !IsObject(json)
obj := json
else if json.toString() != "[object Object]" {
obj := []
Loop % json.length
obj.Push( JsonToAHK(json[A_Index - 1], true) )
}
else {
obj := {}
keys := JS.Object.keys(json)
Loop % keys.length {
k := keys[A_Index - 1]
obj[k] := JsonToAHK(json[k], true)
}
}
Return obj
}
;---------------------------------------------------------------------------------------------------------------------
;~ //the url where the WooCommerce Software Licence plugin is being installed
;~ define('SL_APP_API_URL', 'http://YourDomainWhereSoftwareManagement.com/index.php');
;~ //the Software Unique ID as defined within product admin page
;~ define('SL_PRODUCT_ID', 'APTO');
;~ $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
;~ define('SL_INSTANCE', str_replace($protocol, "", get_bloginfo('wpurl')));
;~ ----------------------------------
;~ $args = array(
;~ 'woo_sl_action' => 'activate',
;~ 'licence_key' => $licence_key,
;~ 'product_unique_id' => SL_PRODUCT_ID,
;~ 'domain' => SL_INSTANCE
;~ );
;~ $request_uri = SL_APP_API_URL . '?' . http_build_query( $args );
;~ $data = wp_remote_get( $request_uri );
;~ if(is_wp_error( $data ) || $data['response']['code'] != 200)
;~ {
;~ //there was a problem establishing a connection to the API server
;~ }
;~ $data_body = json_decode($data['body']);
;~ if(isset($data_body->status))
;~ {
;~ if( $response_block->status == 'success' && ( $response_block->status_code == 's100' || $response_block->status_code == 's101' ) )
;~ {
;~ //the licence is active and the software is active
;~ //doing further actions like saving the licence and allow the plugin to run
;~ }
;~ else
;~ {
;~ //there was a problem activating the licence
;~ }
;~ }
;~ else
;~ {
;~ //there was a problem establishing a connection to the API server
;~ }
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
thanks epete, this is brilliant.
I have been away for a couple of years, now getting back on it.
I have been away for a couple of years, now getting back on it.
-
- Posts: 188
- Joined: 08 Jul 2019, 05:37
- Contact:
Re: Integration with woocomerce
Code: Select all
url := ; "your api request url which should have the parameters like status or activate or deactivate etc"
HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpObj.Open("GET", url, false)
HttpObj.Send()
MsgBox, % HttpObj.Responsetext ; Response in json
objt := JsonToAHK(HttpObj.Responsetext) ; converting json to Ahk and store into variable so you could do what ever you want with the response you get
return
JsonToAHK(json, rec := false) {
static doc := ComObjCreate("htmlfile")
, __ := doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
, JS := doc.parentWindow
if !rec
obj := %A_ThisFunc%(JS.eval("(" . json . ")"), true)
else if !IsObject(json)
obj := json
else if JS.Object.prototype.toString.call(json) == "[object Array]" {
obj := []
Loop % json.length
obj.Push( %A_ThisFunc%(json[A_Index - 1], true) )
}
else {
obj := {}
keys := JS.Object.keys(json)
Loop % keys.length {
k := keys[A_Index - 1]
obj[k] := %A_ThisFunc%(json[k], true)
}
}
Return obj
}
return
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
Hi Epete
I have just got my licensing domain up and working and your script works a treat, thank you
I have just got my licensing domain up and working and your script works a treat, thank you
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
I dont really understand the code from Epete or the code for the client side to run in myapp.
I can make the https request from my browser to my wc site, license status is ok.
but not been able to get a client side, myapp working yet.
The code displays an error message with the option to continue or cancel on the ComObjCreate line.
My aim for when myapp is first run is to activate the licence and write / append a valid license to an ini file.
and when myapp is run, check the inifile for a valid days left to run
I also like the way lintalist offers a help page at start up and want to include that trick.
I can make the https request from my browser to my wc site, license status is ok.
but not been able to get a client side, myapp working yet.
The code displays an error message with the option to continue or cancel on the ComObjCreate line.
My aim for when myapp is first run is to activate the licence and write / append a valid license to an ini file.
and when myapp is run, check the inifile for a valid days left to run
I also like the way lintalist offers a help page at start up and want to include that trick.
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
yea, the client myapp works, it was my typo causing the issue thank you for your contributions
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
How do I use objt?
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
The http json response is [{"status":"success","status_code":"s101","message":"Licence Key was Already Activated for ","licence_status":"active","licence_start":"2022-08-31","licence_expire":"2022-09-14"}]
but I am at a loss how to get these into variables for use in ahk.
from the code example above
objt := JsonToAHK(HttpObj.Responsetext) ; converting json to Ahk and store into variable so you could do what ever you want with the response you get
how do you use objt?
but I am at a loss how to get these into variables for use in ahk.
from the code example above
objt := JsonToAHK(HttpObj.Responsetext) ; converting json to Ahk and store into variable so you could do what ever you want with the response you get
how do you use objt?
Re: Integration with woocomerce
I'd guess the way you're accessing an array... bc you're not storing it within a variable but an object...
Code: Select all
objt := [{"status":"success","status_code":"s101","message":"Licence Key was Already Activated for ","licence_status":"active","licence_start":"2022-08-31","licence_expire":"2022-09-14"}]
MsgBox % objt[1].status
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
thank you for that insight.
so I revisited Epete's code and he strips out the [] square braces
[Mod edit: [code][/code] tags added.]
so I revisited Epete's code and he strips out the [] square braces
Code: Select all
lobj := HttpObj.Responsetext
lobj := LTrim(lObj, OmitChars := " `[")
lobj := RTrim(lObj, OmitChars := " `]")
MsgBox, % lobj - displays correctly
lobjt := JsonToAHK(lobj)
MsgBox, % lobjt - displays blank
-
- Posts: 12
- Joined: 05 Mar 2018, 08:14
Re: Integration with woocomerce
got it.
found this post viewtopic.php?f=76&t=75949
found this post viewtopic.php?f=76&t=75949