From d520df766cd918f87c20757890f0fd49ac74653d Mon Sep 17 00:00:00 2001 From: Paulo Pinho Date: Wed, 12 Jun 2024 18:01:29 -0300 Subject: [PATCH] GET external_subscription by external_id Added new method to get external_subscription by external_id. --- Library/ExternalSubscription.cs | 21 +++++++++++++++++++++ Test/ExternalSubscriptionTest.cs | 1 + 2 files changed, 22 insertions(+) diff --git a/Library/ExternalSubscription.cs b/Library/ExternalSubscription.cs index 1e1082bb..0cfbb038 100644 --- a/Library/ExternalSubscription.cs +++ b/Library/ExternalSubscription.cs @@ -35,6 +35,7 @@ public List ExternalInvoices public int Quantity { get; set; } public ExternalProductReference ExternalProductReference { get; private set; } public DateTime? LastPurchased { get; private set; } + public bool? Import { get; set; } public DateTime? ActivatedAt { get; private set; } public DateTime? CanceledAt { get; private set; } public DateTime? ExpiresAt { get; private set; } @@ -93,6 +94,12 @@ internal override void ReadXml(XmlTextReader reader) if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal)) LastPurchased = dateVal; break; + + case "import": + bool import; + if (bool.TryParse(reader.ReadElementContentAsString(), out import)) + Import = import; + break; case "state": State = reader.ReadElementContentAsString(); @@ -202,6 +209,20 @@ 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; + } /// /// Returns a list of external_invoices for this external subscription /// diff --git a/Test/ExternalSubscriptionTest.cs b/Test/ExternalSubscriptionTest.cs index 3482a8fa..272dfcca 100644 --- a/Test/ExternalSubscriptionTest.cs +++ b/Test/ExternalSubscriptionTest.cs @@ -19,6 +19,7 @@ public void LookupExternalSubscription() externalSubscription.CanceledAt.Should().Be(null); externalSubscription.TrialStartedAt.Should().Be(null); externalSubscription.TrialEndsAt.Should().Be(null); + externalSubscription.Import.Should().Be(false); } } }