这是indexloc提供的服务,不要输入任何密码
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
28 changes: 20 additions & 8 deletions ShopifySharp.Tests/ShopifyPayments_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,41 @@ public class ShopifyPayments_Tests
[Fact]
public async Task GetBalance()
{
var balances = await _Service.GetBalanceAsync();
Assert.NotNull(balances);
if (await _Service.IsShopifyPaymentAPIEnabled())
{
var balances = await _Service.GetBalanceAsync();
Assert.NotNull(balances);
}
}

[Fact]
public async Task GetPayouts()
{
var payouts = await _Service.ListPayoutsAsync();
Assert.NotNull(payouts);
if (await _Service.IsShopifyPaymentAPIEnabled())
{
var payouts = await _Service.ListPayoutsAsync();
Assert.NotNull(payouts);
}
}

[Fact]
public async Task GetDisputes()
{
var disputes = await _Service.ListDisputesAsync();
Assert.NotNull(disputes);
if (await _Service.IsShopifyPaymentAPIEnabled())
{
var disputes = await _Service.ListDisputesAsync();
Assert.NotNull(disputes);
}
}

[Fact]
public async Task GetTransactions()
{
var transactions = await _Service.ListTransactionsAsync();
Assert.NotNull(transactions);
if (await _Service.IsShopifyPaymentAPIEnabled())
{
var transactions = await _Service.ListTransactionsAsync();
Assert.NotNull(transactions);
}
}
}
}
19 changes: 19 additions & 0 deletions ShopifySharp/Services/ShopifyPayments/ShopifyPaymentsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using ShopifySharp.Infrastructure;
using ShopifySharp.Filters;
using System.Net;

namespace ShopifySharp
{
Expand All @@ -18,6 +19,24 @@ public class ShopifyPaymentsService : ShopifyService
/// <param name="shopAccessToken">An API access token for the shop.</param>
public ShopifyPaymentsService(string myShopifyUrl, string shopAccessToken) : base(myShopifyUrl, shopAccessToken) { }

/// <summary>
/// Checks whether the Shopify Payments API is enabled on this store.
/// If not enabled, all Shopify Payments API endpoints will return HTTP 404 / Not Found
/// </summary>
public virtual async Task<bool> IsShopifyPaymentAPIEnabled()
{
try
{
//calling any method endpoint would do, but choosing GetBalance because it is likely the most lightweight
await this.GetBalanceAsync();
return true;
}
catch (ShopifyException ex) when (ex.HttpStatusCode == HttpStatusCode.NotFound)
{
return false;
}
}

/// <summary>
/// Gets a count of all of the shop's transactions.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp/ShopifySharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netcoreapp2.1;netstandard1.4;net45</TargetFrameworks>
<AssemblyName>ShopifySharp</AssemblyName>
<RootNamespace>ShopifySharp</RootNamespace>
<Version>4.19.1</Version>
<Version>4.19.2</Version>
</PropertyGroup>
<PropertyGroup>
<Description>ShopifySharp is a C# and .NET library that helps developers easily authenticate with and manage Shopify stores.</Description>
Expand Down