Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ table 30102 "Shpfy Shop"
begin
Store := GetStoreName();
if Store <> '' then
AuthenticationMgt.InstallShopifyApp(Store);
AuthenticationMgt.InstallShopifyApp(Store, Rec);
end;

internal procedure HasAccessToken(): Boolean
Expand Down Expand Up @@ -892,6 +892,11 @@ table 30102 "Shpfy Shop"
Store := Store.TrimStart('/').TrimEnd('/');
end;

internal procedure SetStoreName(Store: Text)
begin
Rec.Validate("Shopify URL", Store);
end;

/// <summary>
/// Calc Shop Id.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ codeunit 30199 "Shpfy Authentication Mgt."
end;

[NonDebuggable]
internal procedure InstallShopifyApp(InstalllToStore: Text)
internal procedure InstallShopifyApp(InstallToStore: Text; var Shop: Record "Shpfy Shop")
var
OAuth2: Codeunit "OAuth2";
ShopifyAuthentication: Page "Shpfy Authentication";
Expand All @@ -79,15 +79,23 @@ codeunit 30199 "Shpfy Authentication Mgt."
InstallURLTxt: Label 'https://%1/admin/oauth/authorize?scope=%2&redirect_uri=%3&state=%4&grant_options[]=%5', Comment = '%1 = Store, %2 = Scope, %3 = RedirectUrl, %4 = State, %5 = GrantOptions', Locked = true;
InstallURLWithClientIdParamTok: Label '%1&client_id=%2', Comment = '%1 = InstallURLTxt, %2 = ClientId', Locked = true;
NotMatchingStateErr: Label 'The state parameter value does not match.';
StoreMismatchLbl: Label 'The store URL returned from Shopify differs from the URL you entered. You can find your store''s internal URL in Shopify Admin under Domains settings. Do you want to update the store URL to match?';
begin
OAuth2.GetDefaultRedirectURL(RedirectUrl);
State := Random(999);
Url := StrSubstNo(InstallURLTxt, InstalllToStore, GetScope(), RedirectUrl, State, GrandOptionsTxt);
Url := StrSubstNo(InstallURLTxt, InstallToStore, GetScope(), RedirectUrl, State, GrandOptionsTxt);
FullUrl := StrSubstNo(InstallURLWithClientIdParamTok, Url, GetClientId());
ShopifyAuthentication.SetOAuth2Properties(FullUrl);
Commit();
ShopifyAuthentication.RunModal();
Store := ShopifyAuthentication.Store();

if Store <> InstallToStore then
if Confirm(StoreMismatchLbl) then
Shop.SetStoreName(Store)
else
Error('');

AuthorizationCode := ShopifyAuthentication.GetAuthorizationCode();
if AuthorizationCode.IsEmpty() then
if ShopifyAuthentication.GetAuthError() <> '' then
Expand Down
Loading