Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better support for spending limits on Issuing Card #1892

Merged
merged 1 commit into from
Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
namespace Stripe.Issuing
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

// TODO: Rename to CardAuthorizationControls in a future major version and move to Card folder.
public class AuthorizationControls : StripeEntity<AuthorizationControls>
{
/// <summary>
/// Categories of authorizations permitted for this card.
/// </summary>
[JsonProperty("allowed_categories")]
public List<string> AllowedCategories { get; set; }

/// <summary>
/// Categories of authorizations to always decline for this card.
/// </summary>
[JsonProperty("blocked_categories")]
public List<string> BlockedCategories { get; set; }

[Obsolete("Use Card.Currency instead.")]
[JsonProperty("currency")]
public string Currency { get; set; }

[Obsolete("Use SpendingLimits instead.")]
[JsonProperty("max_amount")]
public long? MaxAmount { get; set; }

/// <summary>
/// Maximum count of approved authorizations on this card. Counts all authorizations
/// retroactively.
/// </summary>
[JsonProperty("max_approvals")]
public long? MaxApprovals { get; set; }

/// <summary>
/// Limit the spending with rules based on time intervals and categories.
/// </summary>
[JsonProperty("spending_limits")]
public List<CardAuthorizationControlsSpendingLimit> SpendingLimits { get; set; }

/// <summary>
/// Currency for the amounts within spending_limits. Locked to the currency of the card.
/// </summary>
[JsonProperty("spending_limits_currency")]
public string SpendingLimitsCurrency { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Stripe.Issuing
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

public class CardAuthorizationControlsSpendingLimit : StripeEntity<CardAuthorizationControlsSpendingLimit>
{
/// <summary>
/// Maximum amount allowed to spend per time interval.
/// </summary>
[JsonProperty("amount")]
public long Amount { get; set; }

/// <summary>
/// Categories on which to apply the spending limit. Leave this empty to limit all charges.
/// </summary>
[JsonProperty("categories")]
public List<string> Categories { get; set; }

/// <summary>
/// The time interval with which to apply this spending limit towards. Allowed values are
/// <c>per_authorization</c>, <c>daily</c>, <c>weekly</c>, <c>monthly</c>, <c>yearly</c>,
/// or <c>all_time</c>.
/// </summary>
[JsonProperty("interval")]
public string Interval { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/Stripe.net/Entities/Issuing/Cards/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public class Card : StripeEntity<Card>, IHasId, IHasMetadata, IHasObject
[JsonConverter(typeof(DateTimeConverter))]
public DateTime Created { get; set; }

/// <summary>
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
/// </summary>
[JsonProperty("currency")]
public string Currency { get; set; }

/// <summary>
/// The expiration month of the card.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
namespace Stripe.Issuing
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

// TODO: Rename to CardAuthorizationControls in a future major version and move to Card folder.
public class AuthorizationControlsOptions : INestedOptions
{
/// <summary>
/// Categories of authorizations permitted for this card.
/// </summary>
[JsonProperty("allowed_categories")]
public List<string> AllowedCategories { get; set; }

/// <summary>
/// Categories of authorizations to always decline for this card.
/// </summary>
[JsonProperty("blocked_categories")]
public List<string> BlockedCategories { get; set; }

[Obsolete("Use SpendingLimits instead.")]
[JsonProperty("max_amount")]
public long? MaxAmount { get; set; }

/// <summary>
/// Maximum count of approved authorizations on this card. Counts all authorizations
/// retroactively.
/// </summary>
[JsonProperty("max_approvals")]
public long? MaxApprovals { get; set; }

/// <summary>
/// Limit the spending with rules based on time intervals and categories.
/// </summary>
[JsonProperty("spending_limits")]
public List<CardAuthorizationControlsSpendingLimitOptions> SpendingLimits { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Stripe.Issuing
{
using System.Collections.Generic;
using Newtonsoft.Json;

public class CardAuthorizationControlsSpendingLimitOptions : INestedOptions
{
/// <summary>
/// Maximum amount allowed to spend per time interval.
/// </summary>
[JsonProperty("amount")]
public long? Amount { get; set; }

/// <summary>
/// Categories on which to apply the spending limit. Leave this empty to limit all charges.
/// </summary>
[JsonProperty("categories")]
public List<string> Categories { get; set; }

/// <summary>
/// The time interval with which to apply this spending limit towards. Allowed values are
/// <c>per_authorization</c>, <c>daily</c>, <c>weekly</c>, <c>monthly</c>, <c>yearly</c>,
/// or <c>all_time</c>.
/// </summary>
[JsonProperty("interval")]
public string Interval { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Stripe.net/Services/Issuing/Cards/CardCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Stripe.Issuing
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

Expand All @@ -12,6 +13,7 @@ public class CardCreateOptions : BaseOptions, IHasMetadata
[JsonProperty("authorization_controls")]
public AuthorizationControlsOptions AuthorizationControls { get; set; }

[Obsolete("This parameter does not exist and was added to the library incorrectly.")]
[JsonProperty("billing")]
public BillingOptions Billing { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions src/Stripe.net/Services/Issuing/Cards/CardUpdateOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Stripe.Issuing
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

Expand All @@ -12,6 +13,7 @@ public class CardUpdateOptions : BaseOptions, IHasMetadata
[JsonProperty("authorization_controls")]
public AuthorizationControlsOptions AuthorizationControls { get; set; }

[Obsolete("This parameter does not exist and was added to the library incorrectly.")]
[JsonProperty("billing")]
public BillingOptions Billing { get; set; }

Expand Down
13 changes: 12 additions & 1 deletion src/StripeTests/Services/Issuing/Cards/IssuingCardServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ public IssuingCardServiceTest(
{
AuthorizationControls = new AuthorizationControlsOptions
{
MaxAmount = 123,
SpendingLimits = new List<CardAuthorizationControlsSpendingLimitOptions>
{
new CardAuthorizationControlsSpendingLimitOptions
{
Amount = 1000,
Categories = new List<string>
{
"financial_institutions",
},
Interval = "all_time",
},
},
},
Currency = "usd",
Type = "virtual",
Expand Down