-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AWE-774] Add external payment phases
GET /external_subscriptions/{external_subscription_id}/external_payment_phases GET /external_subscriptions/{external_subscription_id}/external_payment_phases/{external_payment_phase_id} GET /external_payment_phases/{external_payment_phase_id}
- Loading branch information
1 parent
e02b0f5
commit 85fc56e
Showing
15 changed files
with
483 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
using System; | ||
using System.Net; | ||
using System.Xml; | ||
|
||
namespace Recurly | ||
{ | ||
public class ExternalPaymentPhase : RecurlyEntity | ||
{ | ||
public DateTime StartedAt { get; private set; } | ||
public DateTime EndsAt { get; private set; } | ||
public int StartingBillingPeriodIndex { get; private set; } | ||
public int EndingBillingPeriodIndex { get; private set; } | ||
public string OfferType { get; private set; } | ||
public string OfferName { get; private set; } | ||
public int PeriodCount { get; private set; } | ||
public string PeriodLength { get; private set; } | ||
public decimal Amount { get; private set; } | ||
public string Currency { get; private set; } | ||
public DateTime CreatedAt { get; private set; } | ||
public DateTime UpdatedAt { get; private set; } | ||
|
||
internal const string UrlPrefix = "/external_payment_phases/"; | ||
|
||
internal ExternalPaymentPhase() | ||
{ | ||
} | ||
internal ExternalPaymentPhase(XmlTextReader reader) | ||
{ | ||
ReadXml(reader); | ||
} | ||
#region Read XML documents | ||
|
||
internal override void ReadXml(XmlTextReader reader) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
DateTime dateVal; | ||
|
||
if (reader.Name == "external_payment_phase" && reader.NodeType == XmlNodeType.EndElement) | ||
break; | ||
|
||
if (reader.NodeType != XmlNodeType.Element) continue; | ||
|
||
switch (reader.Name) | ||
{ | ||
case "started_at": | ||
if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal)) | ||
StartedAt = dateVal; ; | ||
break; | ||
|
||
case "ends_at": | ||
if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal)) | ||
EndsAt = dateVal; ; | ||
break; | ||
|
||
case "starting_billing_period_index": | ||
StartingBillingPeriodIndex = reader.ReadElementContentAsInt(); | ||
break; | ||
|
||
case "ending_billing_period_index": | ||
EndingBillingPeriodIndex = reader.ReadElementContentAsInt(); | ||
break; | ||
|
||
case "offer_type": | ||
OfferType = reader.ReadElementContentAsString(); | ||
break; | ||
|
||
case "offer_name": | ||
OfferName = reader.ReadElementContentAsString(); | ||
break; | ||
|
||
case "period_count": | ||
PeriodCount = reader.ReadElementContentAsInt(); | ||
break; | ||
|
||
case "period_length": | ||
PeriodLength = reader.ReadElementContentAsString(); | ||
break; | ||
|
||
case "amount": | ||
Amount = reader.ReadElementContentAsDecimal(); | ||
break; | ||
|
||
case "currency": | ||
Currency = reader.ReadElementContentAsString(); | ||
break; | ||
|
||
case "updated_at": | ||
if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal)) | ||
UpdatedAt = dateVal; ; | ||
break; | ||
|
||
case "created_at": | ||
if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal)) | ||
CreatedAt = dateVal; ; | ||
break; | ||
|
||
} | ||
} | ||
} | ||
|
||
internal override void WriteXml(XmlTextWriter writer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
#endregion | ||
|
||
#region Object Overrides | ||
|
||
public override string ToString() | ||
{ | ||
return "Recurly External Payment Phase: " + StartedAt + " " + EndsAt + " " + StartingBillingPeriodIndex + " " + EndingBillingPeriodIndex + " " + OfferType + " " + OfferName + " " + PeriodCount + " " + PeriodLength + " " + Amount + " " + Currency + " " + CreatedAt + " " + UpdatedAt; | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
public sealed class ExternalPaymentPhases | ||
{ | ||
/// <summary> | ||
/// Returns a list of recurly external_payment_phases | ||
/// </summary> | ||
/// <returns></returns> | ||
public static RecurlyList<ExternalPaymentPhase> List() | ||
{ | ||
return List(null); | ||
} | ||
/// <summary> | ||
/// Returns a list of recurly external_payment_phases | ||
/// </summary> | ||
/// <param name="filter">FilterCriteria used to apply server side sorting and filtering</param> | ||
/// <returns></returns> | ||
public static RecurlyList<ExternalPaymentPhase> List(FilterCriteria filter) | ||
{ | ||
filter = filter ?? FilterCriteria.Instance; | ||
var parameters = filter.ToNamedValueCollection(); | ||
return new ExternalPaymentPhaseList(ExternalPaymentPhase.UrlPrefix + "?" + parameters.ToString()); | ||
} | ||
public static ExternalPaymentPhase Get(string uuid) | ||
{ | ||
if (string.IsNullOrWhiteSpace(uuid)) | ||
{ | ||
return null; | ||
} | ||
var externalPaymentPhase = new ExternalPaymentPhase(); | ||
var statusCode = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get, | ||
ExternalPaymentPhase.UrlPrefix + Uri.EscapeDataString(uuid), | ||
externalPaymentPhase.ReadXml); | ||
|
||
return statusCode == HttpStatusCode.NotFound ? null : externalPaymentPhase; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Xml; | ||
|
||
namespace Recurly | ||
{ | ||
public class ExternalPaymentPhaseList : RecurlyList<ExternalPaymentPhase> | ||
{ | ||
internal ExternalPaymentPhaseList(string baseUrl) : base(Client.HttpRequestMethod.Get, baseUrl) | ||
{ | ||
} | ||
|
||
internal ExternalPaymentPhaseList() | ||
{ | ||
} | ||
public override RecurlyList<ExternalPaymentPhase> Start | ||
{ | ||
get { return HasStartPage() ? new ExternalPaymentPhaseList(StartUrl) : RecurlyList.Empty<ExternalPaymentPhase>(); } | ||
} | ||
|
||
public override RecurlyList<ExternalPaymentPhase> Next | ||
{ | ||
get { return HasNextPage() ? new ExternalPaymentPhaseList(NextUrl) : RecurlyList.Empty<ExternalPaymentPhase>(); } | ||
} | ||
|
||
public override RecurlyList<ExternalPaymentPhase> Prev | ||
{ | ||
get { return HasPrevPage() ? new ExternalPaymentPhaseList(PrevUrl) : RecurlyList.Empty<ExternalPaymentPhase>(); } | ||
} | ||
|
||
internal override void ReadXml(XmlTextReader reader) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
if (reader.Name == "external_payment_phases" && reader.NodeType == XmlNodeType.EndElement) | ||
break; | ||
|
||
if (reader.NodeType == XmlNodeType.Element && reader.Name == "external_payment_phase") | ||
{ | ||
Add(new ExternalPaymentPhase(reader)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Xml; | ||
using FluentAssertions; | ||
using Recurly.Test.Fixtures; | ||
|
||
namespace Recurly.Test | ||
{ | ||
public class ExternalPaymentPhaseTest : BaseTest | ||
{ | ||
[RecurlyFact(TestEnvironment.Type.Integration)] | ||
public void LookupExternalPaymentPhase() | ||
{ | ||
var externalPaymentPhase = new ExternalPaymentPhase(); | ||
var xmlFixture = FixtureImporter.Get(FixtureType.ExternalPaymentPhases, "show-200").Xml; | ||
XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(xmlFixture)); | ||
externalPaymentPhase.ReadXml(reader); | ||
externalPaymentPhase.StartedAt.Should().Be(new DateTime(2023, 11, 15, 0, 0, 0, DateTimeKind.Utc)); | ||
externalPaymentPhase.EndsAt.Should().Be(new DateTime(2023, 11, 17, 21, 27, 10, DateTimeKind.Utc)); | ||
externalPaymentPhase.StartingBillingPeriodIndex.Should().Be(1); | ||
externalPaymentPhase.EndingBillingPeriodIndex.Should().Be(2); | ||
externalPaymentPhase.OfferType.Should().Be("FREE_TRIAL"); | ||
externalPaymentPhase.OfferName.Should().Be("introductory"); | ||
externalPaymentPhase.PeriodCount.Should().Be(2); | ||
externalPaymentPhase.PeriodLength.Should().Be("TWO WEEKS"); | ||
externalPaymentPhase.Amount.Should().Be(new decimal(1.99)); | ||
externalPaymentPhase.Currency.Should().Be("USD"); | ||
externalPaymentPhase.CreatedAt.Should().Be(new DateTime(2023, 11, 15, 16, 16, 43, DateTimeKind.Utc)); | ||
externalPaymentPhase.UpdatedAt.Should().Be(new DateTime(2023, 11, 15, 16, 16, 43, DateTimeKind.Utc)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.