Skip to content

Commit

Permalink
Remove all custom types based on string
Browse files Browse the repository at this point in the history
We want to stop using custom types that are alias to string. We also moved
all constants at the top-level for each package and renamed each ones to
make it clearer and avoid conflicts.
  • Loading branch information
remi-stripe committed Apr 18, 2018
1 parent c77c833 commit 825dce3
Show file tree
Hide file tree
Showing 55 changed files with 500 additions and 837 deletions.
110 changes: 52 additions & 58 deletions balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,52 @@ 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

// 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

// 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
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"
BalanceTransactionStatusAvailable string = "available"
BalanceTransactionStatusPending string = "pending"

BalanceTransactionSourceTypeApplicationFee string = "application_fee"
BalanceTransactionSourceTypeCharge string = "charge"
BalanceTransactionSourceTypeDispute string = "dispute"
BalanceTransactionSourceTypePayout string = "payout"
BalanceTransactionSourceTypeRecipientTransfer string = "recipient_transfer"
BalanceTransactionSourceTypeRefund string = "refund"
BalanceTransactionSourceTypeReversal string = "reversal"
BalanceTransactionSourceTypeTransfer string = "transfer"

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

// BalanceTransactionSource describes the source of a balance Transaction.
// The Type should indicate which object is fleshed out.
// For more details see https://stripe.com/docs/api#retrieve_balance_transaction
type BalanceTransactionSource struct {
ApplicationFee *ApplicationFee `json:"-"`
Charge *Charge `json:"-"`
Dispute *Dispute `json:"-"`
ID string `json:"id"`
Payout *Payout `json:"-"`
RecipientTransfer *RecipientTransfer `json:"-"`
Refund *Refund `json:"-"`
Reversal *Reversal `json:"-"`
Transfer *Transfer `json:"-"`
Type BalanceTransactionSourceType `json:"object"`
ApplicationFee *ApplicationFee `json:"-"`
Charge *Charge `json:"-"`
Dispute *Dispute `json:"-"`
ID string `json:"id"`
Payout *Payout `json:"-"`
RecipientTransfer *RecipientTransfer `json:"-"`
Refund *Refund `json:"-"`
Reversal *Reversal `json:"-"`
Transfer *Transfer `json:"-"`
Type string `json:"object"`
}

// BalanceParams is the set of parameters that can be used when retrieving a balance.
Expand Down Expand Up @@ -93,19 +87,19 @@ type Balance struct {
// BalanceTransaction is the resource representing the balance transaction.
// For more details see https://stripe.com/docs/api/#balance.
type BalanceTransaction struct {
Amount int64 `json:"amount"`
AvailableOn int64 `json:"available_on"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Description string `json:"description"`
ID string `json:"id"`
Fee int64 `json:"fee"`
FeeDetails []BalanceTransactionFee `json:"fee_details"`
Net int64 `json:"net"`
Recipient string `json:"recipient"`
Source BalanceTransactionSource `json:"source"`
Status BalanceTransactionStatus `json:"status"`
Type BalanceTransactionType `json:"type"`
Amount int64 `json:"amount"`
AvailableOn int64 `json:"available_on"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Description string `json:"description"`
ID string `json:"id"`
Fee int64 `json:"fee"`
FeeDetails []BalanceTransactionFee `json:"fee_details"`
Net int64 `json:"net"`
Recipient string `json:"recipient"`
Source string `json:"source"`
Status string `json:"status"`
Type string `json:"type"`
}

// BalanceTransactionList is a list of transactions as returned from a list endpoint.
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
16 changes: 9 additions & 7 deletions bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
)

const (
AccountHolderTypeCompany string = "company"
AccountHolderTypeIndividual string = "individual"
BankAccountAccountHolderTypeCompany string = "company"
BankAccountAccountHolderTypeIndividual string = "individual"

BankAccountStatusErrored string = "errored"
BankAccountStatusNew string = "new"
BankAccountStatusValidated string = "validated"
BankAccountStatusVerificationFailed string = "verification_failed"
BankAccountStatusVerified string = "verified"
)

// 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

// BankAccountParams is the set of parameters that can be used when updating a
// bank account.
//
Expand Down Expand Up @@ -130,7 +132,7 @@ type BankAccount struct {
Last4 string `json:"last4"`
Metadata map[string]string `json:"metadata"`
RoutingNumber string `json:"routing_number"`
Status BankAccountStatus `json:"status"`
Status string `json:"status"`
}

// BankAccountList is a list object for bank accounts.
Expand Down
8 changes: 0 additions & 8 deletions bankaccount/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ type Client struct {
Key string
}

const (
NewAccount stripe.BankAccountStatus = "new"
VerificationFAiledAccount stripe.BankAccountStatus = "verification_failed"
VerifiedAccount stripe.BankAccountStatus = "verified"
ValidatedAccount stripe.BankAccountStatus = "validated"
ErroredAccount stripe.BankAccountStatus = "errored"
)

// New POSTs a new bank account.
func New(params *stripe.BankAccountParams) (*stripe.BankAccount, error) {
return getC().New(params)
Expand Down
2 changes: 1 addition & 1 deletion bankaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestBankAccountParams_AppendToAsSourceOrExternalAccount(t *testing.T) {

// Includes account_holder_name
{
params := &BankAccountParams{AccountHolderType: String(string(AccountHolderTypeIndividual))}
params := &BankAccountParams{AccountHolderType: String(string(BankAccountAccountHolderTypeIndividual))}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
Expand Down
91 changes: 47 additions & 44 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@ import (
"github.com/stripe/stripe-go/form"
)

const (
CardBrandAmex string = "American Express"
CardBrandDiscover string = "Discover"
CardBrandDinersClub string = "Diners Club"
CardBrandJCB string = "JCB"
CardBrandMasterCard string = "MasterCard"
CardBrandUnknown string = "Unknown"
CardBrandUnionPay string = "UnionPay"
CardBrandVisa string = "Visa"

CardVerificationFail string = "fail"
CardVerificationPass string = "pass"
CardVerificationUnchecked string = "unchecked"

CardFundingCredit string = "credit"
CardFundingDebit string = "debit"
CardFundingPrepaid string = "prepaid"
CardFundingUnknown string = "unknown"
)

// cardSource is a string that's used to build card form parameters. It's a
// constant just to make mistakes less likely.
const cardSource = "source"

// CardBrand is the list of allowed values for the card's brand.
// Allowed values are "Unknown", "Visa", "American Express", "MasterCard", "Discover"
// "JCB", "Diners Club".
type CardBrand string

// CardFunding is the list of allowed values for the card's funding.
// Allowed values are "credit", "debit", "prepaid", "unknown".
type CardFunding string

// TokenizationMethod is the list of allowed values for the card's tokenization method.
// Allowed values are "apple_pay", "android_pay".
type TokenizationMethod string

// Verification is the list of allowed verification responses.
// Allowed values are "pass", "fail", "unchecked", "unavailable".
type Verification string

// CardParams is the set of parameters that can be used when creating or updating a card.
// For more details see https://stripe.com/docs/api#create_card and https://stripe.com/docs/api#update_card.
//
Expand Down Expand Up @@ -145,34 +148,34 @@ type CardListParams struct {
// Card is the resource representing a Stripe credit/debit card.
// For more details see https://stripe.com/docs/api#cards.
type Card struct {
AddressCity string `json:"address_city"`
AddressCountry string `json:"address_country"`
AddressLine1 string `json:"address_line1"`
AddressLine1Check Verification `json:"address_line1_check"`
AddressLine2 string `json:"address_line2"`
AddressState string `json:"address_state"`
AddressZip string `json:"address_zip"`
AddressZipCheck Verification `json:"address_zip_check"`
Brand CardBrand `json:"brand"`
CVCCheck Verification `json:"cvc_check"`
Country string `json:"country"`
Currency Currency `json:"currency"`
Customer *Customer `json:"customer"`
DefaultForCurrency bool `json:"default_for_currency"`
Deleted bool `json:"deleted"`
AddressCity string `json:"address_city"`
AddressCountry string `json:"address_country"`
AddressLine1 string `json:"address_line1"`
AddressLine1Check string `json:"address_line1_check"`
AddressLine2 string `json:"address_line2"`
AddressState string `json:"address_state"`
AddressZip string `json:"address_zip"`
AddressZipCheck string `json:"address_zip_check"`
Brand string `json:"brand"`
CVCCheck string `json:"cvc_check"`
Country string `json:"country"`
Currency Currency `json:"currency"`
Customer *Customer `json:"customer"`
DefaultForCurrency bool `json:"default_for_currency"`
Deleted bool `json:"deleted"`

// Description is a succinct summary of the card's information.
//
// Please note that this field is for internal use only and is not returned
// as part of standard API requests.
Description string `json:"description"`

DynamicLast4 string `json:"dynamic_last4"`
ExpMonth uint8 `json:"exp_month"`
ExpYear uint16 `json:"exp_year"`
Fingerprint string `json:"fingerprint"`
Funding CardFunding `json:"funding"`
ID string `json:"id"`
DynamicLast4 string `json:"dynamic_last4"`
ExpMonth uint8 `json:"exp_month"`
ExpYear uint16 `json:"exp_year"`
Fingerprint string `json:"fingerprint"`
Funding string `json:"funding"`
ID string `json:"id"`

// IIN is the card's "Issuer Identification Number".
//
Expand All @@ -186,12 +189,12 @@ type Card struct {
// as part of standard API requests.
Issuer string `json:"issuer"`

Last4 string `json:"last4"`
Metadata map[string]string `json:"metadata"`
Name string `json:"name"`
Recipient *Recipient `json:"recipient"`
ThreeDSecure *ThreeDSecure `json:"three_d_secure"`
TokenizationMethod TokenizationMethod `json:"tokenization_method"`
Last4 string `json:"last4"`
Metadata map[string]string `json:"metadata"`
Name string `json:"name"`
Recipient *Recipient `json:"recipient"`
ThreeDSecure *ThreeDSecure `json:"three_d_secure"`
TokenizationMethod string `json:"tokenization_method"`
}

// CardList is a list object for cards.
Expand Down
19 changes: 0 additions & 19 deletions card/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,6 @@ import (
"github.com/stripe/stripe-go/form"
)

const (
BrandUnknown stripe.CardBrand = "Unknown"
Visa stripe.CardBrand = "Visa"
Amex stripe.CardBrand = "American Express"
MasterCard stripe.CardBrand = "MasterCard"
Discover stripe.CardBrand = "Discover"
JCB stripe.CardBrand = "JCB"
DinersClub stripe.CardBrand = "Diners Club"

Pass stripe.Verification = "pass"
Fail stripe.Verification = "fail"
Unchecked stripe.Verification = "unchecked"

Credit stripe.CardFunding = "credit"
Debit stripe.CardFunding = "debit"
Prepaid stripe.CardFunding = "prepaid"
FundingUnknown stripe.CardFunding = "unknown"
)

// Client is used to invoke /cards APIs.
type Client struct {
B stripe.Backend
Expand Down
13 changes: 7 additions & 6 deletions charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"encoding/json"
)

const (
ChargeFraudReportFraudulent string = "fraudulent"
ChargeFraudReportSafe string = "safe"
)

// Currency is the list of supported currencies.
// For more details see https://support.stripe.com/questions/which-currencies-does-stripe-support.
type Currency string

// FraudReport is the list of allowed values for reporting fraud.
// Allowed values are "fraudulent", "safe".
type FraudReport string

// ChargeParams is the set of parameters that can be used when creating or updating a charge.
// For more details see https://stripe.com/docs/api#create_charge and https://stripe.com/docs/api#update_charge.
type ChargeParams struct {
Expand Down Expand Up @@ -143,8 +144,8 @@ type ChargeList struct {

// FraudDetails is the structure detailing fraud status.
type FraudDetails struct {
UserReport FraudReport `json:"user_report"`
StripeReport FraudReport `json:"stripe_report"`
UserReport string `json:"user_report"`
StripeReport string `json:"stripe_report"`
}

// ChargeOutcomeRule tells you the Radar rule that blocked the charge, if any.
Expand Down
Loading

0 comments on commit 825dce3

Please sign in to comment.