Skip to content

Commit

Permalink
Renames, bugfixes, push to v20
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyVyska committed Jun 5, 2022
1 parent 669dcdd commit 6384af6
Show file tree
Hide file tree
Showing 20 changed files with 569 additions and 461 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"CRS.FileNamePattern": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
"CRS.FileNamePatternExtensions": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
"CRS.FileNamePatternPageCustomizations": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
"CRS.OnSaveAlFileAction": "Reorganize",
"CRS.RenameWithGit": false,
"CRS.ObjectNamePrefix": "SPBPL ",
"al.ruleSetPath": "./ruleset.json",
Expand Down
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publisher": "Spare Brained Ideas AB",
"brief": "This library helps other Extensions verify a current subscription license.",
"description": "This library helps other Extensions verify a current subscription license.",
"version": "1.0.0.0",
"version": "1.1.0.0",
"privacyStatement": "https://sparebrained.com/appsource/privacystatement",
"EULA": "https://sparebrained.com/appsource/eula",
"help": "https://sparebrained.com/support",
Expand All @@ -14,7 +14,7 @@
"dependencies": [],
"screenshots": [],
"platform": "1.0.0.0",
"application": "19.0.0.0",
"application": "20.0.0.0",
"idRanges": [
{
"from": 71033,
Expand Down
121 changes: 121 additions & 0 deletions src/codeunit/SPBLICExtensionRegistration.Codeunit.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
codeunit 71034 "SPBPL Extension Registration"
{
Permissions = tabledata "SPBPL Extension License" = RIM;
procedure RegisterExtension(
AppInfo: ModuleInfo;
newProductCode: Text[100];
newProductUrl: Text[250];
newSupportUrl: Text[250];
newBillingEmail: Text[250];
newVersionURL: Text[250];
newUpdateNewsURL: Text[250];
daysAllowedBeforeActivationProd: Integer;
daysAllowedBeforeActivationSandbox: Integer;
minimumLicensingAppVersion: Version;
licensePlatform: Enum "SPBPL License Platform";
forceUpdate: Boolean)
begin
RegisterExtension(AppInfo,
AppInfo.Id,
'',
newProductCode,
newProductUrl,
newSupportUrl,
newBillingEmail,
newVersionURL,
newUpdateNewsURL,
daysAllowedBeforeActivationProd,
daysAllowedBeforeActivationSandbox,
minimumLicensingAppVersion,
licensePlatform,
forceUpdate);
end;

procedure RegisterExtension(
AppInfo: ModuleInfo;
SubModuleId: Guid;
SubModuleName: Text[100];
newProductCode: Text[100];
newProductUrl: Text[250];
newSupportUrl: Text[250];
newBillingEmail: Text[250];
newVersionURL: Text[250];
newUpdateNewsURL: Text[250];
daysAllowedBeforeActivationProd: Integer;
daysAllowedBeforeActivationSandbox: Integer;
minimumLicensingAppVersion: Version;
licensePlatform: Enum "SPBPL License Platform";
forceUpdate: Boolean)
var
SPBExtensionLicense: Record "SPBPL Extension License";
SPBLicenseManagement: Codeunit "SPBPL License Management";
SPBIsoStoreManager: Codeunit "SPBPL IsoStore Manager";
EnvironmentInformation: Codeunit "Environment Information";
PlusDaysTok: Label '<+%1D>', Comment = '%1 is the number of days ';
GraceEndDate: Date;
GraceDays: Integer;
begin
if minimumLicensingAppVersion > Version.Create('1.0.0.0') then
SPBLicenseManagement.CheckSupportedVersion(minimumLicensingAppVersion);

if EnvironmentInformation.IsOnPrem() or EnvironmentInformation.IsProduction() then
GraceDays := daysAllowedBeforeActivationProd
else
GraceDays := daysAllowedBeforeActivationSandbox;
if GraceDays > 0 then
GraceEndDate := CalcDate(StrSubstNo(PlusDaysTok, daysAllowedBeforeActivationProd), Today)
else
GraceEndDate := Today;

if (SPBExtensionLicense.Get(SubModuleId)) then begin
if forceUpdate then begin
SPBExtensionLicense."Submodule Name" := SubModuleName;
SPBExtensionLicense."Extension Name" := CopyStr(AppInfo.Name, 1, MaxStrLen(SPBExtensionLicense."Extension Name"));
SPBExtensionLicense."Product Code" := newProductCode;
SPBExtensionLicense."Product URL" := newProductUrl;
SPBExtensionLicense."Support URL" := newSupportUrl;
SPBExtensionLicense."Billing Support Email" := newBillingEmail;
SPBExtensionLicense."Version Check URL" := newVersionURL;
SPBExtensionLicense."Update News URL" := newUpdateNewsURL;
SPBExtensionLicense."Sandbox Grace Days" := daysAllowedBeforeActivationSandbox;
SPBExtensionLicense.Modify();
end;
end else begin

SPBExtensionLicense."Entry Id" := SubModuleId;
SPBExtensionLicense."Submodule Name" := SubModuleName;
SPBExtensionLicense."Extension App Id" := AppInfo.Id;
SPBExtensionLicense."Extension Name" := CopyStr(AppInfo.Name, 1, MaxStrLen(SPBExtensionLicense."Extension Name"));
SPBExtensionLicense."Product Code" := newProductCode;
SPBExtensionLicense."Product URL" := newProductUrl;
SPBExtensionLicense."Support URL" := newSupportUrl;
SPBExtensionLicense."Billing Support Email" := newBillingEmail;
SPBExtensionLicense."Version Check URL" := newVersionURL;
SPBExtensionLicense."Update News URL" := newUpdateNewsURL;
SPBExtensionLicense."Installed At" := CurrentDateTime();
SPBExtensionLicense."Trial Grace End Date" := GraceEndDate;
SPBExtensionLicense."Sandbox Grace Days" := daysAllowedBeforeActivationSandbox;
SPBExtensionLicense.Insert();
end;
SPBIsoStoreManager.SetAppValue(SPBExtensionLicense, 'installDate', Format(CurrentDateTime, 0, 9));
SPBIsoStoreManager.SetAppValue(SPBExtensionLicense, 'preactivationDays', Format(GraceDays));
end;

procedure CheckIfActive(SubscriptionId: Guid; InactiveShowError: Boolean): Boolean
var
SPBExtensionLicense: Record "SPBPL Extension License";
SPBLicenseManagement: Codeunit "SPBPL License Management";
NoSubFoundErr: Label 'No License was found in the Licenses list for SubscriptionId: %1';
SubscriptionInactiveErr: Label 'The License for %1 is not Active. Contact your system administrator to re-activate it.', Comment = '%1 is the name of the Extension.';
IsActive: Boolean;
begin
if not SPBExtensionLicense.get(SubscriptionId) then
if GuiAllowed() then
Error(NoSubFoundErr, SubscriptionId);
IsActive := SPBLicenseManagement.CheckIfActive(SPBExtensionLicense);
if not IsActive and InactiveShowError then
if GuiAllowed() then
Error(SubscriptionInactiveErr, SPBExtensionLicense."Extension Name");
exit(IsActive);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
{

var
GumroadVerifyAPITok: Label 'https://api.gumroad.com/v2/licenses/verify?product_permalink=%1&license_key=%2&increment_uses_count=%3', Comment = '%1 %2 %3';
GumroadVerifyAPITok: Label 'https://api.gumroad.com/v2/licenses/verify?product_permalink=%1&license_key=%2&increment_uses_count=%3', Comment = '%1 %2 %3', Locked = true;

procedure CallAPIForVerification(var SPBPLExtensionLicense: Record "SPBPL Extension License"; var ResponseBody: Text; IncrementLicenseCount: Boolean) ResultOK: Boolean
procedure CallAPIForVerification(var SPBExtensionLicense: Record "SPBPL Extension License"; var ResponseBody: Text; IncrementLicenseCount: Boolean) ResultOK: Boolean
var
NAVAppSetting: Record "NAV App Setting";
EnvInformation: Codeunit "Environment Information";
ApiHttpClient: HttpClient;
ApiHttpRequestMessage: HttpRequestMessage;
ApiHttpResponseMessage: HttpResponseMessage;
Expand All @@ -28,7 +29,7 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
NAVAppSetting.Insert();
end;

VerifyAPI := StrSubstNo(GumroadVerifyAPITok, SPBPLExtensionLicense."Product Code", SPBPLExtensionLicense."License Key", Format(IncrementLicenseCount, 0, 9));
VerifyAPI := StrSubstNo(GumroadVerifyAPITok, SPBExtensionLicense."Product Code", SPBExtensionLicense."License Key", Format(IncrementLicenseCount, 0, 9));
ApiHttpRequestMessage.SetRequestUri(VerifyAPI);
ApiHttpRequestMessage.Method('POST');

Expand All @@ -49,15 +50,15 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
end;


procedure ReportPossibleMisuse(SPBPLExtensionLicense: Record "SPBPL Extension License")
procedure ReportPossibleMisuse(SPBExtensionLicense: Record "SPBPL Extension License")
begin
// Potential future use of 'reporting' misuse attempts. For example, someone programmatically changing the Subscription Record

OnAfterThrowPossibleMisuse(SPBPLExtensionLicense);
OnAfterThrowPossibleMisuse(SPBExtensionLicense);
end;

#pragma warning disable AA0150 // TODO - Passed as "var" for the interface
procedure PopulateSubscriptionFromResponse(var SPBPLExtensionLicense: Record "SPBPL Extension License"; var ResponseBody: Text)
procedure PopulateSubscriptionFromResponse(var SPBExtensionLicense: Record "SPBPL Extension License"; var ResponseBody: Text)
#pragma warning restore AA0150
var
TempJsonBuffer: Record "JSON Buffer" temporary;
Expand All @@ -67,7 +68,7 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
GumroadToken: JsonToken;
ActivationFailureErr: Label 'An error occured validating the license. Contact %1 for assistance', Comment = '%1 is the App Publisher';
begin
NavApp.GetModuleInfo(SPBPLExtensionLicense."Entry Id", AppInfo);
NavApp.GetModuleInfo(SPBExtensionLicense."Extension App Id", AppInfo);
GumroadJson.ReadFrom(ResponseBody);
GumroadJson.Get('success', GumroadToken);
if not GumroadToken.AsValue().AsBoolean() then
Expand All @@ -78,27 +79,27 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
TempJsonBuffer.ReadFromText(ResponseBody);

// Update the current Subscription record
SPBPLExtensionLicense.Validate(Activated, true);
SPBExtensionLicense.Validate(Activated, true);
TempJsonBuffer.GetPropertyValue(TempPlaceholder, 'license_key');
SPBPLExtensionLicense."License Key" := CopyStr(TempPlaceholder, 1, MaxStrLen(SPBPLExtensionLicense."License Key"));
SPBExtensionLicense."License Key" := CopyStr(TempPlaceholder, 1, MaxStrLen(SPBExtensionLicense."License Key"));
TempJsonBuffer.GetPropertyValue(TempPlaceholder, 'created_at');
Evaluate(SPBPLExtensionLicense."Created At", TempPlaceholder);
Evaluate(SPBExtensionLicense."Created At", TempPlaceholder);
TempJsonBuffer.GetPropertyValue(TempPlaceholder, 'subscription_ended_at');
Evaluate(SPBPLExtensionLicense."Subscription Ended At", TempPlaceholder);
Evaluate(SPBExtensionLicense."Subscription Ended At", TempPlaceholder);
TempJsonBuffer.GetPropertyValue(TempPlaceholder, 'subscription_cancelled_at');
Evaluate(SPBPLExtensionLicense."Subscription Cancelled At", TempPlaceholder);
Evaluate(SPBExtensionLicense."Subscription Cancelled At", TempPlaceholder);
TempJsonBuffer.GetPropertyValue(TempPlaceholder, 'subscription_failed_at');
Evaluate(SPBPLExtensionLicense."Subscription Failed At", TempPlaceholder);
Evaluate(SPBExtensionLicense."Subscription Failed At", TempPlaceholder);

TempJsonBuffer.GetPropertyValue(TempPlaceholder, 'email');
SPBPLExtensionLicense."Subscription Email" := CopyStr(TempPlaceholder, 1, MaxStrLen(SPBPLExtensionLicense."Subscription Email"));
SPBPLExtensionLicense.CalculateEndDate();
SPBExtensionLicense."Subscription Email" := CopyStr(TempPlaceholder, 1, MaxStrLen(SPBExtensionLicense."Subscription Email"));
SPBExtensionLicense.CalculateEndDate();
end;

procedure CheckAPILicenseCount(var SPBPLExtensionLicense: Record "SPBPL Extension License"; ResponseBody: Text): Boolean
procedure CheckAPILicenseCount(var SPBExtensionLicense: Record "SPBPL Extension License"; ResponseBody: Text): Boolean
var
TempJsonBuffer: Record "JSON Buffer" temporary;
GumroadSPBPLLicenseUtilities: Codeunit "SPBPL License Utilities";
GumroadSPBLicenseUtilities: Codeunit "SPBPL License Utilities";
LicenseUses: Integer;
LicenseCount: Integer;
AppInfo: ModuleInfo;
Expand All @@ -107,13 +108,13 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
GumroadErr: Label 'An error occured validating the license. Contact %1 for assistance', Comment = '%1 is the App Publisher';
begin
// The 'Test' product, we never do a Count check on this application
if SPBPLExtensionLicense."Entry Id" = GumroadSPBPLLicenseUtilities.GetTestProductAppId() then
if SPBExtensionLicense."Entry Id" = GumroadSPBLicenseUtilities.GetTestProductAppId() then
exit(true);

GumroadJson.ReadFrom(ResponseBody);
GumroadJson.Get('success', GumroadToken);
if not GumroadToken.AsValue().AsBoolean() then begin
NavApp.GetModuleInfo(SPBPLExtensionLicense."Entry Id", AppInfo);
NavApp.GetModuleInfo(SPBExtensionLicense."Extension App Id", AppInfo);
if GuiAllowed() then
Error(GumroadErr, AppInfo.Publisher);
end;
Expand All @@ -134,7 +135,7 @@ codeunit 71035 "SPBPL Gumroad Communicator" implements "SPBPL ILicenseCommunicat
end;

[IntegrationEvent(false, false)]
local procedure OnAfterThrowPossibleMisuse(SPBPLExtensionLicense: Record "SPBPL Extension License")
local procedure OnAfterThrowPossibleMisuse(SPBExtensionLicense: Record "SPBPL Extension License")
begin
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ codeunit 71038 "SPBPL IsoStore Manager"
var
EnvironmentInformation: Codeunit "Environment Information";
CryptographyManagement: Codeunit "Cryptography Management";
NameMapTok: Label '%1-%2', Comment = '%1 %2';
NameMapTok: Label '%1-%2', Comment = '%1 %2', Locked = true;

internal procedure SetAppValue(SPBPLExtensionLicense: Record "SPBPL Extension License"; StoreName: Text; StoreValue: Text)
internal procedure SetAppValue(SPBExtensionLicense: Record "SPBPL Extension License"; StoreName: Text; StoreValue: Text)
begin
if not IsolatedStorage.Contains(SPBPLExtensionLicense."Entry Id") then
IsolatedStorage.Set(SPBPLExtensionLicense."Entry Id", '', DataScope::Module);
if not IsolatedStorage.Contains(SPBExtensionLicense."Entry Id") then
IsolatedStorage.Set(SPBExtensionLicense."Entry Id", '', DataScope::Module);

if EnvironmentInformation.IsOnPrem() then
if CryptographyManagement.IsEncryptionEnabled() and CryptographyManagement.IsEncryptionPossible() then
Expand All @@ -18,18 +18,18 @@ codeunit 71038 "SPBPL IsoStore Manager"
if GuiAllowed() then
Error('To use Spare Brained Licensing On-Prem, Database Encryption must be enabled.');

IsolatedStorage.Set(StrSubstNo(NameMapTok, SPBPLExtensionLicense."Entry Id", StoreName), StoreValue, DataScope::Module);
IsolatedStorage.Set(StrSubstNo(NameMapTok, SPBExtensionLicense."Entry Id", StoreName), StoreValue, DataScope::Module);
end;

internal procedure GetAppValue(SPBPLExtensionLicense: Record "SPBPL Extension License"; StoreName: Text) ReturnValue: Text
internal procedure GetAppValue(SPBExtensionLicense: Record "SPBPL Extension License"; StoreName: Text) ReturnValue: Text
begin
IsolatedStorage.Get(StrSubstNo(NameMapTok, SPBPLExtensionLicense."Entry Id", StoreName), DataScope::Module, ReturnValue);
IsolatedStorage.Get(StrSubstNo(NameMapTok, SPBExtensionLicense."Entry Id", StoreName), DataScope::Module, ReturnValue);
if EnvironmentInformation.IsOnPrem() and CryptographyManagement.IsEncryptionEnabled() and CryptographyManagement.IsEncryptionPossible() then
ReturnValue := CryptographyManagement.Decrypt(ReturnValue);
end;

internal procedure ContainsAppValue(SPBPLExtensionLicense: Record "SPBPL Extension License"; StoreName: Text): Boolean
internal procedure ContainsAppValue(SPBExtensionLicense: Record "SPBPL Extension License"; StoreName: Text): Boolean
begin
exit(IsolatedStorage.Contains(StrSubstNo(NameMapTok, SPBPLExtensionLicense."Entry Id", StoreName), DataScope::Module));
exit(IsolatedStorage.Contains(StrSubstNo(NameMapTok, SPBExtensionLicense."Entry Id", StoreName), DataScope::Module));
end;
}
Loading

0 comments on commit 6384af6

Please sign in to comment.