diff --git a/src/Stripe.net/Infrastructure/Middleware/RequestStringBuilder.cs b/src/Stripe.net/Infrastructure/Middleware/RequestStringBuilder.cs index fd8d056be3..c60410ccdf 100755 --- a/src/Stripe.net/Infrastructure/Middleware/RequestStringBuilder.cs +++ b/src/Stripe.net/Infrastructure/Middleware/RequestStringBuilder.cs @@ -98,6 +98,15 @@ private static List FlattenParamsValue(object value, string keyPrefix flatParams.Add(new Parameter(keyPrefix, paramValue)); } + else if (value is DateTime) + { + flatParams = new List(); + DateTime? dateTime = (DateTime)value; + if (dateTime.HasValue) + { + flatParams.Add(new Parameter(keyPrefix, dateTime?.ConvertDateTimeToEpoch().ToString())); + } + } else if (value == null) { flatParams = new List(); diff --git a/src/Stripe.net/Services/Account/StripeAccountSharedOptions.cs b/src/Stripe.net/Services/Account/StripeAccountSharedOptions.cs index d63272358b..b4d130f062 100755 --- a/src/Stripe.net/Services/Account/StripeAccountSharedOptions.cs +++ b/src/Stripe.net/Services/Account/StripeAccountSharedOptions.cs @@ -69,21 +69,8 @@ public abstract class StripeAccountSharedOptions : StripeBaseOptions, ISupportMe #region Tos Acceptance - public DateTime? TosAcceptanceDate { get; set; } - [JsonProperty("tos_acceptance[date]")] - internal long? TosAcceptanceDateInternal - { - get - { - if (!this.TosAcceptanceDate.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.TosAcceptanceDate.Value); - } - } + public DateTime? TosAcceptanceDate { get; set; } [JsonProperty("tos_acceptance[ip]")] public string TosAcceptanceIp { get; set; } diff --git a/src/Stripe.net/Services/Coupons/StripeCouponCreateOptions.cs b/src/Stripe.net/Services/Coupons/StripeCouponCreateOptions.cs index 43a636ef87..b28e852631 100644 --- a/src/Stripe.net/Services/Coupons/StripeCouponCreateOptions.cs +++ b/src/Stripe.net/Services/Coupons/StripeCouponCreateOptions.cs @@ -34,20 +34,7 @@ public class StripeCouponCreateOptions : StripeBaseOptions, ISupportMetadata [JsonProperty("name")] public string Name { get; set; } - public DateTime? RedeemBy { get; set; } - [JsonProperty("redeem_by")] - internal long? RedeemByInternal - { - get - { - if (!this.RedeemBy.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.RedeemBy.Value); - } - } + public DateTime? RedeemBy { get; set; } } } diff --git a/src/Stripe.net/Services/FileLinks/StripeFileLinkSharedOptions.cs b/src/Stripe.net/Services/FileLinks/StripeFileLinkSharedOptions.cs index 404ef1cf6e..a49c6296c7 100644 --- a/src/Stripe.net/Services/FileLinks/StripeFileLinkSharedOptions.cs +++ b/src/Stripe.net/Services/FileLinks/StripeFileLinkSharedOptions.cs @@ -10,21 +10,8 @@ public class StripeFileLinkSharedOptions : StripeBaseOptions, ISupportMetadata /// /// A future timestamp after which the link will no longer be usable. /// - public DateTime? ExpiresAt { get; set; } - [JsonProperty("expires_at")] - internal long? ExpiresAtInternal - { - get - { - if (!this.ExpiresAt.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.ExpiresAt.Value); - } - } + public DateTime? ExpiresAt { get; set; } /// /// Set of key-value pairs that you can attach to an object. This can be useful for storing diff --git a/src/Stripe.net/Services/Invoices/StripeInvoiceCreateOptions.cs b/src/Stripe.net/Services/Invoices/StripeInvoiceCreateOptions.cs index 69aa8095f2..d7f18f033e 100644 --- a/src/Stripe.net/Services/Invoices/StripeInvoiceCreateOptions.cs +++ b/src/Stripe.net/Services/Invoices/StripeInvoiceCreateOptions.cs @@ -28,10 +28,8 @@ public class StripeInvoiceCreateOptions : StripeBaseOptions, ISupportMetadata /// /// The date on which payment for this invoice is due. Only valid for invoices where billing=send_invoice. /// - public DateTime? DueDate { get; set; } - [JsonProperty("due_date")] - internal long? DueDateInternal => this.DueDate?.ConvertDateTimeToEpoch(); + public DateTime? DueDate { get; set; } [JsonProperty("metadata")] public Dictionary Metadata { get; set; } @@ -45,4 +43,4 @@ public class StripeInvoiceCreateOptions : StripeBaseOptions, ISupportMetadata [JsonProperty("tax_percent")] public decimal? TaxPercent { get; set; } } -} \ No newline at end of file +} diff --git a/src/Stripe.net/Services/Invoices/StripeUpcomingInvoiceOptions.cs b/src/Stripe.net/Services/Invoices/StripeUpcomingInvoiceOptions.cs index 9ecdaabd07..8ec8f88153 100644 --- a/src/Stripe.net/Services/Invoices/StripeUpcomingInvoiceOptions.cs +++ b/src/Stripe.net/Services/Invoices/StripeUpcomingInvoiceOptions.cs @@ -16,21 +16,8 @@ public class StripeUpcomingInvoiceOptions : StripeBaseOptions /// /// A future date to anchor the subscription’s billing cycle. This is used to determine the date of the first full invoice, and, for plans with month or year intervals, the day of the month for subsequent invoices. /// - public DateTime? SubscriptionBillingCycleAnchor { get; set; } - [JsonProperty("subscription_billing_cycle_anchor")] - internal long? SubscriptionBillingCycleAnchorInternal - { - get - { - if (!this.SubscriptionBillingCycleAnchor.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.SubscriptionBillingCycleAnchor.Value); - } - } + public DateTime? SubscriptionBillingCycleAnchor { get; set; } [JsonProperty("subscription")] public string SubscriptionId { get; set; } @@ -44,21 +31,8 @@ internal long? SubscriptionBillingCycleAnchorInternal [JsonProperty("subscription_prorate")] public bool? SubscriptionProrate { get; set; } - public DateTime? SubscriptionProrationDate { get; set; } - [JsonProperty("subscription_proration_date")] - internal long? SubscriptionProrationDateInternal - { - get - { - if (!this.SubscriptionProrationDate.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.SubscriptionProrationDate.Value); - } - } + public DateTime? SubscriptionProrationDate { get; set; } [JsonProperty("subscription_quantity")] public int? SubscriptionQuantity { get; set; } @@ -66,21 +40,8 @@ internal long? SubscriptionProrationDateInternal [JsonProperty("subscription_tax_percent")] public decimal? SubscriptionTaxPercent { get; set; } - public DateTime? SubscriptionTrialEnd { get; set; } - [JsonProperty("subscription_trial_end")] - internal long? SubscriptionTrialEndInternal - { - get - { - if (!this.SubscriptionTrialEnd.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.SubscriptionTrialEnd.Value); - } - } + public DateTime? SubscriptionTrialEnd { get; set; } [JsonProperty("subscription_trial_from_plan")] public bool? SubscriptionTrialFromPlan { get; set; } diff --git a/src/Stripe.net/Services/Reporting/ReportRuns/ParametersOptions.cs b/src/Stripe.net/Services/Reporting/ReportRuns/ParametersOptions.cs index a0f491bc74..1038a2276d 100644 --- a/src/Stripe.net/Services/Reporting/ReportRuns/ParametersOptions.cs +++ b/src/Stripe.net/Services/Reporting/ReportRuns/ParametersOptions.cs @@ -13,37 +13,11 @@ public class ParametersOptions : INestedOptions [JsonProperty("currency")] public string Currency { get; set; } - public DateTime? IntervalEnd { get; set; } - [JsonProperty("interval_end")] - internal long? IntervalEndInternal - { - get - { - if (!this.IntervalEnd.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.IntervalEnd.Value); - } - } - - public DateTime? IntervalStart { get; set; } + public DateTime? IntervalEnd { get; set; } [JsonProperty("interval_start")] - internal long? IntervalStartInternal - { - get - { - if (!this.IntervalStart.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.IntervalStart.Value); - } - } + public DateTime? IntervalStart { get; set; } [JsonProperty("payout")] public string Payout { get; set; } diff --git a/src/Stripe.net/Services/Sources/StripeSourceMandateOptions.cs b/src/Stripe.net/Services/Sources/StripeSourceMandateOptions.cs index 14437c7afe..8e881a1b95 100644 --- a/src/Stripe.net/Services/Sources/StripeSourceMandateOptions.cs +++ b/src/Stripe.net/Services/Sources/StripeSourceMandateOptions.cs @@ -6,21 +6,8 @@ namespace Stripe public class StripeSourceMandateOptions : INestedOptions { - public DateTime? MandateAcceptanceDate { get; set; } - [JsonProperty("acceptance[date]")] - internal long? MandateAcceptanceDateInternal - { - get - { - if (!this.MandateAcceptanceDate.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.MandateAcceptanceDate.Value); - } - } + public DateTime? MandateAcceptanceDate { get; set; } [JsonProperty("acceptance[ip]")] public string MandateAcceptanceIp { get; set; } diff --git a/src/Stripe.net/Services/SubscriptionItems/SubscriptionItemSharedOptions.cs b/src/Stripe.net/Services/SubscriptionItems/SubscriptionItemSharedOptions.cs index b2e33346d5..0ef11c2eb7 100755 --- a/src/Stripe.net/Services/SubscriptionItems/SubscriptionItemSharedOptions.cs +++ b/src/Stripe.net/Services/SubscriptionItems/SubscriptionItemSharedOptions.cs @@ -21,21 +21,8 @@ public abstract class SubscriptionItemSharedOptions : StripeBaseOptions /// /// If set, the proration will be calculated as though the subscription was updated at the given time. This can be used to apply the same proration that was previewed with the upcoming invoice endpoint. /// - public DateTime? ProrationDate { get; set; } - [JsonProperty("proration_date")] - internal long? ProrationDateInternal - { - get - { - if (!this.ProrationDate.HasValue) - { - return null; - } - - return this.ProrationDate.Value.ConvertDateTimeToEpoch(); - } - } + public DateTime? ProrationDate { get; set; } /// /// The quantity you’d like to apply to the subscription item you’re creating. diff --git a/src/Stripe.net/Services/Subscriptions/StripeSubscriptionCreateOptions.cs b/src/Stripe.net/Services/Subscriptions/StripeSubscriptionCreateOptions.cs index 095645c76f..5db0c5ff85 100755 --- a/src/Stripe.net/Services/Subscriptions/StripeSubscriptionCreateOptions.cs +++ b/src/Stripe.net/Services/Subscriptions/StripeSubscriptionCreateOptions.cs @@ -10,21 +10,8 @@ public class StripeSubscriptionCreateOptions : SubscriptionSharedOptions /// /// A future date to anchor the subscription’s billing cycle. This is used to determine the date of the first full invoice, and, for plans with month or year intervals, the day of the month for subsequent invoices. /// - public DateTime? BillingCycleAnchor { get; set; } - [JsonProperty("billing_cycle_anchor")] - internal long? BillingCycleAnchorInternal - { - get - { - if (!this.BillingCycleAnchor.HasValue) - { - return null; - } - - return EpochTime.ConvertDateTimeToEpoch(this.BillingCycleAnchor.Value); - } - } + public DateTime? BillingCycleAnchor { get; set; } /// /// REQUIRED: The identifier of the customer to subscribe. diff --git a/src/Stripe.net/Services/Subscriptions/StripeSubscriptionUpdateOptions.cs b/src/Stripe.net/Services/Subscriptions/StripeSubscriptionUpdateOptions.cs index 8bba9de685..1dc2012d97 100755 --- a/src/Stripe.net/Services/Subscriptions/StripeSubscriptionUpdateOptions.cs +++ b/src/Stripe.net/Services/Subscriptions/StripeSubscriptionUpdateOptions.cs @@ -44,15 +44,10 @@ internal string BillingCycleAnchorInternal [JsonProperty("items")] public List Items { get; set; } - #region ProrationDate - /// /// Boolean indicating whether this subscription should cancel at the end of the current period. /// - public DateTime? ProrationDate { get; set; } - [JsonProperty("proration_date")] - internal string ProrationDateInternal => this.ProrationDate?.ConvertDateTimeToEpoch().ToString(); - #endregion + public DateTime? ProrationDate { get; set; } } } diff --git a/src/Stripe.net/Services/UsageRecords/StripeUsageRecordCreateOptions.cs b/src/Stripe.net/Services/UsageRecords/StripeUsageRecordCreateOptions.cs index c1430ef8c7..22e3589937 100644 --- a/src/Stripe.net/Services/UsageRecords/StripeUsageRecordCreateOptions.cs +++ b/src/Stripe.net/Services/UsageRecords/StripeUsageRecordCreateOptions.cs @@ -13,15 +13,10 @@ public class StripeUsageRecordCreateOptions : StripeBaseOptions [JsonIgnore] public string SubscriptionItem { get; set; } - public DateTime Timestamp { get; set; } - [JsonProperty("timestamp")] - internal string TimestampInternal - { - get { return this.Timestamp.ConvertDateTimeToEpoch().ToString(); } - } + public DateTime Timestamp { get; set; } [JsonProperty("quantity")] public int Quantity { get; set; } } -} \ No newline at end of file +} diff --git a/src/StripeTests/Infrastructure/ParameterBuilderTest.cs b/src/StripeTests/Infrastructure/ParameterBuilderTest.cs index 1e7eacf4a4..99b6302f07 100644 --- a/src/StripeTests/Infrastructure/ParameterBuilderTest.cs +++ b/src/StripeTests/Infrastructure/ParameterBuilderTest.cs @@ -133,6 +133,16 @@ public void EncodesParameters() want = "?bool=False&date_filter[lt]=946702800&date_filter[gte]=946684800&decimal=0&enum=test_one&int=0" }, + // DateTimeNullable + new + { + data = new TestOptions + { + DateTimeNullable = DateTime.Parse("Sat, 01 Jan 2000 00:00:00Z"), + }, + want = "?bool=False&datetime_nullable=946684800&decimal=0&enum=test_one&int=0" + }, + // Decimal new { diff --git a/src/StripeTests/Infrastructure/TestData/TestOptions.cs b/src/StripeTests/Infrastructure/TestData/TestOptions.cs index 47fa67b974..435c829879 100644 --- a/src/StripeTests/Infrastructure/TestData/TestOptions.cs +++ b/src/StripeTests/Infrastructure/TestData/TestOptions.cs @@ -35,6 +35,9 @@ public enum TestEnum [JsonProperty("date_filter")] public StripeDateFilter DateFilter { get; set; } + [JsonProperty("datetime_nullable")] + public DateTime? DateTimeNullable { get; set; } + [JsonProperty("decimal")] public decimal Decimal { get; set; }