Reduce Shopify integration steps and make sure checks work.

This commit is contained in:
Kukks 2020-09-21 12:36:09 +02:00
parent f352399428
commit 078a2d7e39
4 changed files with 9 additions and 8 deletions

View file

@ -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;

View file

@ -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; }
}

View file

@ -70,7 +70,7 @@ namespace BTCPayServer.Services.Shopify
public async Task<string[]> 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<JToken>()
.Select(token => token["handle"].Value<string>()).ToArray();
}

View file

@ -1,7 +1,7 @@
@model IntegrationsViewModel
@{
var shopify = Model.Shopify;
var shopifyCredsSet = shopify?.CredentialsValid == true;
var shopifyCredsSet = shopify?.IntegratedAt.HasValue is true;
}
<script>
function promptExampleUrl(){
@ -21,7 +21,7 @@ function promptExampleUrl(){
</h4>
@if (!shopifyCredsSet)
{
<p class="alert alert-info">Create a Shopify private app with the permission "Script tags - Read and write" then <a href="#" class="alert-link" onclick="promptExampleUrl()">click here and paste the provided example URL.</a></p>
<p class="alert alert-info">Create a Shopify private app with the permissions "Script tags - Read and write" and "Orders - Read and write" then <a href="#" class="alert-link" onclick="promptExampleUrl()">click here and paste the provided example URL.</a></p>
<input type="hidden" id="exampleUrl" name="exampleUrl">
}
<div class="form-group">
@ -61,7 +61,7 @@ function promptExampleUrl(){
{
<button name="command" type="submit" class="btn btn-primary" value="ShopifySaveCredentials">Save Credentials</button>
}
else if (shopify?.IntegratedAt.HasValue == true)
else
{
<p class="alert alert-success">
Orders on <b>@shopify.ShopName</b>.myshopify.com will be marked as paid on successful invoice payment.