From 21ce27cb601111e3269d31e455c5560b12f6d983 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 | 29 +++++++++++++++++++++++++++++ Test/ExternalSubscriptionTest.cs | 2 ++ 2 files changed, 31 insertions(+) diff --git a/Library/ExternalSubscription.cs b/Library/ExternalSubscription.cs index 1e1082bb..d1314fcb 100644 --- a/Library/ExternalSubscription.cs +++ b/Library/ExternalSubscription.cs @@ -35,6 +35,8 @@ public List 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; } @@ -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; @@ -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; + } /// /// Returns a list of external_invoices for this external subscription /// diff --git a/Test/ExternalSubscriptionTest.cs b/Test/ExternalSubscriptionTest.cs index 3482a8fa..e101768c 100644 --- a/Test/ExternalSubscriptionTest.cs +++ b/Test/ExternalSubscriptionTest.cs @@ -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); } } }