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 support for spending_limits with Issuing Card and Cardholder #831

Merged
merged 1 commit into from
Apr 12, 2019
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
55 changes: 46 additions & 9 deletions issuing_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,37 @@ const (
IssuingCardTypeVirtual IssuingCardType = "virtual"
)

// IssuingSpendingLimitInterval is the list of possible values for the interval of a given
// spending limit on an issuing card or cardholder.
type IssuingSpendingLimitInterval string

// List of values that IssuingCardShippingStatus can take.
const (
IssuingSpendingLimitIntervalAllTime IssuingSpendingLimitInterval = "all_time"
IssuingSpendingLimitIntervalDaily IssuingSpendingLimitInterval = "daily"
IssuingSpendingLimitIntervalMonthly IssuingSpendingLimitInterval = "monthly"
IssuingSpendingLimitIntervalPerAuthorization IssuingSpendingLimitInterval = "per_authorization"
IssuingSpendingLimitIntervalWeekly IssuingSpendingLimitInterval = "weekly"
IssuingSpendingLimitIntervalYearly IssuingSpendingLimitInterval = "yearly"
)

// IssuingAuthorizationControlsSpendingLimitsParams is the set of parameters that can be used for
// the spending limits associated with a given issuing card or cardholder.
type IssuingAuthorizationControlsSpendingLimitsParams struct {
Amount *int64 `form:"amount"`
Categories []*string `form:"categories"`
Interval *string `form:"interval"`
}

// AuthorizationControlsParams is the set of parameters that can be used for the shipping parameter.
type AuthorizationControlsParams struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I never prefixed this with Issuing. Do you agree it's better to rename in the next major? (there will be an API version).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I noticed that too. Yeah, I think it's fine to just wait for the next major.

AllowedCategories []*string `form:"allowed_categories"`
BlockedCategories []*string `form:"blocked_categories"`
MaxAmount *int64 `form:"max_amount"`
MaxApprovals *int64 `form:"max_approvals"`
AllowedCategories []*string `form:"allowed_categories"`
BlockedCategories []*string `form:"blocked_categories"`
SpendingLimits *IssuingAuthorizationControlsSpendingLimitsParams `form:"spending_limits"`

// The following parameters are considered deprecated and only apply to issuing cards
MaxAmount *int64 `form:"max_amount"`
MaxApprovals *int64 `form:"max_approvals"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this as this is going away in a future API version and is technically unsupported on Cardholder

}

// IssuingCardShippingParams is the set of parameters that can be used for the shipping parameter.
Expand Down Expand Up @@ -98,13 +123,25 @@ type IssuingCardDetails struct {
Object string `json:"object"`
}

// IssuingAuthorizationControlsSpendingLimits is the resource representing spending limits
// associated with a card or cardholder.
type IssuingAuthorizationControlsSpendingLimits struct {
Amount int64 `json:"amount"`
Categories []string `json:"categories"`
Interval IssuingSpendingLimitInterval `json:"interval"`
}

// IssuingCardAuthorizationControls is the resource representing authorization controls on an issuing card.
// TODO: Rename to IssuingAuthorizationControls in the next major
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagging this as I am using the bad class name in Cardholder. An API version will be released to change this so I wanted to avoid 2 major versions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.

type IssuingCardAuthorizationControls struct {
AllowedCategories []string `json:"allowed_categories"`
BlockedCategories []string `json:"blocked_categories"`
Currency Currency `json:"currency"`
MaxAmount int64 `json:"max_amount"`
MaxApprovals int64 `json:"max_approvals"`
AllowedCategories []string `json:"allowed_categories"`
BlockedCategories []string `json:"blocked_categories"`
SpendingLimits *IssuingAuthorizationControlsSpendingLimits `json:"spending_limits"`

// The properties below are considered deprecated and can only be used for an issuing card.
Currency Currency `json:"currency"`
MaxAmount int64 `json:"max_amount"`
MaxApprovals int64 `json:"max_approvals"`
}

// IssuingCardShipping is the resource representing shipping on an issuing card.
Expand Down
40 changes: 21 additions & 19 deletions issuing_cardholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ type IssuingBillingParams struct {

// IssuingCardholderParams is the set of parameters that can be used when creating or updating an issuing cardholder.
type IssuingCardholderParams struct {
Params `form:"*"`
Billing *IssuingBillingParams `form:"billing"`
Email *string `form:"email"`
IsDefault *bool `form:"is_default"`
Name *string `form:"name"`
PhoneNumber *string `form:"phone_number"`
Status *string `form:"status"`
Type *string `form:"type"`
Params `form:"*"`
AuthorizationControls *AuthorizationControlsParams `form:"authorization_controls"`
Billing *IssuingBillingParams `form:"billing"`
Email *string `form:"email"`
IsDefault *bool `form:"is_default"`
Name *string `form:"name"`
PhoneNumber *string `form:"phone_number"`
Status *string `form:"status"`
Type *string `form:"type"`
}

// IssuingCardholderListParams is the set of parameters that can be used when listing issuing cardholders.
Expand All @@ -59,17 +60,18 @@ type IssuingBilling struct {

// IssuingCardholder is the resource representing a Stripe issuing cardholder.
type IssuingCardholder struct {
Billing *IssuingBilling `json:"billing"`
Created int64 `json:"created"`
Email string `json:"email"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Name string `json:"name"`
Object string `json:"object"`
PhoneNumber string `json:"phone_number"`
Status IssuingCardholderStatus `json:"status"`
Type IssuingCardholderType `json:"type"`
AuthorizationControls *IssuingCardAuthorizationControls `json:"authorization_controls"`
Billing *IssuingBilling `json:"billing"`
Created int64 `json:"created"`
Email string `json:"email"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Name string `json:"name"`
Object string `json:"object"`
PhoneNumber string `json:"phone_number"`
Status IssuingCardholderStatus `json:"status"`
Type IssuingCardholderType `json:"type"`
}

// IssuingCardholderList is a list of issuing cardholders as retrieved from a list endpoint.
Expand Down