Skip to content

Commit

Permalink
GET external_subscription by external_id
Browse files Browse the repository at this point in the history
Added new method to get external_subscription by external_id.
  • Loading branch information
paulorbpinho-fullstacklabs committed Jul 2, 2024
1 parent 351dc00 commit 21ce27c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Library/ExternalSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public List<ExternalInvoice> ExternalInvoices
public int Quantity { get; set; }
public ExternalProductReference ExternalProductReference { get; private set; }
public DateTime? LastPurchased { get; private set; }
public bool? Imported { get; set; }
public bool? Test { get; set; }
public DateTime? ActivatedAt { get; private set; }
public DateTime? CanceledAt { get; private set; }
public DateTime? ExpiresAt { get; private set; }
Expand Down Expand Up @@ -94,6 +96,18 @@ internal override void ReadXml(XmlTextReader reader)
LastPurchased = dateVal;
break;

case "imported":
bool imported;
if (bool.TryParse(reader.ReadElementContentAsString(), out imported))
Imported = imported;
break;

case "test":
bool test;
if (bool.TryParse(reader.ReadElementContentAsString(), out test))
Test = test;
break;

case "state":
State = reader.ReadElementContentAsString();
break;
Expand Down Expand Up @@ -202,6 +216,21 @@ public static ExternalSubscription Get(string uuid)

return statusCode == HttpStatusCode.NotFound ? null : externalSubscription;
}

public static ExternalSubscription GetByExternalId(string externalId)
{
if (string.IsNullOrWhiteSpace(externalId))
{
return null;
}
var externalSubscription = new ExternalSubscription();
var statusCode = Client.Instance.PerformRequest(
Client.HttpRequestMethod.Get,
ExternalSubscription.UrlPrefix + Uri.EscapeDataString("external-id-" + externalId),
externalSubscription.ReadXml
);
return statusCode == HttpStatusCode.NotFound ? null : externalSubscription;
}
/// <summary>
/// Returns a list of external_invoices for this external subscription
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Test/ExternalSubscriptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public void LookupExternalSubscription()
externalSubscription.CanceledAt.Should().Be(null);
externalSubscription.TrialStartedAt.Should().Be(null);
externalSubscription.TrialEndsAt.Should().Be(null);
externalSubscription.Imported.Should().Be(false);
externalSubscription.Test.Should().Be(false);
}
}
}

0 comments on commit 21ce27c

Please sign in to comment.