-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nozzlegear/ShopifyChargeService
ShopifyChargeService: Create, get, list and activate one-time app charges.
- Loading branch information
Showing
23 changed files
with
554 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_creating_a_charge_with_trial::should_create_a_charge_with_trial" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_listing_charges::should_retrieve_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_activating_a_charge::should_activate_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_deleting_a_charge::should_delete_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_retrieving_a_charge::should_retrieve_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_creating_a_charge_with_no_trial::should_create_a_charge_with_no_trial" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_listing_charges::should_retrieve_a_list_of_charges" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_creating_a_charge::should_create_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_deleting_a_charge::should_delete_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_listing_charges::should_retrieve_a_list_of_charges" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_creating_a_charge::should_create_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_retrieving_a_charge::should_retrieve_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_activating_a_charge::should_activate_a_charge" /></Playlist> | ||
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.ShopifyChargeService_Tests.When_listing_charges::should_retrieve_a_list_of_charges" /><Add Test="ShopifySharp.Tests.ShopifyChargeService_Tests.When_activating_a_charge::should_activate_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyChargeService_Tests.When_retrieving_a_charge::should_retrieve_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyChargeService_Tests.When_creating_a_charge::should_create_a_charge" /></Playlist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<Playlist Version="1.0"><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_creating_a_charge_with_trial::should_create_a_charge_with_trial" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_listing_charges::should_retrieve_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_activating_a_charge::should_activate_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_deleting_a_charge::should_delete_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_retrieving_a_charge::should_retrieve_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_creating_a_charge_with_no_trial::should_create_a_charge_with_no_trial" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_listing_charges::should_retrieve_a_list_of_charges" /><Add Test="ShopifySharp.Tests.ShopifyBillingService_Tests.When_creating_a_charge::should_create_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_deleting_a_charge::should_delete_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_listing_charges::should_retrieve_a_list_of_charges" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_creating_a_charge::should_create_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_retrieving_a_charge::should_retrieve_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_activating_a_charge::should_activate_a_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_activating_a_recurring_charge::should_activate_a_recurring_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_retrieving_a_recurring_charge::should_retrieve_a_recurring_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_deleting_a_recurring_charge::should_delete_a_recurring_charge" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_listing_recurring_charges::should_retrieve_a_list_of_recurring_charges" /><Add Test="ShopifySharp.Tests.ShopifyRecurringChargeService_Tests.When_creating_a_recurring_charge::should_create_a_recurring_charge" /></Playlist> |
50 changes: 50 additions & 0 deletions
50
ShopifySharp.Tests/ShopifyChargeService Tests/When_activating_a_charge.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyChargeService_Tests | ||
{ | ||
[Subject(typeof(ShopifyChargeService))] | ||
class When_activating_a_charge | ||
{ | ||
Establish context = () => | ||
{ | ||
// NOTE: Creating a charge will fail if the access token used is for a private app. | ||
// Only real apps can use the Shopify billing API. | ||
Service = new ShopifyChargeService(Utils.BillingMyShopifyUrl, Utils.BillingAccessToken); | ||
Charge = Service.CreateAsync(new ShopifyCharge() | ||
{ | ||
Name = "Lorem Ipsum Single Charge", | ||
Price = 123.45, | ||
Test = true, | ||
ReturnUrl = "http://localhost:5445/shopify/chargeresult/?attemptedChargeId=" + Guid.NewGuid().ToString() | ||
}).Await().AsTask.Result; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Service.ActivateAsync(Charge.Id.Value).Await(); | ||
Charge = Service.GetAsync(Charge.Id.Value).Await().AsTask.Result; | ||
}; | ||
|
||
It should_activate_a_charge = () => | ||
{ | ||
// NOTE: This test will require you to set a break point after creating the charge but before activating it, | ||
// grab the confirmation url and manually accept it, then continue the test. | ||
Charge.Status.ShouldEqual(Enums.ShopifyChargeStatus.Active); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
//Charges cannot be deleted. | ||
}; | ||
|
||
static ShopifyChargeService Service; | ||
|
||
static ShopifyCharge Charge; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
ShopifySharp.Tests/ShopifyChargeService Tests/When_creating_a_charge.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyChargeService_Tests | ||
{ | ||
[Subject(typeof(ShopifyChargeService))] | ||
class When_creating_a_charge | ||
{ | ||
Establish context = () => | ||
{ | ||
Service = new ShopifyChargeService(Utils.BillingMyShopifyUrl, Utils.BillingAccessToken); | ||
Charge = new ShopifyCharge() | ||
{ | ||
Name = "Lorem Ipsum Single Charge", | ||
Price = 123.45, | ||
Test = true | ||
}; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
// NOTE: Creating a charge will fail if the access token used is for a private app. | ||
// Only real apps can use the Shopify billing API. | ||
Charge = Service.CreateAsync(Charge).Await().AsTask.Result; | ||
}; | ||
|
||
It should_create_a_charge = () => | ||
{ | ||
Charge.ConfirmationUrl.ShouldNotBeNull(); | ||
Charge.Price.ShouldEqual(123.45); | ||
Charge.Test.ShouldBeTrue(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
//Charges cannot be deleted. | ||
}; | ||
|
||
static ShopifyChargeService Service; | ||
|
||
static ShopifyCharge Charge; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
ShopifySharp.Tests/ShopifyChargeService Tests/When_listing_charges.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyChargeService_Tests | ||
{ | ||
[Subject(typeof(ShopifyChargeService))] | ||
class When_listing_charges | ||
{ | ||
Establish context = () => | ||
{ | ||
// NOTE: Creating a charge will fail if the access token used is for a private app. | ||
// Only real apps can use the Shopify billing API. | ||
Service = new ShopifyChargeService(Utils.BillingMyShopifyUrl, Utils.BillingAccessToken); | ||
ChargeId = Service.CreateAsync(new ShopifyCharge() | ||
{ | ||
Name = "Lorem Ipsum Single Charge", | ||
Price = 123.45, | ||
Test = true, | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Charges = Service.ListAsync().Await().AsTask.Result; | ||
}; | ||
|
||
It should_retrieve_a_list_of_charges = () => | ||
{ | ||
Charges.ShouldNotBeNull(); | ||
Charges.Count().ShouldBeGreaterThanOrEqualTo(1); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
//Charges cannot be deleted. | ||
}; | ||
|
||
static ShopifyChargeService Service; | ||
|
||
static IEnumerable<ShopifyCharge> Charges; | ||
|
||
static long ChargeId; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
ShopifySharp.Tests/ShopifyChargeService Tests/When_retrieving_a_charge.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Machine.Specifications; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp.Tests.ShopifyChargeService_Tests | ||
{ | ||
[Subject(typeof(ShopifyChargeService))] | ||
class When_retrieving_a_charge | ||
{ | ||
Establish context = () => | ||
{ | ||
// NOTE: Creating a charge will fail if the access token used is for a private app. | ||
// Only real apps can use the Shopify billing API. | ||
Service = new ShopifyChargeService(Utils.BillingMyShopifyUrl, Utils.BillingAccessToken); | ||
ChargeId = Service.CreateAsync(new ShopifyCharge() | ||
{ | ||
Name = "Lorem Ipsum Single Charge", | ||
Price = 123.45, | ||
Test = true, | ||
}).Await().AsTask.Result.Id.Value; | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
Charge = Service.GetAsync(ChargeId).Await().AsTask.Result; | ||
}; | ||
|
||
It should_retrieve_a_charge = () => | ||
{ | ||
Charge.ShouldNotBeNull(); | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
//Charges cannot be deleted. | ||
}; | ||
|
||
static ShopifyChargeService Service; | ||
|
||
static ShopifyCharge Charge; | ||
|
||
static long ChargeId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Newtonsoft.Json.Converters; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using ShopifySharp.Enums; | ||
|
||
namespace ShopifySharp.Converters | ||
{ | ||
/// <summary> | ||
/// A custom enum converter for <see cref="ShopifyChargeStatus"/> enums which sets the default value | ||
/// to <see cref="ShopifyChargeStatus.Unknown"/> when the value is null or does not exist. | ||
/// </summary> | ||
public class ShopifyChargeConverter : StringEnumConverter | ||
{ | ||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
ShopifyChargeStatus parsed; | ||
|
||
if (!Enum.TryParse(reader.Value?.ToString() ?? "", true, out parsed)) | ||
{ | ||
return ShopifyChargeStatus.Unknown; | ||
} | ||
|
||
return parsed; | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
if (value == null || | ||
!Enum.IsDefined(typeof(ShopifyChargeStatus), value) || | ||
(Enum.IsDefined(typeof(ShopifyChargeStatus), value) && ((ShopifyChargeStatus)value) == ShopifyChargeStatus.Unknown)) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
base.WriteJson(writer, value, serializer); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.