Skip to content

Commit

Permalink
Use custom types for resources and string on params
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed May 24, 2018
1 parent bf3a684 commit 35258f8
Show file tree
Hide file tree
Showing 58 changed files with 620 additions and 698 deletions.
149 changes: 65 additions & 84 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,71 @@ import (
"github.com/stripe/stripe-go/form"
)

// AccountType is the type of an account.
type AccountType string

const (
AccountTypeCustom AccountType = "custom"
AccountTypeExpress AccountType = "express"
AccountTypeStandard AccountType = "standard"
)

// ExternalAccountType is the type of an external account.
type ExternalAccountType string

const (
ExternalAccountTypeBankAccount ExternalAccountType = "bank_account"
ExternalAccountTypeCard ExternalAccountType = "card"
)

// LegalEntityType describes the types for a legal entity.
// Allowed values are "individual", "company".
type LegalEntityType string

const (
LegalEntityTypeCompany LegalEntityType = "company"
LegalEntityTypeIndividual LegalEntityType = "individual"
)

// IdentityVerificationDetailsCode is a machine-readable code specifying the
// verification state of a legal entity. Allowed values are
// "failed_keyed_identity", "failed_other", "scan_corrupt",
// "scan_failed_greyscale", "scan_failed_other",
// "scan_id_country_not_supported", "scan_id_type_not_supported",
// "scan_name_mismatch", "scan_not_readable", "scan_not_uploaded".
// verification state of a legal entity
type IdentityVerificationDetailsCode string

const (
IdentityVerificationDetailsCodeFailedKeyedIdentity IdentityVerificationDetailsCode = "failed_keyed_identity"
IdentityVerificationDetailsCodeFailedOther IdentityVerificationDetailsCode = "failed_other"
IdentityVerificationDetailsCodeScanCorrupt IdentityVerificationDetailsCode = "scan_corrupt"
IdentityVerificationDetailsCodeScanFailedGreyscale IdentityVerificationDetailsCode = "scan_failed_greyscale"
IdentityVerificationDetailsCodeScanFailedOther IdentityVerificationDetailsCode = "scan_failed_other"
IdentityVerificationDetailsCodeScanIdCountryNotSupported IdentityVerificationDetailsCode = "scan_id_country_not_supported"
IdentityVerificationDetailsCodeScanIdTypeNotSupported IdentityVerificationDetailsCode = "scan_id_type_not_supported"
IdentityVerificationDetailsCodeScanNameMismatch IdentityVerificationDetailsCode = "scan_name_mismatch"
IdentityVerificationDetailsCodeScanNotReadable IdentityVerificationDetailsCode = "scan_not_readable"
IdentityVerificationDetailsCodeScanNotUploaded IdentityVerificationDetailsCode = "scan_not_uploaded"
)

// IdentityVerificationStatus describes the different statuses for identity verification.
// Allowed values are "pending", "verified", "unverified".
type IdentityVerificationStatus string

// Interval describes the payout interval.
// Allowed values are "manual", "daily", "weekly", "monthly".
type Interval string

const (
// Company is a constant value representing a company legal entity type.
Company LegalEntityType = "company"

// Day is a constant value representing a daily payout interval.
Day Interval = "daily"

// Individual is a constant value representing an individual legal entity
// type.
Individual LegalEntityType = "individual"

// IdentityVerificationPending is a constant value indicating that identity
// verification status is pending.
IdentityVerificationPending IdentityVerificationStatus = "pending"

// IdentityVerificationUnverified is a constant value indicating that
// identity verification status is unverified.
IdentityVerificationUnverified IdentityVerificationStatus = "unverified"

// IdentityVerificationVerified is a constant value indicating that
// identity verification status is verified.
IdentityVerificationVerified IdentityVerificationStatus = "verified"
IdentityVerificationStatusPending IdentityVerificationStatus = "pending"
IdentityVerificationStatusUnverified IdentityVerificationStatus = "unverified"
IdentityVerificationStatusVerified IdentityVerificationStatus = "verified"
)

// Manual is a constant value representing a manual payout interval.
Manual Interval = "manual"
// Interval describes the payout interval.
type PayoutInterval string

// Monthly is a constant value representing a monthly payout interval.
Monthly Interval = "monthly"
const (
PayoutIntervalDay PayoutInterval = "daily"
PayoutIntervalManual PayoutInterval = "manual"
PayoutIntervalMonthly PayoutInterval = "monthly"
PayoutIntervalWeekly PayoutInterval = "weekly"
)

// Weekly is a constant value representing a weekly payout interval.
Weekly Interval = "weekly"
const (
AccountRejectReasonFraud string = "fraud"
AccountRejectReasonOther string = "other"
AccountRejectReasonTermsOfService string = "terms_of_service"
)

// AccountParams are the parameters allowed during account creation/updates.
Expand Down Expand Up @@ -217,7 +231,7 @@ type Account struct {
ChargesEnabled bool `json:"charges_enabled"`
Country string `json:"country"`
DebitNegativeBalances bool `json:"debit_negative_balances"`
DefaultCurrency string `json:"default_currency"`
DefaultCurrency Currency `json:"default_currency"`
Deleted bool `json:"deleted"`
DetailsSubmitted bool `json:"details_submitted"`
Email string `json:"email"`
Expand Down Expand Up @@ -274,33 +288,6 @@ func (a *Account) UnmarshalJSON(data []byte) error {
return nil
}

// ExternalAccountType is the type of an external account.
type ExternalAccountType string

const (
// ExternalAccountTypeBankAccount is a constant value representing an external
// account which is a bank account.
ExternalAccountTypeBankAccount ExternalAccountType = "bank_account"

// ExternalAccountTypeCard is a constant value representing an external account
// which is a card.
ExternalAccountTypeCard ExternalAccountType = "card"
)

// AccountType is the type of an account.
type AccountType string

const (
// AccountTypeCustom is a constant value representing an account of type custom.
AccountTypeCustom AccountType = "custom"

// AccountTypeExpress is a constant value representing an account of type express.
AccountTypeExpress AccountType = "express"

// AccountTypeStandard is a constant value representing an account of type standard.
AccountTypeStandard AccountType = "standard"
)

// AccountList is a list of accounts as returned from a list endpoint.
type AccountList struct {
ListMeta
Expand Down Expand Up @@ -369,7 +356,7 @@ type LegalEntity struct {
FirstName string `json:"first_name"`
FirstNameKana string `json:"first_name_kana"`
FirstNameKanji string `json:"first_name_kanji"`
Gender Gender `json:"gender"`
Gender string `json:"gender"`
LastName string `json:"last_name"`
LastNameKana string `json:"last_name_kana"`
LastNameKanji string `json:"last_name_kanji"`
Expand Down Expand Up @@ -405,19 +392,15 @@ type DOB struct {
Year int64 `json:"year"`
}

// Gender is the gender of an account owner. International regulations require
// either “male” or “female”.
type Gender string

// AdditionalOwner is the structure for an account owner.
type AdditionalOwner struct {
Address AccountAddress `json:"address"`
DOB DOB `json:"dob"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
MaidenName string `json:"maiden_name"`
PersonalIDNumberProvided bool `json:"personal_id_number_provided"`
Verification IdentityVerification `json:"verification"`
Address AccountAddress `json:"address"`
DOB DOB `json:"dob"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
MaidenName string `json:"maiden_name"`
PersonalIDNumberProvided bool `json:"personal_id_number_provided"`
Verification string `json:"verification"`
}

// IdentityVerification is the structure for an account's verification.
Expand All @@ -430,15 +413,13 @@ type IdentityVerification struct {

// PayoutSchedule is the structure for an account's payout schedule.
type PayoutSchedule struct {
DelayDays int64 `json:"delay_days"`
Interval Interval `json:"interval"`
MonthlyAnchor int64 `json:"monthly_anchor"`
WeeklyAnchor string `json:"weekly_anchor"`
DelayDays int64 `json:"delay_days"`
Interval PayoutInterval `json:"interval"`
MonthlyAnchor int64 `json:"monthly_anchor"`
WeeklyAnchor string `json:"weekly_anchor"`
}

// AccountRejectParams is the structure for the Reject function.
type AccountRejectParams struct {
// Reason is the reason that an account was rejected. It should be given a
// value of one of `fraud`, `terms_of_service`, or `other`.
Reason *string `form:"reason"`
}
4 changes: 2 additions & 2 deletions account/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestAccountNew(t *testing.T) {
SupportURL: stripe.String("www.stripe.com"),
SupportPhone: stripe.String("4151234567"),
LegalEntity: &stripe.LegalEntityParams{
Type: stripe.String(string(stripe.Individual)),
Type: stripe.String(string(stripe.LegalEntityTypeIndividual)),
BusinessName: stripe.String("Stripe Go"),
AdditionalOwners: []stripe.AdditionalOwnerParams{
{
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestAccountNew(t *testing.T) {

func TestAccountReject(t *testing.T) {
account, err := Reject("acct_123", &stripe.AccountRejectParams{
Reason: stripe.String("fraud"),
Reason: stripe.String(stripe.AccountRejectReasonFraud),
})
assert.Nil(t, err)
assert.NotNil(t, account)
Expand Down
59 changes: 33 additions & 26 deletions balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,48 @@ package stripe
import "encoding/json"

// BalanceTransactionStatus is the list of allowed values for the balance transaction's status.
// Allowed values are "available", "pending".
type BalanceTransactionStatus string

const (
BalanceTransactionStatusAvailable BalanceTransactionStatus = "available"
BalanceTransactionStatusPending BalanceTransactionStatus = "pending"
)

// BalanceTransactionType is the list of allowed values for the balance transaction's type.
// Allowed values are "charge", "refund", "adjustment", "application_fee",
// "application_fee_refund", "transfer", "transfer_cancel", "transfer_failure".
type BalanceTransactionType string

const (
BalanceTransactionTypeAdjustment BalanceTransactionType = "adjustment"
BalanceTransactionTypeApplicationFee BalanceTransactionType = "application_fee"
BalanceTransactionTypeApplicationFeeRefund BalanceTransactionType = "application_fee_refund"
BalanceTransactionTypeCharge BalanceTransactionType = "charge"
BalanceTransactionTypePayment BalanceTransactionType = "payment"
BalanceTransactionTypePaymentFailureRefund BalanceTransactionType = "payment_failure_refund"
BalanceTransactionTypePaymentRefund BalanceTransactionType = "payment_refund"
BalanceTransactionTypePayout BalanceTransactionType = "payout"
BalanceTransactionTypePayoutCancel BalanceTransactionType = "payout_cancel"
BalanceTransactionTypePayoutFailure BalanceTransactionType = "payout_failure"
BalanceTransactionTypeRecipientTransfer BalanceTransactionType = "recipient_transfer"
BalanceTransactionTypeRecipientTransferCancel BalanceTransactionType = "recipient_transfer_cancel"
BalanceTransactionTypeRecipientTransferFailure BalanceTransactionType = "recipient_transfer_failure"
BalanceTransactionTypeRefund BalanceTransactionType = "refund"
BalanceTransactionTypeStripeFee BalanceTransactionType = "stripe_fee"
BalanceTransactionTypeTransfer BalanceTransactionType = "transfer"
BalanceTransactionTypeTransferRefund BalanceTransactionType = "transfer_refund"
)

// BalanceTransactionSourceType consts represent valid balance transaction sources.
type BalanceTransactionSourceType string

const (
// BalanceTransactionSourceTypeCharge is a constant representing a transaction source of charge
BalanceTransactionSourceTypeCharge BalanceTransactionSourceType = "charge"

// BalanceTransactionSourceTypeDispute is a constant representing a transaction source of dispute
BalanceTransactionSourceTypeDispute BalanceTransactionSourceType = "dispute"

// BalanceTransactionSourceTypeApplicationFee is a constant representing a transaction source of application_fee
BalanceTransactionSourceTypeApplicationFee BalanceTransactionSourceType = "application_fee"

// BalanceTransactionSourceTypePayout is a constant representing a transaction source of payout
BalanceTransactionSourceTypePayout BalanceTransactionSourceType = "payout"

// BalanceTransactionSourceTypeRecipientTransfer is a constant representing a transaction source of recipient_transfer
BalanceTransactionSourceTypeApplicationFee BalanceTransactionSourceType = "application_fee"
BalanceTransactionSourceTypeCharge BalanceTransactionSourceType = "charge"
BalanceTransactionSourceTypeDispute BalanceTransactionSourceType = "dispute"
BalanceTransactionSourceTypePayout BalanceTransactionSourceType = "payout"
BalanceTransactionSourceTypeRecipientTransfer BalanceTransactionSourceType = "recipient_transfer"

// BalanceTransactionSourceTypeRefund is a constant representing a transaction source of refund
BalanceTransactionSourceTypeRefund BalanceTransactionSourceType = "refund"

// BalanceTransactionSourceTypeReversal is a constant representing a transaction source of reversal
BalanceTransactionSourceTypeReversal BalanceTransactionSourceType = "reversal"

// BalanceTransactionSourceTypeTransfer is a constant representing a transaction source of transfer
BalanceTransactionSourceTypeTransfer BalanceTransactionSourceType = "transfer"
BalanceTransactionSourceTypeRefund BalanceTransactionSourceType = "refund"
BalanceTransactionSourceTypeReversal BalanceTransactionSourceType = "reversal"
BalanceTransactionSourceTypeTransfer BalanceTransactionSourceType = "transfer"
)

// BalanceTransactionSource describes the source of a balance Transaction.
Expand Down Expand Up @@ -103,7 +110,7 @@ type BalanceTransaction struct {
FeeDetails []BalanceTransactionFee `json:"fee_details"`
Net int64 `json:"net"`
Recipient string `json:"recipient"`
Source BalanceTransactionSource `json:"source"`
Source string `json:"source"`
Status BalanceTransactionStatus `json:"status"`
Type BalanceTransactionType `json:"type"`
}
Expand Down
19 changes: 0 additions & 19 deletions balance/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ import (
"github.com/stripe/stripe-go/form"
)

const (
BalanceTransactionAvailable stripe.BalanceTransactionStatus = "available"
BalanceTransactionPending stripe.BalanceTransactionStatus = "pending"

BalanceTransactionCharge stripe.BalanceTransactionType = "charge"
BalanceTransactionRefund stripe.BalanceTransactionType = "refund"
BalanceTransactionAdjust stripe.BalanceTransactionType = "adjustment"
BalanceTransactionAppFee stripe.BalanceTransactionType = "application_fee"
BalanceTransactionFeeRefund stripe.BalanceTransactionType = "application_fee_refund"
BalanceTransactionRecipientTransfer stripe.BalanceTransactionType = "recipient_transfer"
BalanceTransactionRecipientTransferCancel stripe.BalanceTransactionType = "recipient_transfer_cancel"
BalanceTransactionRecipientTransferFail stripe.BalanceTransactionType = "recipient_transfer_failure"
BalanceTransactionPayout stripe.BalanceTransactionType = "payout"
BalanceTransactionPayoutCancel stripe.BalanceTransactionType = "payout_cancel"
BalanceTransactionPayoutFail stripe.BalanceTransactionType = "payout_failure"
BalanceTransactionTransfer stripe.BalanceTransactionType = "transfer"
BalanceTransactionTransferCancel stripe.BalanceTransactionType = "transfer_refund"
)

// Client is used to invoke /balance and transaction-related APIs.
type Client struct {
B stripe.Backend
Expand Down
45 changes: 30 additions & 15 deletions bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@ import (
)

// BankAccountStatus is the list of allowed values for the bank account's status.
// Allowed values are "new", "validated", "verified", "verification_failed", "errored".
type BankAccountStatus string

const (
BankAccountStatusErrored BankAccountStatus = "errored"
BankAccountStatusNew BankAccountStatus = "new"
BankAccountStatusValidated BankAccountStatus = "validated"
BankAccountStatusVerificationFailed BankAccountStatus = "verification_failed"
BankAccountStatusVerified BankAccountStatus = "verified"
)

// BankAccountAccountHolderType is the list of allowed values for the bank account holder type.
type BankAccountAccountHolderType string

const (
BankAccountAccountHolderTypeCompany BankAccountAccountHolderType = "company"
BankAccountAccountHolderTypeIndividual BankAccountAccountHolderType = "individual"
)

// BankAccountParams is the set of parameters that can be used when updating a
// bank account.
//
Expand Down Expand Up @@ -112,20 +127,20 @@ type BankAccountListParams struct {

// BankAccount represents a Stripe bank account.
type BankAccount struct {
AccountHolderName string `json:"account_holder_name"`
AccountHolderType string `json:"account_holder_type"`
BankName string `json:"bank_name"`
Country string `json:"country"`
Currency Currency `json:"currency"`
Customer *Customer `json:"customer"`
DefaultForCurrency bool `json:"default_for_currency"`
Deleted bool `json:"deleted"`
Fingerprint string `json:"fingerprint"`
ID string `json:"id"`
Last4 string `json:"last4"`
Metadata map[string]string `json:"metadata"`
RoutingNumber string `json:"routing_number"`
Status BankAccountStatus `json:"status"`
AccountHolderName string `json:"account_holder_name"`
AccountHolderType BankAccountAccountHolderType `json:"account_holder_type"`
BankName string `json:"bank_name"`
Country string `json:"country"`
Currency Currency `json:"currency"`
Customer *Customer `json:"customer"`
DefaultForCurrency bool `json:"default_for_currency"`
Deleted bool `json:"deleted"`
Fingerprint string `json:"fingerprint"`
ID string `json:"id"`
Last4 string `json:"last4"`
Metadata map[string]string `json:"metadata"`
RoutingNumber string `json:"routing_number"`
Status BankAccountStatus `json:"status"`
}

// BankAccountList is a list object for bank accounts.
Expand Down
Loading

0 comments on commit 35258f8

Please sign in to comment.