fix shopify settings

This commit is contained in:
Kukks 2022-02-25 10:31:37 +01:00 committed by Andrew Camilleri
parent eb2a887f77
commit 30d0410b49
4 changed files with 76 additions and 93 deletions

View file

@ -4,7 +4,6 @@ using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Extensions;
using BTCPayServer.Abstractions.Models;
using BTCPayServer.Models;
using BTCPayServer.Models.ServerViewModels;
using BTCPayServer.Storage.Models;
using BTCPayServer.Storage.Services.Providers.AmazonS3Storage;
@ -17,12 +16,9 @@ using BTCPayServer.Storage.Services.Providers.GoogleCloudStorage;
using BTCPayServer.Storage.Services.Providers.GoogleCloudStorage.Configuration;
using BTCPayServer.Storage.Services.Providers.Models;
using BTCPayServer.Storage.ViewModels;
using BTCPayServer.Views;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Controllers

View file

@ -8,7 +8,11 @@ namespace BTCPayServer.Plugins.Shopify.Models
{
[Display(Name = "Shop Name")]
public string ShopName { get; set; }
[Display(Name = "Api Key (Apps->Develop Apps-> Create app)")]
public string ApiKey { get; set; }
[Display(Name = "Api Secret Key")]
public string Password { get; set; }
public bool CredentialsPopulated()

View file

@ -214,31 +214,8 @@ namespace BTCPayServer.Plugins.Shopify
[HttpPost("stores/{storeId}/integrations/shopify")]
public async Task<IActionResult> EditShopifyIntegration(string storeId,
ShopifySettings vm, string command = "", string exampleUrl = "")
ShopifySettings vm, string command = "")
{
if (!string.IsNullOrEmpty(exampleUrl))
{
try
{
//https://{apikey}:{password}@{hostname}/admin/api/{version}/{resource}.json
var parsedUrl = new Uri(exampleUrl);
var userInfo = parsedUrl.UserInfo.Split(":");
vm = new ShopifySettings()
{
ApiKey = userInfo[0],
Password = userInfo[1],
ShopName = parsedUrl.Host.Replace(".myshopify.com", "",
StringComparison.InvariantCultureIgnoreCase)
};
command = "ShopifySaveCredentials";
}
catch (Exception)
{
TempData[WellKnownTempData.ErrorMessage] = "The provided Example Url was invalid.";
return View(vm);
}
}
switch (command)
{
case "ShopifySaveCredentials":

View file

@ -10,76 +10,82 @@
<partial name="_StatusMessage"/>
<h2 class="mt-1 mb-4">
@ViewData["Title"]
<small>
<a href="https://docs.btcpayserver.org/Shopify" target="_blank" rel="noreferrer noopener">
<span class="fa fa-question-circle-o text-secondary" title="More information..."></span>
</a>
</small>
</h2>
<form method="post" id="shopifyForm">
@if (!shopifyCredsSet)
{
<p class="alert alert-info">Create a Shopify Private App with the permissions "Orders - Read and write"</p>
<div class="form-group">
<label class="form-label" for="exampleUrl">Example Url from Shopify Private App</label>
<input class="form-control" id="exampleUrl" name="exampleUrl">
</div>
<div class="row">
<div class="col-xxl-constrain col-xl-8">
<h3 class="mb-3">
@ViewData["Title"]
<small>
<a href="https://docs.btcpayserver.org/Shopify" target="_blank" rel="noreferrer noopener">
<span class="fa fa-question-circle-o text-secondary" title="More information..."></span>
</a>
</small>
</h3>
<p>Connect BTCPay Server to your Shopify checkout experience to accept Bitcoin.</p>
<button name="command" type="submit" class="btn btn-primary mt-3" value="ShopifySaveCredentials">Connect to Shopify</button>
}
else
{
<div class="form-group">
<label asp-for="ShopName" class="form-label"></label>
<div class="input-group">
@if (!Model?.ShopName?.Contains(".") is true)
{
<span class="input-group-text">https://</span>
}
<input asp-for="ShopName" class="form-control" readonly="@shopifyCredsSet"/>
@if (!ViewContext.ModelState.IsValid)
{
<div asp-validation-summary="All" class="text-danger"></div>
}
@if (!Model?.ShopName?.Contains(".") is true)
{
<span class="input-group-text">.myshopify.com</span>
}
<form method="post" id="shopifyForm">
<div class="form-group">
<label asp-for="ShopName" class="form-label"></label>
<div class="input-group">
@if (!Model?.ShopName?.Contains(".") is true)
{
<span class="input-group-text">https://</span>
}
<input asp-for="ShopName" class="form-control" readonly="@shopifyCredsSet"/>
@if (!shopifyCredsSet || !Model?.ShopName?.Contains(".") is true)
{
<span class="input-group-text">.myshopify.com</span>
}
</div>
<span asp-validation-for="ShopName" class="text-danger"></span>
</div>
<span asp-validation-for="ShopName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ApiKey" class="form-label"></label>
<input asp-for="ApiKey" class="form-control" readonly="@shopifyCredsSet"/>
<span asp-validation-for="ApiKey" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ApiKey" class="form-label"></label>
<input asp-for="ApiKey" class="form-control" readonly="@shopifyCredsSet"/>
<span asp-validation-for="ApiKey" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Password" class="form-label"></label>
<input asp-for="Password" class="form-control" type="password" value="@Model?.Password" readonly="@shopifyCredsSet"/>
<span asp-validation-for="Password" class="text-danger"></span>
</div>
<div class="alert alert-warning">
<p>
In Shopify please paste following script at <a href="@shopifyUrl/admin/settings/checkout#PolarisTextField1" target="_blank" class="fw-bold" rel="noreferrer noopener"> Settings &gt; Checkout &gt; Order Processing &gt; Additional Scripts</a>
</p>
<kbd style="display: block; word-break: break-all;">
@($"<script src='{Url.Action("ShopifyJavascript", "UIShopify", new { storeId = Context.GetRouteValue("storeId") }, Context.Request.Scheme)}'></script>")
</kbd>
</div>
<p class="alert alert-warning">
In Shopify please add a payment method at <a target="_blank" href="@shopifyUrl/admin/settings/payments" class="fw-bold" rel="noreferrer noopener"> Settings &gt; Payments &gt; Manual Payment Methods</a> with the name <kbd>Bitcoin with BTCPay Server</kbd>
</p>
<div class="form-group">
<label asp-for="Password" class="form-label"></label>
<input asp-for="Password" class="form-control" type="password" value="@Model?.Password" readonly="@shopifyCredsSet"/>
<span asp-validation-for="Password" class="text-danger"></span>
</div>
<p class="alert alert-success">
Orders on <b>@Model.ShopName</b>.myshopify.com will be marked as paid on successful invoice payment.
Started: @Model.IntegratedAt.Value.ToBrowserDate()
</p>
@if (shopifyCredsSet)
{
<div class="alert alert-warning">
<p>
In Shopify please paste following script at <a href="@shopifyUrl/admin/settings/checkout#PolarisTextField1" target="_blank" class="fw-bold" rel="noreferrer noopener"> Settings &gt; Checkout &gt; Order Processing &gt; Additional Scripts</a>
</p>
<kbd style="display: block; word-break: break-all;" class="bg-dark">
@($"<script src='{Url.Action("ShopifyJavascript", "UIShopify", new { storeId = Context.GetRouteValue("storeId") }, Context.Request.Scheme)}'></script>")
</kbd>
</div>
<p class="alert alert-warning">
In Shopify please add a payment method at <a target="_blank" href="@shopifyUrl/admin/settings/payments" class="fw-bold" rel="noreferrer noopener"> Settings &gt; Payments &gt; Manual Payment Methods</a> with the name <kbd class="bg-dark">Bitcoin with BTCPay Server</kbd>
</p>
<p class="alert alert-success">
Orders on <b>@Model.ShopName</b>.myshopify.com will be marked as paid on successful invoice payment.
Started: @Model.IntegratedAt.Value.ToBrowserDate()
</p>
<button name="command" type="submit" class="btn btn-danger mt-3" value="ShopifyClearCredentials">
Stop Shopify calls and clear credentials
</button>
}
</form>
<button name="command" type="submit" class="btn btn-danger mt-3" value="ShopifyClearCredentials">
Stop Shopify calls and clear credentials
</button>
}
else
{
<button name="command" type="submit" class="btn btn-primary mt-3" value="ShopifySaveCredentials">
Save
</button>
}
</form>
</div>
</div>