Skip to content

Commit

Permalink
Fixes #88
Browse files Browse the repository at this point in the history
Thanks @Glen5641 for the find
  • Loading branch information
byter10 committed Jun 30, 2020
1 parent 8846b07 commit 45e6d50
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
24 changes: 24 additions & 0 deletions Source/ChargifyDotNet.Tests/CouponTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ public void Coupon_Read()
Assert.IsTrue(result.Amount == (Convert.ToDecimal(result.AmountInCents)/100));
Assert.AreEqual(result.ID, couponID);
}

[TestMethod]
public void Coupon_Read_Percentage()
{
// Arrange
var productFamily = Chargify.GetProductFamilyList().Values.FirstOrDefault();
if (productFamily == null) Assert.Inconclusive("A valid product family could not be found.");
var coupons = Chargify.GetAllCoupons(productFamily.ID);
var coupon = coupons.FirstOrDefault(c => c.Value.Percentage > 0).Value;
var couponID = coupon.ID;

// Act
var result = Chargify.LoadCoupon(productFamily.ID, couponID);

// Assert
Assert.IsNotNull(result);
Assert.IsTrue(result.Percentage != decimal.MinValue);
Assert.IsTrue(result.Percentage > 0);
Assert.AreEqual(coupon.Percentage, result.Percentage);
Assert.AreEqual(result.ID, couponID);

TestContext.WriteLine($"Coupon percentage: {coupon.Percentage}");
}

[TestMethod]
public void Coupon_Create()
{
Expand Down
2 changes: 1 addition & 1 deletion Source/ChargifyDotNet/ChargifyConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3896,7 +3896,7 @@ public ICoupon UpdateCoupon(ICoupon coupon)
/// <param name="durationPeriodCount">How long does the coupon last?</param>
/// <param name="endDate">At what point will the coupon no longer be valid?</param>
/// <returns></returns>
private string BuildCouponXml(int productFamilyId, string name, string code, string description, decimal amount, int percentage, bool allowNegativeBalance,
private string BuildCouponXml(int productFamilyId, string name, string code, string description, decimal amount, decimal percentage, bool allowNegativeBalance,
bool recurring, int durationPeriodCount, DateTime endDate)
{
// make sure data is valid
Expand Down
8 changes: 4 additions & 4 deletions Source/ChargifyDotNet/Coupon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void LoadFromJson(JsonObject obj)
_durationPeriodCount = obj.GetJSONContentAsInt(key);
break;
case PercentageKey:
_percentage = obj.GetJSONContentAsInt(key);
_percentage = obj.GetJSONContentAsDecimal(key);
break;
case RecurringKey:
_isRecurring = obj.GetJSONContentAsBoolean(key);
Expand Down Expand Up @@ -232,7 +232,7 @@ private void LoadFromNode(XmlNode couponNode)
_durationPeriodCount = dataNode.GetNodeContentAsInt();
break;
case PercentageKey:
_percentage = dataNode.GetNodeContentAsInt();
_percentage = dataNode.GetNodeContentAsDecimal();
break;
case RecurringKey:
_isRecurring = dataNode.GetNodeContentAsBoolean();
Expand Down Expand Up @@ -386,12 +386,12 @@ public int DurationPeriodCount
/// <summary>
/// If percentage based, the percentage. Int.MinValue otherwise.
/// </summary>
public int Percentage
public decimal Percentage
{
get { return _percentage; }
set { _percentage = value; }
}
private int _percentage = int.MinValue;
private decimal _percentage = decimal.MinValue;

/// <summary>
/// Is this a recurring coupon?
Expand Down
4 changes: 2 additions & 2 deletions Source/ChargifyDotNet/Interfaces/ICoupon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public interface ICoupon : IComparable<ICoupon>
int DurationPeriodCount { get; set; }

/// <summary>
/// If percentage based, the percentage. Int.MinValue otherwise.
/// If percentage based, the percentage. decimal.MinValue otherwise.
/// </summary>
int Percentage { get; set; }
decimal Percentage { get; set; }

/// <summary>
/// Is this a recurring coupon?
Expand Down

0 comments on commit 45e6d50

Please sign in to comment.