From 078a2d7e392ad5b1443dd74087428b6f7924ffad Mon Sep 17 00:00:00 2001 From: Kukks Date: Mon, 21 Sep 2020 12:36:09 +0200 Subject: [PATCH] Reduce Shopify integration steps and make sure checks work. --- BTCPayServer/Controllers/StoresController.Integrations.cs | 7 +++++-- BTCPayServer/Services/Shopify/Models/ShopifySettings.cs | 2 -- BTCPayServer/Services/Shopify/ShopifyApiClient.cs | 2 +- BTCPayServer/Views/Stores/Integrations/Shopify.cshtml | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.Integrations.cs b/BTCPayServer/Controllers/StoresController.Integrations.cs index e5a84f6f9..ec960e892 100644 --- a/BTCPayServer/Controllers/StoresController.Integrations.cs +++ b/BTCPayServer/Controllers/StoresController.Integrations.cs @@ -116,8 +116,6 @@ namespace BTCPayServer.Controllers return View("Integrations", vm); } - shopify.CredentialsValid = true; - var scopesGranted = await apiClient.CheckScopes(); if (!scopesGranted.Contains("read_orders") || !scopesGranted.Contains("write_script_tags")) { @@ -125,6 +123,11 @@ namespace BTCPayServer.Controllers "Please grant the private app permissions for read_orders, write_script_tags"; return View("Integrations", vm); } + var result = await apiClient.CreateScript(Url.Action("ShopifyJavascript", "Stores", + new {storeId = CurrentStore.Id}, Request.Scheme)); + + shopify.ScriptId = result.ScriptTag?.Id.ToString(CultureInfo.InvariantCulture); + shopify.IntegratedAt = DateTimeOffset.Now; var blob = CurrentStore.GetStoreBlob(); blob.Shopify = shopify; diff --git a/BTCPayServer/Services/Shopify/Models/ShopifySettings.cs b/BTCPayServer/Services/Shopify/Models/ShopifySettings.cs index e7216afcf..59ea917ee 100644 --- a/BTCPayServer/Services/Shopify/Models/ShopifySettings.cs +++ b/BTCPayServer/Services/Shopify/Models/ShopifySettings.cs @@ -17,8 +17,6 @@ namespace BTCPayServer.Services.Shopify.Models !string.IsNullOrWhiteSpace(ApiKey) && !string.IsNullOrWhiteSpace(Password); } - - public bool CredentialsValid { get; set; } public DateTimeOffset? IntegratedAt { get; set; } public string ScriptId { get; set; } } diff --git a/BTCPayServer/Services/Shopify/ShopifyApiClient.cs b/BTCPayServer/Services/Shopify/ShopifyApiClient.cs index 5da3df3ac..9ba4c412e 100644 --- a/BTCPayServer/Services/Shopify/ShopifyApiClient.cs +++ b/BTCPayServer/Services/Shopify/ShopifyApiClient.cs @@ -70,7 +70,7 @@ namespace BTCPayServer.Services.Shopify public async Task CheckScopes() { - var req = CreateRequest(_credentials.ShopName, HttpMethod.Delete, null, "admin/oauth/access_scopes.json"); + var req = CreateRequest(_credentials.ShopName, HttpMethod.Get, null, "admin/oauth/access_scopes.json"); return JObject.Parse(await SendRequest(req))["access_scopes"].Values() .Select(token => token["handle"].Value()).ToArray(); } diff --git a/BTCPayServer/Views/Stores/Integrations/Shopify.cshtml b/BTCPayServer/Views/Stores/Integrations/Shopify.cshtml index 2c56a5778..ef5bd6157 100644 --- a/BTCPayServer/Views/Stores/Integrations/Shopify.cshtml +++ b/BTCPayServer/Views/Stores/Integrations/Shopify.cshtml @@ -1,7 +1,7 @@ @model IntegrationsViewModel @{ var shopify = Model.Shopify; - var shopifyCredsSet = shopify?.CredentialsValid == true; + var shopifyCredsSet = shopify?.IntegratedAt.HasValue is true; }