Skip to content

Commit

Permalink
Merge pull request #23 from mattgenious/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mattgenious authored Sep 23, 2021
2 parents c832b29 + ec0df35 commit 5de3ee5
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 154 deletions.
174 changes: 109 additions & 65 deletions RechargeSharp/Entities/Charges/Charge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,6 @@ namespace RechargeSharp.Entities.Charges
{
public class Charge : IEquatable<Charge>
{
public bool Equals(Charge other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return AddressId == other.AddressId && Equals(BillingAddress, other.BillingAddress) && Equals(ClientDetails, other.ClientDetails) && CreatedAt.Equals(other.CreatedAt) && CustomerHash == other.CustomerHash && CustomerId == other.CustomerId && Email == other.Email && FirstName == other.FirstName && HasUncommitedChanges == other.HasUncommitedChanges && Id == other.Id && LastName == other.LastName && Note == other.Note && Nullable.Equals(ProcessedAt, other.ProcessedAt) && ProcessorName == other.ProcessorName && Nullable.Equals(ScheduledAt, other.ScheduledAt) && ShipmentsCount == other.ShipmentsCount && Equals(ShippingAddress, other.ShippingAddress) && ShopifyOrderId == other.ShopifyOrderId && Status == other.Status && SubTotal == other.SubTotal && SubtotalPrice == other.SubtotalPrice && Tags == other.Tags && TaxLines == other.TaxLines && TotalDiscounts == other.TotalDiscounts && TotalLineItemsPrice == other.TotalLineItemsPrice && TotalPrice == other.TotalPrice && TotalRefunds == other.TotalRefunds && TotalTax == other.TotalTax && TotalWeight == other.TotalWeight && TransactionId == other.TransactionId && Type == other.Type && UpdatedAt.Equals(other.UpdatedAt);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Charge) obj);
}

public override int GetHashCode()
{
unchecked
{
var hashCode = AddressId.GetHashCode();
hashCode = (hashCode * 397) ^ (BillingAddress != null ? BillingAddress.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (ClientDetails != null ? ClientDetails.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ CreatedAt.GetHashCode();
hashCode = (hashCode * 397) ^ (CustomerHash != null ? CustomerHash.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ CustomerId.GetHashCode();
hashCode = (hashCode * 397) ^ (Email != null ? Email.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (FirstName != null ? FirstName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ HasUncommitedChanges.GetHashCode();
hashCode = (hashCode * 397) ^ Id.GetHashCode();
hashCode = (hashCode * 397) ^ (LastName != null ? LastName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Note != null ? Note.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ProcessedAt.GetHashCode();
hashCode = (hashCode * 397) ^ (ProcessorName != null ? ProcessorName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ScheduledAt.GetHashCode();
hashCode = (hashCode * 397) ^ ShipmentsCount.GetHashCode();
hashCode = (hashCode * 397) ^ (ShippingAddress != null ? ShippingAddress.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ShopifyOrderId.GetHashCode();
hashCode = (hashCode * 397) ^ Status.GetHashCode();
hashCode = (hashCode * 397) ^ (SubTotal != null ? SubTotal.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ SubtotalPrice.GetHashCode();
hashCode = (hashCode * 397) ^ (Tags != null ? Tags.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ TaxLines.GetHashCode();
hashCode = (hashCode * 397) ^ (TotalDiscounts != null ? TotalDiscounts.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (TotalLineItemsPrice != null ? TotalLineItemsPrice.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (TotalPrice != null ? TotalPrice.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (TotalRefunds != null ? TotalRefunds.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ TotalTax.GetHashCode();
hashCode = (hashCode * 397) ^ TotalWeight.GetHashCode();
hashCode = (hashCode * 397) ^ (TransactionId != null ? TransactionId.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ UpdatedAt.GetHashCode();
return hashCode;
}
}

public static bool operator ==(Charge left, Charge right)
{
return Equals(left, right);
}

public static bool operator !=(Charge left, Charge right)
{
return !Equals(left, right);
}

[JsonProperty("address_id")]
public long AddressId { get; set; }

Expand Down Expand Up @@ -183,5 +118,114 @@ public override int GetHashCode()

[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; set; }

/// <summary>
/// only present for failed charges
/// </summary>
[JsonProperty("last_charge_attempt_date", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? LastChargeAttemptDate { get; set; }

/// <summary>
/// only present for failed charges
/// </summary>
[JsonProperty("retry_date", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? RetryDate { get; set; }

/// <summary>
/// only present for failed charges
/// </summary>
[JsonProperty("number_times_tried", NullValueHandling = NullValueHandling.Ignore)]
public long? NumberTimesTried { get; set; }

/// <summary>
/// only present for failed charges
/// </summary>
[JsonProperty("shopify_variant_id_not_found", NullValueHandling = NullValueHandling.Ignore)]
public string ShopifyVariantIdNotFound { get; set; }

/// <summary>
/// only present for failed charges
/// </summary>
[JsonProperty("error_type", NullValueHandling = NullValueHandling.Ignore)]
public string ErrorType { get; set; }

/// <summary>
/// only present for failed charges
/// </summary>
[JsonProperty("error", NullValueHandling = NullValueHandling.Ignore)]
public string Error { get; set; }


public bool Equals(Charge other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return AddressId == other.AddressId && CreatedAt.Equals(other.CreatedAt) &&
CustomerHash == other.CustomerHash && CustomerId == other.CustomerId && Email == other.Email &&
FirstName == other.FirstName && HasUncommitedChanges == other.HasUncommitedChanges &&
Id == other.Id && LastName == other.LastName && Note == other.Note &&
Nullable.Equals(ProcessedAt, other.ProcessedAt) && ProcessorName == other.ProcessorName &&
Nullable.Equals(ScheduledAt, other.ScheduledAt) && ShipmentsCount == other.ShipmentsCount &&
ShopifyOrderId == other.ShopifyOrderId &&
Status == other.Status && SubTotal == other.SubTotal && SubtotalPrice == other.SubtotalPrice &&
Tags == other.Tags && TaxLines == other.TaxLines && TotalDiscounts == other.TotalDiscounts &&
TotalLineItemsPrice == other.TotalLineItemsPrice && TotalPrice == other.TotalPrice &&
TotalRefunds == other.TotalRefunds && TotalTax == other.TotalTax &&
TotalWeight == other.TotalWeight && TransactionId == other.TransactionId && Type == other.Type &&
UpdatedAt.Equals(other.UpdatedAt) &&
Nullable.Equals(LastChargeAttemptDate, other.LastChargeAttemptDate) &&
Nullable.Equals(RetryDate, other.RetryDate) && NumberTimesTried == other.NumberTimesTried &&
ShopifyVariantIdNotFound == other.ShopifyVariantIdNotFound && ErrorType == other.ErrorType &&
Error == other.Error;
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Charge)obj);
}

public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(AddressId);
hashCode.Add(CreatedAt);
hashCode.Add(CustomerHash);
hashCode.Add(CustomerId);
hashCode.Add(Email);
hashCode.Add(FirstName);
hashCode.Add(HasUncommitedChanges);
hashCode.Add(Id);
hashCode.Add(LastName);
hashCode.Add(Note);
hashCode.Add(ProcessedAt);
hashCode.Add(ProcessorName);
hashCode.Add(ScheduledAt);
hashCode.Add(ShipmentsCount);
hashCode.Add(ShopifyOrderId);
hashCode.Add(Status);
hashCode.Add(SubTotal);
hashCode.Add(SubtotalPrice);
hashCode.Add(Tags);
hashCode.Add(TaxLines);
hashCode.Add(TotalDiscounts);
hashCode.Add(TotalLineItemsPrice);
hashCode.Add(TotalPrice);
hashCode.Add(TotalRefunds);
hashCode.Add(TotalTax);
hashCode.Add(TotalWeight);
hashCode.Add(TransactionId);
hashCode.Add(Type);
hashCode.Add(UpdatedAt);
hashCode.Add(LastChargeAttemptDate);
hashCode.Add(RetryDate);
hashCode.Add(NumberTimesTried);
hashCode.Add(ShopifyVariantIdNotFound);
hashCode.Add(ErrorType);
hashCode.Add(Error);
return hashCode.ToHashCode();
}
}
}
21 changes: 6 additions & 15 deletions RechargeSharp/Entities/Charges/ChargeResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,28 @@ namespace RechargeSharp.Entities.Charges
{
public class ChargeResponse : IEquatable<ChargeResponse>
{

[JsonProperty("charge")]
public Charge Charge { get; set; }

public bool Equals(ChargeResponse other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Charge == other.Charge;
return Equals(Charge, other.Charge);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ChargeResponse) obj);
return Equals((ChargeResponse)obj);
}

public override int GetHashCode()
{
return (Charge != null ? Charge.GetHashCode() : 0);
}

public static bool operator ==(ChargeResponse left, ChargeResponse right)
{
return Equals(left, right);
}

public static bool operator !=(ChargeResponse left, ChargeResponse right)
{
return !Equals(left, right);
}

[JsonProperty("charge")]
public Charge Charge { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
using RechargeSharp.Entities.Charges;

namespace RechargeSharp.Entities.WebhookResponses.Charges
{
Expand Down Expand Up @@ -36,6 +37,6 @@ public override int GetHashCode()
}

[JsonProperty("charge")]
public WebhookChargeFailed Charge { get; set; }
public Charge Charge { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
using RechargeSharp.Entities.Charges;

namespace RechargeSharp.Entities.WebhookResponses.Charges
{
Expand Down Expand Up @@ -36,6 +37,6 @@ public override int GetHashCode()
}

[JsonProperty("charge")]
public WebhookChargeFailed Charge { get; set; }
public Charge Charge { get; set; }
}
}

This file was deleted.

8 changes: 4 additions & 4 deletions RechargeSharp/RechargeSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>7.0.0</Version>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<Version>8.0.1</Version>
<AssemblyVersion>8.0.1.0</AssemblyVersion>
<PackageLicenseExpression></PackageLicenseExpression>
<PackageProjectUrl>https://github.com/mattgenious/RechargeSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/mattgenious/RechargeSharp</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<PackageTags>C#, .NET, ecommerce, recharge, rechargepayments</PackageTags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<FileVersion>7.0.0.0</FileVersion>
<FileVersion>8.0.1.0</FileVersion>
<Authors>Matt Luccas Phaure Minet</Authors>
<Description>A C# library for RechargePayments</Description>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageReleaseNotes>Fixed equality bug</PackageReleaseNotes>
<LangVersion>8.0</LangVersion>
<PackageIcon>icon.png</PackageIcon>
<Company>Matt Luccas Phaure Minet</Company>
Expand Down
5 changes: 4 additions & 1 deletion RechargeSharpTests/RechargeSharpSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ public void SerializeDeserializeChargeResponseTest(ChargeResponse sut)
{
var jsonString = JsonConvert.SerializeObject(sut);

Assert.Equal(sut, JsonConvert.DeserializeObject<ChargeResponse>(jsonString));
var result = JsonConvert.DeserializeObject<ChargeResponse>(jsonString);


Assert.Equal(sut, result);
}

[Theory]
Expand Down

0 comments on commit 5de3ee5

Please sign in to comment.