diff --git a/account.go b/account.go index 8c3a729083..4b0fd59c86 100644 --- a/account.go +++ b/account.go @@ -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. @@ -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"` @@ -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 @@ -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"` @@ -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. @@ -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"` } diff --git a/account/client_test.go b/account/client_test.go index a65fe7de4c..e7a4154889 100644 --- a/account/client_test.go +++ b/account/client_test.go @@ -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{ { @@ -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) diff --git a/balance.go b/balance.go index 4cc080c8dd..d0ab108fba 100644 --- a/balance.go +++ b/balance.go @@ -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. @@ -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"` } diff --git a/balance/client.go b/balance/client.go index 0848254990..f1e1f634c3 100644 --- a/balance/client.go +++ b/balance/client.go @@ -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 diff --git a/bankaccount.go b/bankaccount.go index 6bd964fe1d..a31a2a1601 100644 --- a/bankaccount.go +++ b/bankaccount.go @@ -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. // @@ -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. diff --git a/bankaccount/client.go b/bankaccount/client.go index 4a6eb3fa06..d4fe33a75f 100644 --- a/bankaccount/client.go +++ b/bankaccount/client.go @@ -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) diff --git a/bankaccount_test.go b/bankaccount_test.go index ace1b6b6ab..f1c57e6e23 100644 --- a/bankaccount_test.go +++ b/bankaccount_test.go @@ -30,7 +30,7 @@ func TestBankAccountParams_AppendToAsSourceOrExternalAccount(t *testing.T) { // Includes account_holder_name { - params := &BankAccountParams{AccountHolderType: String(string(Individual))} + params := &BankAccountParams{AccountHolderType: String(string(BankAccountAccountHolderTypeIndividual))} body := &form.Values{} params.AppendToAsSourceOrExternalAccount(body) t.Logf("body = %+v", body) diff --git a/card.go b/card.go index f9323530d4..b4d9d28dcd 100644 --- a/card.go +++ b/card.go @@ -7,26 +7,50 @@ import ( "github.com/stripe/stripe-go/form" ) -// 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 +const ( + CardBrandAmex CardBrand = "American Express" + CardBrandDiscover CardBrand = "Discover" + CardBrandDinersClub CardBrand = "Diners Club" + CardBrandJCB CardBrand = "JCB" + CardBrandMasterCard CardBrand = "MasterCard" + CardBrandUnknown CardBrand = "Unknown" + CardBrandUnionPay CardBrand = "UnionPay" + CardBrandVisa CardBrand = "Visa" +) + // 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 +const ( + CardFundingCredit CardFunding = "credit" + CardFundingDebit CardFunding = "debit" + CardFundingPrepaid CardFunding = "prepaid" + CardFundingUnknown CardFunding = "unknown" +) + +// CardTokenizationMethod is the list of allowed values for the card's tokenization method. +type CardTokenizationMethod string -// Verification is the list of allowed verification responses. -// Allowed values are "pass", "fail", "unchecked", "unavailable". -type Verification string +const ( + TokenizationMethodAndroidPay CardTokenizationMethod = "android_pay" + TokenizationMethodApplePay CardTokenizationMethod = "apple_pay" +) + +// CardVerification is the list of allowed verification responses. +type CardVerification string + +const ( + CardVerificationFail CardVerification = "fail" + CardVerificationPass CardVerification = "pass" + CardVerificationUnchecked CardVerification = "unchecked" +) + +// 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" // 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. @@ -147,21 +171,21 @@ 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 CardVerification `json:"address_line1_check"` + AddressLine2 string `json:"address_line2"` + AddressState string `json:"address_state"` + AddressZip string `json:"address_zip"` + AddressZipCheck CardVerification `json:"address_zip_check"` + Brand CardBrand `json:"brand"` + CVCCheck CardVerification `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. // @@ -188,12 +212,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 CardTokenizationMethod `json:"tokenization_method"` } // CardList is a list object for cards. diff --git a/card/client.go b/card/client.go index c21032201f..baf6846095 100644 --- a/card/client.go +++ b/card/client.go @@ -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 diff --git a/charge.go b/charge.go index 5f0032cf70..e3a9606d74 100644 --- a/charge.go +++ b/charge.go @@ -4,14 +4,25 @@ import ( "encoding/json" ) +// ChargeFraudUserReport is the list of allowed values for reporting fraud. +type ChargeFraudUserReport string + +const ( + ChargeFraudUserReportFraudulent ChargeFraudUserReport = "fraudulent" + ChargeFraudUserReportSafe ChargeFraudUserReport = "safe" +) + +// ChargeFraudStripeReport is the list of allowed values for reporting fraud. +type ChargeFraudStripeReport string + +const ( + ChargeFraudStripeReportFraudulent ChargeFraudStripeReport = "fraudulent" +) + // 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 { @@ -143,8 +154,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 ChargeFraudUserReport `json:"user_report"` + StripeReport ChargeFraudStripeReport `json:"stripe_report"` } // ChargeOutcomeRule tells you the Radar rule that blocked the charge, if any. diff --git a/charge/client.go b/charge/client.go index 8ed79ef06f..f67dc9cac9 100644 --- a/charge/client.go +++ b/charge/client.go @@ -8,11 +8,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - ReportFraudulent stripe.FraudReport = "fraudulent" - ReportSafe stripe.FraudReport = "safe" -) - // Client is used to invoke /charges APIs. type Client struct { B stripe.Backend @@ -143,7 +138,7 @@ func (c Client) MarkFraudulent(id string) (*stripe.Charge, error) { id, &stripe.ChargeParams{ FraudDetails: &stripe.FraudDetailsParams{ - UserReport: stripe.String(string(ReportFraudulent)), + UserReport: stripe.String(string(stripe.ChargeFraudUserReportFraudulent)), }, }, ) @@ -159,7 +154,7 @@ func (c Client) MarkSafe(id string) (*stripe.Charge, error) { id, &stripe.ChargeParams{ FraudDetails: &stripe.FraudDetailsParams{ - UserReport: stripe.String(string(ReportSafe)), + UserReport: stripe.String(string(stripe.ChargeFraudUserReportSafe)), }, }, ) diff --git a/coupon.go b/coupon.go index 2cec158b1d..8a5809c3d1 100644 --- a/coupon.go +++ b/coupon.go @@ -3,9 +3,14 @@ package stripe import "encoding/json" // CouponDuration is the list of allowed values for the coupon's duration. -// Allowed values are "forever", "once", "repeating". type CouponDuration string +const ( + CouponDurationForever CouponDuration = "forever" + CouponDurationOnce CouponDuration = "once" + CouponDurationRepeating CouponDuration = "repeating" +) + // CouponParams is the set of parameters that can be used when creating a coupon. // For more details see https://stripe.com/docs/api#create_coupon. type CouponParams struct { diff --git a/coupon/client.go b/coupon/client.go index 8ffd2d2fb9..412a48b4e5 100644 --- a/coupon/client.go +++ b/coupon/client.go @@ -8,12 +8,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - Forever stripe.CouponDuration = "forever" - Once stripe.CouponDuration = "once" - Repeating stripe.CouponDuration = "repeating" -) - // Client is used to invoke /coupons APIs. type Client struct { B stripe.Backend diff --git a/coupon/client_test.go b/coupon/client_test.go index 7870bb4b7f..8027ee4909 100644 --- a/coupon/client_test.go +++ b/coupon/client_test.go @@ -33,7 +33,7 @@ func TestCouponList(t *testing.T) { func TestCouponNew(t *testing.T) { coupon, err := New(&stripe.CouponParams{ Currency: stripe.String(string(currency.USD)), - Duration: stripe.String(string(Repeating)), + Duration: stripe.String(string(stripe.CouponDurationRepeating)), DurationInMonths: stripe.Int64(3), ID: stripe.String("25OFF"), PercentOff: stripe.Int64(25), diff --git a/dispute.go b/dispute.go index d3dc1083b0..674469c54d 100644 --- a/dispute.go +++ b/dispute.go @@ -5,17 +5,33 @@ import ( ) // DisputeReason is the list of allowed values for a discount's reason. -// Allowed values are "duplicate", "fraudulent", "subscription_canceled", -// "product_unacceptable", "product_not_received", "unrecognized", -// "credit_not_processed", "general". type DisputeReason string +const ( + DisputeReasonCreditNotProcessed DisputeReason = "credit_not_processed" + DisputeReasonDuplicate DisputeReason = "duplicate" + DisputeReasonFraudulent DisputeReason = "fraudulent" + DisputeReasonGeneral DisputeReason = "general" + DisputeReasonProductNotReceived DisputeReason = "product_not_received" + DisputeReasonProductUnacceptable DisputeReason = "product_unacceptable" + DisputeReasonSubscriptionCanceled DisputeReason = "subscription_canceled" + DisputeReasonUnrecognized DisputeReason = "unrecognized" +) + // DisputeStatus is the list of allowed values for a discount's status. -// Allowed values are "won", "lost", "needs_response", "under_review", -// "warning_needs_response", "warning_under_review", "charge_refunded", -// "warning_closed". type DisputeStatus string +const ( + DisputeStatusChargeRefunded DisputeStatus = "charge_refunded" + DisputeStatusLost DisputeStatus = "lost" + DisputeStatusNeedsResponse DisputeStatus = "needs_response" + DisputeStatusUnderReview DisputeStatus = "under_review" + DisputeStatusWarningClosed DisputeStatus = "warning_closed" + DisputeStatusWarningNeedsResponse DisputeStatus = "warning_needs_response" + DisputeStatusWarningUnderReview DisputeStatus = "warning_under_review" + DisputeStatusWon DisputeStatus = "won" +) + // DisputeParams is the set of parameters that can be used when updating a dispute. // For more details see https://stripe.com/docs/api#update_dispute. type DisputeParams struct { diff --git a/dispute/client.go b/dispute/client.go index 9e20baae9d..37991831ef 100644 --- a/dispute/client.go +++ b/dispute/client.go @@ -7,26 +7,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - CreditNotProcessed stripe.DisputeReason = "credit_not_processed" - Duplicate stripe.DisputeReason = "duplicate" - Fraudulent stripe.DisputeReason = "fraudulent" - General stripe.DisputeReason = "general" - ProductNotReceived stripe.DisputeReason = "product_not_received" - ProductUnacceptable stripe.DisputeReason = "product_unacceptable" - SubscriptionCanceled stripe.DisputeReason = "subscription_canceled" - Unrecognized stripe.DisputeReason = "unrecognized" - - Lost stripe.DisputeStatus = "lost" - NeedsResponse stripe.DisputeStatus = "needs_response" - ChargeRefunded stripe.DisputeStatus = "charge_refunded" - UnderReview stripe.DisputeStatus = "under_review" - WarningClosed stripe.DisputeStatus = "warning_closed" - WarningNeedsResponse stripe.DisputeStatus = "warning_needs_response" - WarningUnderReview stripe.DisputeStatus = "warning_under_review" - Won stripe.DisputeStatus = "won" -) - // Client is used to invoke dispute-related APIs. type Client struct { B stripe.Backend diff --git a/error.go b/error.go index fb00d31969..f1356ce4cb 100644 --- a/error.go +++ b/error.go @@ -5,9 +5,6 @@ import "encoding/json" // ErrorType is the list of allowed values for the error's type. type ErrorType string -// ErrorCode is the list of allowed values for the error's code. -type ErrorCode string - const ( ErrorTypeAPI ErrorType = "api_error" ErrorTypeAPIConnection ErrorType = "api_connection_error" @@ -16,7 +13,12 @@ const ( ErrorTypeInvalidRequest ErrorType = "invalid_request_error" ErrorTypePermission ErrorType = "more_permissions_required" ErrorTypeRateLimit ErrorType = "rate_limit_error" +) +// ErrorCode is the list of allowed values for the error's code. +type ErrorCode string + +const ( ErrorCodeCardDeclined ErrorCode = "card_declined" ErrorCodeExpiredCard ErrorCode = "expired_card" ErrorCodeIncorrectCVC ErrorCode = "incorrect_cvc" diff --git a/fileupload.go b/fileupload.go index ce7ec78815..7a6ef8490a 100644 --- a/fileupload.go +++ b/fileupload.go @@ -7,6 +7,14 @@ import ( "path/filepath" ) +// FileUploadPurpose is the purpose of a particular file upload. +type FileUploadPurpose string + +const ( + FileUploadPurposeDisputeEvidence FileUploadPurpose = "dispute_evidence" + FileUploadPurposeIdentityDocument FileUploadPurpose = "identity_document" +) + // FileUploadParams is the set of parameters that can be used when creating a // file upload. // For more details see https://stripe.com/docs/api#create_file_upload. @@ -31,10 +39,6 @@ type FileUploadListParams struct { Purpose *string `form:"purpose"` } -// FileUploadPurpose is the purpose of a particular file upload. Allowed values -// are "dispute_evidence" and "identity_document". -type FileUploadPurpose string - // FileUpload is the resource representing a Stripe file upload. // For more details see https://stripe.com/docs/api#file_uploads. type FileUpload struct { diff --git a/fileupload/client.go b/fileupload/client.go index a8280618b7..459a7712aa 100644 --- a/fileupload/client.go +++ b/fileupload/client.go @@ -9,11 +9,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - DisputeEvidenceFile stripe.FileUploadPurpose = "dispute_evidence" - IdentityDocFile stripe.FileUploadPurpose = "identity_document" -) - // Client is used to invoke file upload APIs. type Client struct { B stripe.Backend diff --git a/fileupload/client_test.go b/fileupload/client_test.go index 3c8eb228e0..a6f9c6c7a6 100644 --- a/fileupload/client_test.go +++ b/fileupload/client_test.go @@ -34,7 +34,7 @@ func TestFileUploadNewThenGet(t *testing.T) { } uploadParams := &stripe.FileUploadParams{ - Purpose: stripe.String(string(DisputeEvidenceFile)), + Purpose: stripe.String(string(stripe.FileUploadPurposeDisputeEvidence)), FileReader: f, Filename: stripe.String(f.Name()), } @@ -59,7 +59,7 @@ func TestFileUploadList(t *testing.T) { } uploadParams := &stripe.FileUploadParams{ - Purpose: stripe.String(string(DisputeEvidenceFile)), + Purpose: stripe.String(string(stripe.FileUploadPurposeDisputeEvidence)), FileReader: f, Filename: stripe.String(f.Name()), } diff --git a/invoice.go b/invoice.go index 10d76d46cf..982f9c68ad 100644 --- a/invoice.go +++ b/invoice.go @@ -6,10 +6,20 @@ import "encoding/json" // Allowed values are "invoiceitem", "subscription". type InvoiceLineType string +const ( + InvoiceLineTypeInvoiceItem InvoiceLineType = "invoiceitem" + InvoiceLineTypeSubscription InvoiceLineType = "subscription" +) + // InvoiceBilling is the type of billing method for this invoice. // Currently supported values are "send_invoice" and "charge_automatically". type InvoiceBilling string +const ( + InvoiceBillingChargeAutomatically InvoiceBilling = "charge_automatically" + InvoiceBillingSendInvoice InvoiceBilling = "send_invoice" +) + // InvoiceParams is the set of parameters that can be used when creating or updating an invoice. // For more details see https://stripe.com/docs/api#create_invoice, https://stripe.com/docs/api#update_invoice. type InvoiceParams struct { diff --git a/invoice/client.go b/invoice/client.go index 04245e0096..ba3e10532e 100644 --- a/invoice/client.go +++ b/invoice/client.go @@ -8,11 +8,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - TypeInvoiceItem stripe.InvoiceLineType = "invoiceitem" - TypeSubscription stripe.InvoiceLineType = "subscription" -) - // Client is the client used to invoke /invoices APIs. type Client struct { B stripe.Backend diff --git a/invoice/client_test.go b/invoice/client_test.go index ad1cc5d66a..e7722810de 100644 --- a/invoice/client_test.go +++ b/invoice/client_test.go @@ -36,7 +36,7 @@ func TestInvoiceListLines(t *testing.T) { func TestInvoiceNew(t *testing.T) { invoice, err := New(&stripe.InvoiceParams{ - Billing: stripe.String("charge_automatically"), + Billing: stripe.String(string(stripe.InvoiceBillingChargeAutomatically)), Customer: stripe.String("cus_123"), }) assert.Nil(t, err) diff --git a/order.go b/order.go index 243d29cd45..8886d46c4b 100644 --- a/order.go +++ b/order.go @@ -8,11 +8,29 @@ import ( type OrderStatus string const ( - StatusCanceled OrderStatus = "canceled" - StatusCreated OrderStatus = "created" - StatusFulfilled OrderStatus = "fulfilled" - StatusPaid OrderStatus = "paid" - StatusReturned OrderStatus = "returned" + OrderStatusCanceled OrderStatus = "canceled" + OrderStatusCreated OrderStatus = "created" + OrderStatusFulfilled OrderStatus = "fulfilled" + OrderStatusPaid OrderStatus = "paid" + OrderStatusReturned OrderStatus = "returned" +) + +// OrderDeliveryEstimateType represents the type of delivery estimate for shipping methods +type OrderDeliveryEstimateType string + +const ( + OrderDeliveryEstimateTypeExact OrderDeliveryEstimateType = "exact" + OrderDeliveryEstimateTypeRange OrderDeliveryEstimateType = "range" +) + +// OrderItemType represents the type of order item +type OrderItemType string + +const ( + OrderItemTeypeDiscount OrderItemType = "discount" + OrderItemTeypeShipping OrderItemType = "shipping" + OrderItemTeypeSKU OrderItemType = "sku" + OrderItemTeypeTax OrderItemType = "tax" ) type OrderParams struct { @@ -67,20 +85,13 @@ type ShippingMethod struct { Description string `json:"description"` } -type EstimateType string - -const ( - Exact EstimateType = "exact" - Range EstimateType = "range" -) - type DeliveryEstimate struct { // If Type == Exact Date string `json:"date"` // If Type == Range - Earliest string `json:"earliest"` - Latest string `json:"latest"` - Type EstimateType `json:"type"` + Earliest string `json:"earliest"` + Latest string `json:"latest"` + Type OrderDeliveryEstimateType `json:"type"` } type Order struct { @@ -101,7 +112,7 @@ type Order struct { SelectedShippingMethod *string `json:"selected_shipping_method"` Shipping Shipping `json:"shipping"` ShippingMethods []ShippingMethod `json:"shipping_methods"` - Status OrderStatus `json:"status"` + Status string `json:"status"` StatusTransitions StatusTransitions `json:"status_transitions"` Updated int64 `json:"updated"` } @@ -144,6 +155,24 @@ type OrderPayParams struct { Source *SourceParams `form:"*"` // SourceParams has custom encoding so brought to top level with "*" } +type OrderItemParams struct { + Amount *int64 `form:"amount"` + Currency *string `form:"currency"` + Description *string `form:"description"` + Parent *string `form:"parent"` + Quantity *int64 `form:"quantity"` + Type *string `form:"type"` +} + +type OrderItem struct { + Amount int64 `json:"amount"` + Currency Currency `json:"currency"` + Description string `json:"description"` + Parent string `json:"parent"` + Quantity int64 `json:"quantity"` + Type OrderItemType `json:"type"` +} + // SetSource adds valid sources to a OrderParams object, // returning an error for unsupported sources. func (op *OrderPayParams) SetSource(sp interface{}) error { diff --git a/order/client_test.go b/order/client_test.go index e08cda6a96..e1db42d224 100644 --- a/order/client_test.go +++ b/order/client_test.go @@ -83,7 +83,7 @@ func TestOrderReturn_RequestParams(t *testing.T) { func TestOrderUpdate(t *testing.T) { order, err := Update("or_123", &stripe.OrderUpdateParams{ - Status: stripe.String(string(stripe.StatusFulfilled)), + Status: stripe.String(string(stripe.OrderStatusFulfilled)), }) assert.Nil(t, err) assert.NotNil(t, order) diff --git a/orderitem.go b/orderitem.go deleted file mode 100644 index 7c8a471fb4..0000000000 --- a/orderitem.go +++ /dev/null @@ -1,26 +0,0 @@ -package stripe - -import ( - // This is pretty silly. Nowhere else do we import a subpackage from the - // top-level namespace like this. We should try to deprecate this at some - // point. - "github.com/stripe/stripe-go/orderitem" -) - -type OrderItemParams struct { - Amount *int64 `form:"amount"` - Currency *string `form:"currency"` - Description *string `form:"description"` - Parent *string `form:"parent"` - Quantity *int64 `form:"quantity"` - Type *string `form:"type"` -} - -type OrderItem struct { - Amount int64 `json:"amount"` - Currency Currency `json:"currency"` - Description string `json:"description"` - Parent string `json:"parent"` - Quantity int64 `json:"quantity"` - Type orderitem.ItemType `json:"type"` -} diff --git a/orderitem/order_item.go b/orderitem/order_item.go deleted file mode 100644 index b9a92920e3..0000000000 --- a/orderitem/order_item.go +++ /dev/null @@ -1,12 +0,0 @@ -package orderitem - -// OrderItemType represents one of the possible types that an order's OrderItem -// can have. -type ItemType string - -const ( - SKU ItemType = "sku" - Tax ItemType = "tax" - Shipping ItemType = "shipping" - Discount ItemType = "discount" -) diff --git a/orderitem/order_item_test.go b/orderitem/order_item_test.go deleted file mode 100644 index ebd4e8162e..0000000000 --- a/orderitem/order_item_test.go +++ /dev/null @@ -1 +0,0 @@ -package orderitem diff --git a/paymentsource.go b/paymentsource.go index 9bd5e3469c..d9247e20b0 100644 --- a/paymentsource.go +++ b/paymentsource.go @@ -7,6 +7,17 @@ import ( "github.com/stripe/stripe-go/form" ) +// PaymentSourceType consts represent valid payment sources. +type PaymentSourceType string + +const ( + PaymentSourceTypeAccount PaymentSourceType = "account" + PaymentSourceTypeBankAccount PaymentSourceType = "bank_account" + PaymentSourceTypeBitcoinReceiver PaymentSourceType = "bitcoin_receiver" + PaymentSourceTypeCard PaymentSourceType = "card" + PaymentSourceTypeObject PaymentSourceType = "source" +) + // SourceParams is a union struct used to describe an // arbitrary payment source. type SourceParams struct { @@ -70,31 +81,6 @@ func SourceParamsFor(obj interface{}) (*SourceParams, error) { return sp, err } -// PaymentSourceType consts represent valid payment sources. -type PaymentSourceType string - -const ( - // PaymentSourceAccount is a constant representing a payment source which is - // an account. - PaymentSourceAccount PaymentSourceType = "account" - - // PaymentSourceBankAccount is a constant representing a payment source - // which is a bank account. - PaymentSourceBankAccount PaymentSourceType = "bank_account" - - // PaymentSourceBitcoinReceiver is a constant representing a payment source - // which is a Bitcoin receiver. - PaymentSourceBitcoinReceiver PaymentSourceType = "bitcoin_receiver" - - // PaymentSourceCard is a constant representing a payment source which is a - // card. - PaymentSourceCard PaymentSourceType = "card" - - // PaymentSourceObject is a constant representing a payment source which - // is a top level source object (/v1/sources). - PaymentSourceObject PaymentSourceType = "source" -) - // PaymentSource describes the payment source used to make a Charge. // The Type should indicate which object is fleshed out (eg. BitcoinReceiver or Card) // For more details see https://stripe.com/docs/api#retrieve_charge @@ -132,13 +118,13 @@ func (s *PaymentSource) UnmarshalJSON(data []byte) error { *s = PaymentSource(ss) switch s.Type { - case PaymentSourceBankAccount: + case PaymentSourceTypeBankAccount: err = json.Unmarshal(data, &s.BankAccount) - case PaymentSourceBitcoinReceiver: + case PaymentSourceTypeBitcoinReceiver: err = json.Unmarshal(data, &s.BitcoinReceiver) - case PaymentSourceCard: + case PaymentSourceTypeCard: err = json.Unmarshal(data, &s.Card) - case PaymentSourceObject: + case PaymentSourceTypeObject: err = json.Unmarshal(data, &s.SourceObject) } @@ -155,12 +141,12 @@ func (s *PaymentSource) UnmarshalJSON(data []byte) error { // MarshalJSON handles serialization of a PaymentSource. // This custom marshaling is needed because the specific type -// of payment instrument it represents is specified by the PaymentSourceType +// of payment instrument it represents is specified by the Type func (s *PaymentSource) MarshalJSON() ([]byte, error) { var target interface{} switch s.Type { - case PaymentSourceBitcoinReceiver: + case PaymentSourceTypeBitcoinReceiver: target = struct { *BitcoinReceiver Type PaymentSourceType `json:"object"` @@ -168,7 +154,7 @@ func (s *PaymentSource) MarshalJSON() ([]byte, error) { BitcoinReceiver: s.BitcoinReceiver, Type: s.Type, } - case PaymentSourceCard: + case PaymentSourceTypeCard: var customerID *string if s.Card.Customer != nil { customerID = &s.Card.Customer.ID @@ -183,7 +169,7 @@ func (s *PaymentSource) MarshalJSON() ([]byte, error) { Customer: customerID, Type: s.Type, } - case PaymentSourceAccount: + case PaymentSourceTypeAccount: target = struct { ID string `json:"id"` Type PaymentSourceType `json:"object"` @@ -191,7 +177,7 @@ func (s *PaymentSource) MarshalJSON() ([]byte, error) { ID: s.ID, Type: s.Type, } - case PaymentSourceBankAccount: + case PaymentSourceTypeBankAccount: var customerID *string if s.BankAccount.Customer != nil { customerID = &s.BankAccount.Customer.ID diff --git a/paymentsource_test.go b/paymentsource_test.go index 7fefedc541..28e5bfe12d 100644 --- a/paymentsource_test.go +++ b/paymentsource_test.go @@ -32,7 +32,7 @@ func TestPaymentSource_MarshalJSON(t *testing.T) { id := "card_123" name := "alice cooper" paymentSource := &PaymentSource{ - Type: PaymentSourceCard, + Type: PaymentSourceTypeCard, ID: id, Card: &Card{ ID: id, @@ -58,7 +58,7 @@ func TestPaymentSource_MarshalJSON(t *testing.T) { id := "ba_123" name := "big bank" paymentSource := &PaymentSource{ - Type: PaymentSourceBankAccount, + Type: PaymentSourceTypeBankAccount, ID: id, BankAccount: &BankAccount{ ID: id, diff --git a/payout.go b/payout.go index 13b9855cda..276f7b5ecb 100644 --- a/payout.go +++ b/payout.go @@ -5,42 +5,61 @@ import "encoding/json" // PayoutDestinationType consts represent valid payout destinations. type PayoutDestinationType string +const ( + PayoutDestinationTypeBankAccount PayoutDestinationType = "bank_account" + PayoutDestinationTypeCard PayoutDestinationType = "card" +) + // PayoutFailureCode is the list of allowed values for the payout's failure code. -// Allowed values are "insufficient_funds", "account_closed", "no_account", -// "invalid_account_number", "debit_not_authorized", "bank_ownership_changed", -// "account_frozen", "could_not_process", "bank_account_restricted", "invalid_currency". type PayoutFailureCode string +const ( + PayoutFailureCodeAccountClosed PayoutFailureCode = "account_closed" + PayoutFailureCodeAccountFrozen PayoutFailureCode = "account_frozen" + PayoutFailureCodeBankAccountRestricted PayoutFailureCode = "bank_account_restricted" + PayoutFailureCodeBankOwnershipChanged PayoutFailureCode = "bank_ownership_changed" + PayoutFailureCodeCouldNotProcess PayoutFailureCode = "could_not_process" + PayoutFailureCodeDebitNotAuthorized PayoutFailureCode = "debit_not_authorized" + PayoutFailureCodeInsufficientFunds PayoutFailureCode = "insufficient_funds" + PayoutFailureCodeInvalidAccountNumber PayoutFailureCode = "invalid_account_number" + PayoutFailureCodeInvalidCurrency PayoutFailureCode = "invalid_currency" + PayoutFailureCodeNoAccount PayoutFailureCode = "no_account" +) + // PayoutSourceType is the list of allowed values for the payout's source_type field. -// Allowed values are "alipay_account", bank_account", "bitcoin_receiver", "card". type PayoutSourceType string +const ( + PayoutSourceTypeAlipayAccount PayoutSourceType = "alipay_account" + PayoutSourceTypeBankAccount PayoutSourceType = "bank_account" + PayoutSourceTypeBitcoinReceiver PayoutSourceType = "bitcoin_receiver" + PayoutSourceTypeCard PayoutSourceType = "card" +) + // PayoutStatus is the list of allowed values for the payout's status. -// Allowed values are "paid", "pending", "in_transit", "failed", "canceled". type PayoutStatus string +const ( + PayoutStatusCanceled PayoutStatus = "canceled" + PayoutStatusFailed PayoutStatus = "failed" + PayoutStatusInTransit PayoutStatus = "in_transit" + PayoutStatusPaid PayoutStatus = "paid" + PayoutStatusPending PayoutStatus = "pending" +) + // PayoutType is the list of allowed values for the payout's type. -// Allowed values are "bank_account" or "card". type PayoutType string const ( - // PayoutDestinationBankAccount is a constant representing a payout destination - // which is a bank account. - PayoutDestinationBankAccount PayoutDestinationType = "bank_account" - - // PayoutDestinationCard is a constant representing a payout destination - // which is a card. - PayoutDestinationCard PayoutDestinationType = "card" + PayoutTypeBank PayoutType = "bank_account" + PayoutTypeCard PayoutType = "card" ) // PayoutMethodType represents the type of payout type PayoutMethodType string const ( - // PayoutMethodInstant is a constant representing an instant payout - PayoutMethodInstant PayoutMethodType = "instant" - - // PayoutMethodStandard is a constant representing a standard payout + PayoutMethodInstant PayoutMethodType = "instant" PayoutMethodStandard PayoutMethodType = "standard" ) @@ -89,7 +108,7 @@ type Payout struct { Card *Card `json:"card"` Created int64 `json:"created"` Currency Currency `json:"currency"` - Destination PayoutDestination `json:"destination"` + Destination string `json:"destination"` FailureBalanceTransaction *BalanceTransaction `json:"failure_balance_transaction"` FailureCode PayoutFailureCode `json:"failure_code"` FailureMessage string `json:"failure_message"` @@ -137,9 +156,9 @@ func (d *PayoutDestination) UnmarshalJSON(data []byte) error { *d = PayoutDestination(dd) switch d.Type { - case PayoutDestinationBankAccount: + case PayoutDestinationTypeBankAccount: err = json.Unmarshal(data, &d.BankAccount) - case PayoutDestinationCard: + case PayoutDestinationTypeCard: err = json.Unmarshal(data, &d.Card) } diff --git a/payout/client.go b/payout/client.go index ea2bc46a58..c528be47e7 100644 --- a/payout/client.go +++ b/payout/client.go @@ -8,33 +8,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - Canceled stripe.PayoutStatus = "canceled" - Failed stripe.PayoutStatus = "failed" - Paid stripe.PayoutStatus = "paid" - Pending stripe.PayoutStatus = "pending" - Transit stripe.PayoutStatus = "in_transit" - - Bank stripe.PayoutType = "bank_account" - Card stripe.PayoutType = "card" - - SourceAlipay stripe.PayoutSourceType = "alipay_account" - SourceBank stripe.PayoutSourceType = "bank_account" - SourceBitcoin stripe.PayoutSourceType = "bitcoin_receiver" - SourceCard stripe.PayoutSourceType = "card" - - AccountClosed stripe.PayoutFailureCode = "account_closed" - AccountFrozen stripe.PayoutFailureCode = "account_frozen" - BankAccountRestrict stripe.PayoutFailureCode = "bank_account_restricted" - BankOwnerChanged stripe.PayoutFailureCode = "bank_ownership_changed" - CouldNotProcess stripe.PayoutFailureCode = "could_not_process" - DebitNotAuth stripe.PayoutFailureCode = "debit_not_authorized" - InsufficientFunds stripe.PayoutFailureCode = "insufficient_funds" - InvalidAccountNumber stripe.PayoutFailureCode = "invalid_account_number" - InvalidCurrency stripe.PayoutFailureCode = "invalid_currency" - NoAccount stripe.PayoutFailureCode = "no_account" -) - // Client is used to invoke /payouts APIs. type Client struct { B stripe.Backend diff --git a/plan.go b/plan.go index 1284aab1c7..be02f5fe2d 100644 --- a/plan.go +++ b/plan.go @@ -7,41 +7,44 @@ import ( ) // PlanInterval is the list of allowed values for a plan's interval. -// Allowed values are "day", "week", "month", "year". type PlanInterval string const ( - // PlanBillingSchemeTiered indicates that the price per single unit is tiered - // and can change with the total number of units. - PlanBillingSchemeTiered string = "tiered" - // PlanBillingSchemePerUnit indicates that each unit is billed at a fixed - // price. - PlanBillingSchemePerUnit string = "per_unit" + PlanIntervalDay PlanInterval = "day" + PlanIntervalWeek PlanInterval = "week" + PlanIntervalMonth PlanInterval = "month" + PlanIntervalYear PlanInterval = "year" ) +// PlanBillingScheme is the list of allowed values for a plan's billing scheme. +type PlanBillingScheme string + +const ( + PlanBillingSchemePerUnit PlanBillingScheme = "per_unit" + PlanBillingSchemeTiered PlanBillingScheme = "tiered" +) + +// PlanUsageType is the list of allowed values for a plan's usage type. +type PlanUsageType string + const ( - // PlanUsageTypeLicensed indicates that the set Quantity on a subscription item - // will be used to bill for a subscription. - PlanUsageTypeLicensed string = "licensed" - // PlanUsageTypeMetered indicates that usage records must be reported instead - // of setting a Quantity on a subscription item. - PlanUsageTypeMetered string = "metered" + PlanUsageTypeLicensed PlanUsageType = "licensed" + PlanUsageTypeMetered PlanUsageType = "metered" ) +// PlanTransformUsageRound is the list of allowed values for a plan's transform usage round logic. +type PlanTransformUsageRound string + const ( - // PlanTransformUsageModeRoundDown represents a bucket billing configuration: a partially - // filled bucket will count as an empty bucket. - PlanTransformUsageModeRoundDown string = "round_down" - // PlanTransformUsageModeRoundUp represents a bucket billing configuration: a partially - // filled bucket will count as a full bucket. - PlanTransformUsageModeRoundUp string = "round_up" + PlanTransformUsageRoundDown PlanTransformUsageRound = "down" + PlanTransformUsageRoundUp PlanTransformUsageRound = "up" ) // Plan is the resource representing a Stripe plan. // For more details see https://stripe.com/docs/api#plans. type Plan struct { Amount int64 `json:"amount"` - BillingScheme string `json:"billing_scheme"` + BillingScheme PlanBillingScheme `json:"billing_scheme"` Created int64 `json:"created"` Currency Currency `json:"currency"` Deleted bool `json:"deleted"` @@ -56,7 +59,7 @@ type Plan struct { TiersMode string `json:"tiers_mode"` TransformUsage *PlanTransformUsage `json:"transform_usage"` TrialPeriodDays int64 `json:"trial_period_days"` - UsageType string `json:"usage_type"` + UsageType PlanUsageType `json:"usage_type"` } // PlanList is a list of plans as returned from a list endpoint. @@ -101,8 +104,8 @@ type PlanTier struct { // PlanTransformUsage represents the bucket billing configuration. type PlanTransformUsage struct { - DivideBy int64 `json:"bucket_size"` - Round string `json:"round"` + DivideBy int64 `json:"bucket_size"` + Round PlanTransformUsageRound `json:"round"` } // PlanTransformUsageParams represents the bucket billing configuration. diff --git a/plan/client.go b/plan/client.go index 409ce67200..8195a607a2 100644 --- a/plan/client.go +++ b/plan/client.go @@ -9,13 +9,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - Day stripe.PlanInterval = "day" - Week stripe.PlanInterval = "week" - Month stripe.PlanInterval = "month" - Year stripe.PlanInterval = "year" -) - // Client is used to invoke /plans APIs. type Client struct { B stripe.Backend diff --git a/plan/client_test.go b/plan/client_test.go index b4feb07bb2..39de697781 100644 --- a/plan/client_test.go +++ b/plan/client_test.go @@ -35,7 +35,7 @@ func TestPlanNew(t *testing.T) { Amount: stripe.Int64(1), Currency: stripe.String(string(currency.USD)), ID: stripe.String("sapphire-elite"), - Interval: stripe.String(string(Month)), + Interval: stripe.String(string(stripe.PlanIntervalMonth)), Product: &stripe.ProductParams{ ID: stripe.String("plan_id"), Name: stripe.String("Sapphire Elite"), @@ -52,7 +52,7 @@ func TestPlanNewWithProductID(t *testing.T) { Amount: stripe.Int64(1), Currency: stripe.String(string(currency.USD)), ID: stripe.String("sapphire-elite"), - Interval: stripe.String(string(Month)), + Interval: stripe.String(string(stripe.PlanIntervalMonth)), ProductID: stripe.String("prod_12345abc"), }) assert.Nil(t, err) diff --git a/product.go b/product.go index 3b9d1baff7..d5b65f348c 100644 --- a/product.go +++ b/product.go @@ -6,12 +6,7 @@ import "encoding/json" type ProductType string const ( - // ProductTypeGood is a constant that indicates a product represents a physical good, - // which may be sold through the Stripe Relay API. - ProductTypeGood ProductType = "good" - - // ProductTypeService is a constant that indicates a product represents a service - // which is provided on a recurring basis and is priced with a Stripe plan. + ProductTypeGood ProductType = "good" ProductTypeService ProductType = "service" ) diff --git a/recipient.go b/recipient.go index 8f7cc5eac3..5aecaa8f3d 100644 --- a/recipient.go +++ b/recipient.go @@ -7,9 +7,13 @@ import ( ) // RecipientType is the list of allowed values for the recipient's type. -// Allowed values are "individual", "corporation". type RecipientType string +const ( + RecipientTypeIndividual RecipientType = "individual" + RecipientTypeCorp RecipientType = "corporation" +) + // RecipientParams is the set of parameters that can be used when creating or updating recipients. // For more details see https://stripe.com/docs/api#create_recipient and https://stripe.com/docs/api#update_recipient. type RecipientParams struct { diff --git a/recipient/client.go b/recipient/client.go index 3ae66964ac..4d2f3b390e 100644 --- a/recipient/client.go +++ b/recipient/client.go @@ -6,11 +6,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - Individual stripe.RecipientType = "individual" - Corp stripe.RecipientType = "corporation" -) - // Client is used to invoke /recipients APIs. type Client struct { B stripe.Backend diff --git a/recipienttransfer.go b/recipienttransfer.go index 92efe24647..d76a11f84c 100644 --- a/recipienttransfer.go +++ b/recipienttransfer.go @@ -5,42 +5,60 @@ import "encoding/json" // RecipientTransferDestinationType consts represent valid recipient_transfer destinations. type RecipientTransferDestinationType string -// RecipientTransferFailCode is the list of allowed values for the recipient_transfer's failure code. -// Allowed values are "insufficient_funds", "account_closed", "no_account", -// "invalid_account_number", "debit_not_authorized", "bank_ownership_changed", -// "account_frozen", "could_not_process", "bank_account_restricted", "invalid_currency". -type RecipientTransferFailCode string +const ( + RecipientTransferDestinationBankAccount RecipientTransferDestinationType = "bank_account" + RecipientTransferDestinationCard RecipientTransferDestinationType = "card" +) + +// RecipientTransferFailureCode is the list of allowed values for the recipient_transfer's failure code. +type RecipientTransferFailureCode string + +const ( + RecipientTransferFailureCodeAccountClosed RecipientTransferFailureCode = "account_closed" + RecipientTransferFailureCodeAccountFrozen RecipientTransferFailureCode = "account_frozen" + RecipientTransferFailureCodeBankAccountRestricted RecipientTransferFailureCode = "bank_account_restricted" + RecipientTransferFailureCodeBankOwnershipChanged RecipientTransferFailureCode = "bank_ownership_changed" + RecipientTransferFailureCodeDebitNotAuthorized RecipientTransferFailureCode = "debit_not_authorized" + RecipientTransferFailureCodeCouldNotProcess RecipientTransferFailureCode = "could_not_process" + RecipientTransferFailureCodeInsufficientFunds RecipientTransferFailureCode = "insufficient_funds" + RecipientTransferFailureCodeInvalidAccountNumber RecipientTransferFailureCode = "invalid_account_number" + RecipientTransferFailureCodeInvalidCurrency RecipientTransferFailureCode = "invalid_currency" + RecipientTransferFailureCodeNoAccount RecipientTransferFailureCode = "no_account" +) // RecipientTransferSourceType is the list of allowed values for the recipient_transfer's source_type field. -// Allowed values are "alipay_account", bank_account", "bitcoin_receiver", "card". type RecipientTransferSourceType string +const ( + RecipientTransferSourceTypeAlipayAccount RecipientTransferSourceType = "alipay_account" + RecipientTransferSourceTypeBankAccount RecipientTransferSourceType = "bank_account" + RecipientTransferSourceTypeBitcoinReceiver RecipientTransferSourceType = "bitcoin_receiver" + RecipientTransferSourceTypeCard RecipientTransferSourceType = "card" +) + // RecipientTransferStatus is the list of allowed values for the recipient_transfer's status. -// Allowed values are "paid", "pending", "in_transit", "failed". type RecipientTransferStatus string +const ( + RecipientTransferStatusFailed RecipientTransferStatus = "failed" + RecipientTransferStatusInTransit RecipientTransferStatus = "in_transit" + RecipientTransferStatusPaid RecipientTransferStatus = "paid" + RecipientTransferStatusPending RecipientTransferStatus = "pending" +) + // RecipientTransferType is the list of allowed values for the recipient_transfer's type. -// Allowed values are "bank_account" or "card". type RecipientTransferType string const ( - // RecipientTransferDestinationBankAccount is a constant representing a recipient_transfer destination - // which is a bank account. - RecipientTransferDestinationBankAccount RecipientTransferDestinationType = "bank_account" - - // RecipientTransferDestinationCard is a constant representing a recipient_transfer destination - // which is a card. - RecipientTransferDestinationCard RecipientTransferDestinationType = "card" + RecipientTransferTypeBank RecipientTransferType = "bank_account" + RecipientTransferTypeCard RecipientTransferType = "card" ) // RecipientTransferMethodType represents the type of recipient_transfer type RecipientTransferMethodType string const ( - // RecipientTransferMethodInstant is a constant representing an instant recipient_transfer - RecipientTransferMethodInstant RecipientTransferMethodType = "instant" - - // RecipientTransferMethodStandard is a constant representing a standard recipient_transfer + RecipientTransferMethodInstant RecipientTransferMethodType = "instant" RecipientTransferMethodStandard RecipientTransferMethodType = "standard" ) @@ -66,8 +84,8 @@ type RecipientTransfer struct { Currency Currency `json:"currency"` Date int64 `json:"date"` Description string `json:"description"` - Destination RecipientTransferDestination `json:"destination"` - FailureCode RecipientTransferFailCode `json:"failure_code"` + Destination string `json:"destination"` + FailureCode RecipientTransferFailureCode `json:"failure_code"` FailureMessage string `json:"failure_message"` ID string `json:"id"` Livemode bool `json:"livemode"` diff --git a/recipienttransfer/client.go b/recipienttransfer/client.go index 25a9e34333..e5b27c6e7a 100644 --- a/recipienttransfer/client.go +++ b/recipienttransfer/client.go @@ -1,35 +1,5 @@ // Package recipienttransfer provides the /recipient_transfers APIs package recipienttransfer -import ( - stripe "github.com/stripe/stripe-go" -) - -const ( - Failed stripe.RecipientTransferStatus = "failed" - Paid stripe.RecipientTransferStatus = "paid" - Pending stripe.RecipientTransferStatus = "pending" - Transit stripe.RecipientTransferStatus = "in_transit" - - Bank stripe.RecipientTransferType = "bank_account" - Card stripe.RecipientTransferType = "card" - - SourceAlipay stripe.RecipientTransferSourceType = "alipay_account" - SourceBank stripe.RecipientTransferSourceType = "bank_account" - SourceBitcoin stripe.RecipientTransferSourceType = "bitcoin_receiver" - SourceCard stripe.RecipientTransferSourceType = "card" - - AccountClosed stripe.RecipientTransferFailCode = "account_closed" - AccountFrozen stripe.RecipientTransferFailCode = "account_frozen" - BankAccountRestrict stripe.RecipientTransferFailCode = "bank_account_restricted" - BankOwnerChanged stripe.RecipientTransferFailCode = "bank_ownership_changed" - DebitNotAuth stripe.RecipientTransferFailCode = "debit_not_authorized" - CouldNotProcess stripe.RecipientTransferFailCode = "could_not_process" - InsufficientFunds stripe.RecipientTransferFailCode = "insufficient_funds" - InvalidAccountNumber stripe.RecipientTransferFailCode = "invalid_account_number" - InvalidCurrency stripe.RecipientTransferFailCode = "invalid_currency" - NoAccount stripe.RecipientTransferFailCode = "no_account" -) - // This object can only be returned/expanded on Balance Transactions // The API doesn't support retrieve/update/list for those. diff --git a/refund.go b/refund.go index 263a3e9ca2..97f2f96f11 100644 --- a/refund.go +++ b/refund.go @@ -2,15 +2,25 @@ package stripe import "encoding/json" -// RefundReason is, if set, the reason the refund is being made--allowed values -// are "fraudulent", "duplicate", and "requested_by_customer". +// RefundReason is, if set, the reason the refund is being made type RefundReason string +const ( + RefundReasonDuplicate RefundReason = "duplicate" + RefundReasonFraudulent RefundReason = "fraudulent" + RefundReasonRequestedByCustomer RefundReason = "requested_by_customer" +) + // RefundStatus is the status of the refund. -// For credit card refunds, this will always be "succeeded". -// For other types of refunds, it can be "pending", "succeeded", "failed", or "cancelled". type RefundStatus string +const ( + RefundStatusCanceled RefundStatus = "canceled" + RefundStatusFailed RefundStatus = "failed" + RefundStatusPending RefundStatus = "pending" + RefundStatusSucceeded RefundStatus = "succeeded" +) + // RefundParams is the set of parameters that can be used when refunding a charge. // For more details see https://stripe.com/docs/api#refund. type RefundParams struct { diff --git a/refund/client.go b/refund/client.go index b145ba1633..cb0bf3c39a 100644 --- a/refund/client.go +++ b/refund/client.go @@ -6,12 +6,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - RefundFraudulent stripe.RefundReason = "fraudulent" - RefundDuplicate stripe.RefundReason = "duplicate" - RefundRequestedByCustomer stripe.RefundReason = "requested_by_customer" -) - // Client is used to invoke /refunds APIs. type Client struct { B stripe.Backend diff --git a/refund/client_test.go b/refund/client_test.go index 7e5c3e4dcb..8a5f5c88a6 100644 --- a/refund/client_test.go +++ b/refund/client_test.go @@ -26,7 +26,7 @@ func TestRefundList(t *testing.T) { func TestRefundNew(t *testing.T) { refund, err := New(&stripe.RefundParams{ Charge: stripe.String("ch_123"), - Reason: stripe.String(string(RefundDuplicate)), + Reason: stripe.String(string(stripe.RefundReasonDuplicate)), }) assert.Nil(t, err) assert.NotNil(t, refund) diff --git a/review.go b/review.go index 8fd5c3c8e6..bcc84eb769 100644 --- a/review.go +++ b/review.go @@ -2,27 +2,25 @@ package stripe import "encoding/json" -// Reason describes the reason why the review is open or closed. -// Allowed values are "rule", "manual", "approved", "refunded", -// "refunded_as_fraud", "disputed". -type ReasonType string +// ReviewReasonType describes the reason why the review is open or closed. +type ReviewReasonType string const ( - ReasonApproved ReasonType = "approved" - ReasonDisputed ReasonType = "disputed" - ReasonManual ReasonType = "manual" - ReasonRefunded ReasonType = "refunded" - ReasonRefundedAsFraud ReasonType = "refunded_as_fraud" - ReasonRule ReasonType = "rule" + ReviewReasonApproved ReviewReasonType = "approved" + ReviewReasonDisputed ReviewReasonType = "disputed" + ReviewReasonManual ReviewReasonType = "manual" + ReviewReasonRefunded ReviewReasonType = "refunded" + ReviewReasonRefundedAsFraud ReviewReasonType = "refunded_as_fraud" + ReviewReasonRule ReviewReasonType = "rule" ) type Review struct { - Charge *Charge `json:"charge"` - Created int64 `json:"created"` - ID string `json:"id"` - Livemode bool `json:"livemode"` - Open bool `json:"open"` - Reason ReasonType `json:"reason"` + Charge *Charge `json:"charge"` + Created int64 `json:"created"` + ID string `json:"id"` + Livemode bool `json:"livemode"` + Open bool `json:"open"` + Reason ReviewReasonType `json:"reason"` } func (r *Review) UnmarshalJSON(data []byte) error { diff --git a/sku.go b/sku.go index fb19f125f4..b2d1f62018 100644 --- a/sku.go +++ b/sku.go @@ -2,6 +2,24 @@ package stripe import "encoding/json" +// SKUInventoryType describe's the possible value for inventory type +type SKUInventoryType string + +const ( + SKUInventoryTypeBucket SKUInventoryType = "bucket" + SKUInventoryTypeFinite SKUInventoryType = "finite" + SKUInventoryTypeInfinite SKUInventoryType = "infinite" +) + +// SKUInventoryValue describe's the possible value for inventory value +type SKUInventoryValue string + +const ( + SKUInventoryValueInStock SKUInventoryValue = "in_stock" + SKUInventoryValueLimited SKUInventoryValue = "limited" + SKUInventoryValueOutOfStock SKUInventoryValue = "out_of_stock" +) + type InventoryParams struct { Quantity *int64 `form:"quantity"` Type *string `form:"type"` @@ -23,9 +41,9 @@ type SKUParams struct { } type Inventory struct { - Quantity int64 `json:"quantity"` - Type string `json:"type"` - Value string `json:"value"` + Quantity int64 `json:"quantity"` + Type SKUInventoryType `json:"type"` + Value SKUInventoryValue `json:"value"` } type SKU struct { diff --git a/sku/client_test.go b/sku/client_test.go index 1e75b546d6..c81734da1d 100644 --- a/sku/client_test.go +++ b/sku/client_test.go @@ -37,8 +37,8 @@ func TestSKUNew(t *testing.T) { Price: stripe.Int64(499), Currency: stripe.String(string(currency.USD)), Inventory: &stripe.InventoryParams{ - Type: stripe.String("bucket"), - Value: stripe.String("limited"), + Type: stripe.String(string(stripe.SKUInventoryTypeBucket)), + Value: stripe.String(string(stripe.SKUInventoryValueLimited)), }, Product: stripe.String("prod_123"), Image: stripe.String("http://example.com/foo.png"), @@ -50,8 +50,8 @@ func TestSKUNew(t *testing.T) { func TestSKUUpdate(t *testing.T) { sku, err := Update("sku_123", &stripe.SKUParams{ Inventory: &stripe.InventoryParams{ - Type: stripe.String("bucket"), - Value: stripe.String("in_stock"), + Type: stripe.String(string(stripe.SKUInventoryTypeBucket)), + Value: stripe.String(string(stripe.SKUInventoryValueInStock)), }, }) assert.Nil(t, err) diff --git a/source.go b/source.go index 72c0631fd9..8ab2206edb 100644 --- a/source.go +++ b/source.go @@ -6,62 +6,86 @@ import ( "github.com/stripe/stripe-go/form" ) -// SourceStatus represents the possible statuses of a source object. -type SourceStatus string +// SourceCodeVerificationFlowStatus represents the possible statuses of a code verification flow. +type SourceCodeVerificationFlowStatus string const ( - // SourceStatusCanceled we canceled the source along with any side-effect - // it had (returned funds to customers if any were sent). - SourceStatusCanceled SourceStatus = "canceled" + SourceCodeVerificationFlowStatusFailed SourceCodeVerificationFlowStatus = "failed" + SourceCodeVerificationFlowStatusPending SourceCodeVerificationFlowStatus = "pending" + SourceCodeVerificationFlowStatusSucceeded SourceCodeVerificationFlowStatus = "succeeded" +) - // SourceStatusChargeable the source is ready to be charged (once if usage - // is `single_use`, repeatedly otherwise). - SourceStatusChargeable SourceStatus = "chargeable" +// SourceFlow represents the possible flows of a source object. +type SourceFlow string - // SourceStatusConsumed the source is `single_use` usage and has been - // charged already. - SourceStatusConsumed SourceStatus = "consumed" +const ( + SourceFlowCodeVerification SourceFlow = "code_verification" + SourceFlowNone SourceFlow = "none" + SourceFlowReceiver SourceFlow = "receiver" + SourceFlowRedirect SourceFlow = "redirect" +) - // SourceStatusFailed the source is no longer usable. - SourceStatusFailed SourceStatus = "failed" +// SourceMandateAcceptanceStatus represents the possible failure reasons of a redirect flow. +type SourceMandateAcceptanceStatus string - // SourceStatusPending the source is freshly created and not yet - // chargeable. The flow should indicate how to authenticate it with your - // customer. - SourceStatusPending SourceStatus = "pending" +const ( + SourceMandateAcceptanceStatusAccepted SourceMandateAcceptanceStatus = "accepted" + SourceMandateAcceptanceStatusRefused SourceMandateAcceptanceStatus = "refused" ) -// SourceFlow represents the possible flows of a source object. -type SourceFlow string +// SourceRedirectFlowFailureReason represents the possible failure reasons of a redirect flow. +type SourceRedirectFlowFailureReason string + +const ( + SourceRedirectFlowFailureReasonDeclined SourceRedirectFlowFailureReason = "declined" + SourceRedirectFlowFailureReasonProcessingError SourceRedirectFlowFailureReason = "processing_error" + SourceRedirectFlowFailureReasonUserAbort SourceRedirectFlowFailureReason = "user_abort" +) + +// SourceRedirectFlowStatus represents the possible statuses of a redirect flow. +type SourceRedirectFlowStatus string const ( - // FlowCodeVerification a verification code should be communicated by the - // customer to authenticate the source. - FlowCodeVerification SourceFlow = "code_verification" + SourceRedirectFlowStatusFailed SourceRedirectFlowStatus = "failed" + SourceRedirectFlowStatusNotRequired SourceRedirectFlowStatus = "not_required" + SourceRedirectFlowStatusPending SourceRedirectFlowStatus = "pending" + SourceRedirectFlowStatusSucceeded SourceRedirectFlowStatus = "succeeded" +) - // FlowNone no particular authentication is involved the source should - // become chargeable directly or asyncrhonously. - FlowNone SourceFlow = "none" +// SourceRefundAttributesMethod are the possible method to retrieve a receiver's refund attributes. +type SourceRefundAttributesMethod string - // FlowReceiver a receiver address should be communicated to the customer - // to push funds to it. - FlowReceiver SourceFlow = "receiver" +const ( + SourceRefundAttributesMethodEmail SourceRefundAttributesMethod = "email" + SourceRefundAttributesMethodManual SourceRefundAttributesMethod = "manual" +) + +// SourceRefundAttributesStatus are the possible status of a receiver's refund attributes. +type SourceRefundAttributesStatus string - // FlowRedirect a redirect is required to authenticate the source. - FlowRedirect SourceFlow = "redirect" +const ( + SourceRefundAttributesStatusAvailable SourceRefundAttributesStatus = "available" + SourceRefundAttributesStatusMissing SourceRefundAttributesStatus = "missing" + SourceRefundAttributesStatusRequested SourceRefundAttributesStatus = "requested" +) + +// SourceStatus represents the possible statuses of a source object. +type SourceStatus string + +const ( + SourceStatusCanceled SourceStatus = "canceled" + SourceStatusChargeable SourceStatus = "chargeable" + SourceStatusConsumed SourceStatus = "consumed" + SourceStatusFailed SourceStatus = "failed" + SourceStatusPending SourceStatus = "pending" ) // SourceUsage represents the possible usages of a source object. type SourceUsage string const ( - // UsageReusable the source can be charged multiple times for arbitrary - // amounts. - UsageReusable SourceUsage = "reusable" - - // UsageSingleUse the source can only be charged once for the specified - // amount and currency. - UsageSingleUse SourceUsage = "single_use" + SourceUsageReusable SourceUsage = "reusable" + SourceUsageSingleUse SourceUsage = "single_use" ) type SourceOwnerParams struct { @@ -109,91 +133,35 @@ type SourceOwner struct { VerifiedPhone string `json:"verified_phone"` } -// RedirectFlowFailureReason represents the possible failure reasons of a redirect flow. -type RedirectFlowFailureReason string - -const ( - RedirectFlowFailureReasonDeclined RedirectFlowFailureReason = "declined" - RedirectFlowFailureReasonProcessingError RedirectFlowFailureReason = "processing_error" - RedirectFlowFailureReasonUserAbort RedirectFlowFailureReason = "user_abort" -) - -// RedirectFlowStatus represents the possible statuses of a redirect flow. -type RedirectFlowStatus string - -const ( - RedirectFlowStatusFailed RedirectFlowStatus = "failed" - RedirectFlowStatusNotRequired RedirectFlowStatus = "not_required" - RedirectFlowStatusPending RedirectFlowStatus = "pending" - RedirectFlowStatusSucceeded RedirectFlowStatus = "succeeded" -) - // ReceiverFlow informs of the state of a redirect authentication flow. type RedirectFlow struct { - FailureReason RedirectFlowFailureReason `json:"failure_reason"` - ReturnURL string `json:"return_url"` - Status RedirectFlowStatus `json:"status"` - URL string `json:"url"` + FailureReason SourceRedirectFlowFailureReason `json:"failure_reason"` + ReturnURL string `json:"return_url"` + Status SourceRedirectFlowStatus `json:"status"` + URL string `json:"url"` } -// RefundAttributesStatus are the possible status of a receiver's refund -// attributes. -type RefundAttributesStatus string - -const ( - // RefundAttributesAvailable the refund attributes are available - RefundAttributesAvailable RefundAttributesStatus = "available" - - // RefundAttributesMissing the refund attributes are missing - RefundAttributesMissing RefundAttributesStatus = "missing" - - // RefundAttributesRequested the refund attributes have been requested - RefundAttributesRequested RefundAttributesStatus = "requested" -) - -// RefundAttributesMethod are the possible method to retrieve a receiver's -// refund attributes. -type RefundAttributesMethod string - -const ( - // RefundAttributesEmail the refund attributes are automatically collected over email - RefundAttributesEmail RefundAttributesMethod = "email" - - // RefundAttributesManual the refund attributes should be collected by the user - RefundAttributesManual RefundAttributesMethod = "manual" -) - // ReceiverFlow informs of the state of a receiver authentication flow. type ReceiverFlow struct { - Address string `json:"address"` - AmountCharged int64 `json:"amount_charged"` - AmountReceived int64 `json:"amount_received"` - AmountReturned int64 `json:"amount_returned"` - RefundAttributesMethod RefundAttributesMethod `json:"refund_attributes_method"` - RefundAttributesStatus RefundAttributesStatus `json:"refund_attributes_status"` + Address string `json:"address"` + AmountCharged int64 `json:"amount_charged"` + AmountReceived int64 `json:"amount_received"` + AmountReturned int64 `json:"amount_returned"` + RefundAttributesMethod SourceRefundAttributesMethod `json:"refund_attributes_method"` + RefundAttributesStatus SourceRefundAttributesStatus `json:"refund_attributes_status"` } -// CodeVerificationFlowStatus represents the possible statuses of a code verification -// flow. -type CodeVerificationFlowStatus string - -const ( - CodeVerificationFlowStatusFailed CodeVerificationFlowStatus = "failed" - CodeVerificationFlowStatusPending CodeVerificationFlowStatus = "pending" - CodeVerificationFlowStatusSucceeded CodeVerificationFlowStatus = "succeeded" -) - // CodeVerificationFlow informs of the state of a verification authentication flow. type CodeVerificationFlow struct { - AttemptsRemaining int64 `json:"attempts_remaining"` - Status CodeVerificationFlowStatus `json:"status"` + AttemptsRemaining int64 `json:"attempts_remaining"` + Status SourceCodeVerificationFlowStatus `json:"status"` } type SourceMandateAcceptance struct { - Date string `json:"date"` - IP string `json:"ip"` - Status string `json:"status"` - UserAgent string `json:"user_agent"` + Date string `json:"date"` + IP string `json:"ip"` + Status SourceMandateAcceptanceStatus `json:"status"` + UserAgent string `json:"user_agent"` } type SourceMandate struct { diff --git a/source/client_test.go b/source/client_test.go index e18ec65963..5425852b61 100644 --- a/source/client_test.go +++ b/source/client_test.go @@ -20,7 +20,7 @@ func TestSourceNew(t *testing.T) { Type: stripe.String("bitcoin"), Amount: stripe.Int64(1000), Currency: stripe.String(string(currency.USD)), - Flow: stripe.String(string(stripe.FlowReceiver)), + Flow: stripe.String(string(stripe.SourceFlowReceiver)), Owner: &stripe.SourceOwnerParams{ Email: stripe.String("jenny.rosen@example.com"), }, @@ -52,7 +52,7 @@ func TestSourceSharing(t *testing.T) { Type: stripe.String("card"), Customer: stripe.String("cus_123"), OriginalSource: stripe.String("src_123"), - Usage: stripe.String(string(stripe.UsageReusable)), + Usage: stripe.String(string(stripe.SourceUsageReusable)), } params.SetStripeAccount("acct_123") source, err := New(params) diff --git a/sub.go b/sub.go index a53731a2dc..6ab04185b5 100644 --- a/sub.go +++ b/sub.go @@ -7,13 +7,25 @@ import ( ) // SubscriptionStatus is the list of allowed values for the subscription's status. -// Allowed values are "trialing", "active", "past_due", "canceled", "unpaid", "all". type SubscriptionStatus string +const ( + SubscriptionStatusActive SubscriptionStatus = "active" + SubscriptionStatusAll SubscriptionStatus = "all" + SubscriptionStatusCanceled SubscriptionStatus = "canceled" + SubscriptionStatusPastDue SubscriptionStatus = "past_due" + SubscriptionStatusTrialing SubscriptionStatus = "trialing" + SubscriptionStatusUnpaid SubscriptionStatus = "unpaid" +) + // SubscriptionBilling is the type of billing method for this subscription's invoices. -// Currently supported values are "send_invoice" and "charge_automatically". type SubscriptionBilling string +const ( + SubscriptionBillingChargeAutomatically SubscriptionBilling = "charge_automatically" + SubscriptionBillingSendInvoice SubscriptionBilling = "send_invoice" +) + // SubscriptionParams is the set of parameters that can be used when creating or updating a subscription. // For more details see https://stripe.com/docs/api#create_subscription and https://stripe.com/docs/api#update_subscription. type SubscriptionParams struct { @@ -77,12 +89,12 @@ type SubscriptionItemsParams struct { // For more details see https://stripe.com/docs/api#list_subscriptions. type SubscriptionListParams struct { ListParams `form:"*"` - Billing SubscriptionBilling `form:"billing"` - Created int64 `form:"created"` - CreatedRange *RangeQueryParams `form:"created"` - Customer string `form:"customer"` - Plan string `form:"plan"` - Status SubscriptionStatus `form:"status"` + Billing string `form:"billing"` + Created int64 `form:"created"` + CreatedRange *RangeQueryParams `form:"created"` + Customer string `form:"customer"` + Plan string `form:"plan"` + Status string `form:"status"` } // Subscription is the resource representing a Stripe subscription. diff --git a/sub/client.go b/sub/client.go index 800023346c..09d6ab3e8a 100644 --- a/sub/client.go +++ b/sub/client.go @@ -8,15 +8,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - Trialing stripe.SubscriptionStatus = "trialing" - Active stripe.SubscriptionStatus = "active" - PastDue stripe.SubscriptionStatus = "past_due" - Canceled stripe.SubscriptionStatus = "canceled" - Unpaid stripe.SubscriptionStatus = "unpaid" - All stripe.SubscriptionStatus = "all" -) - // Client is used to invoke /subscriptions APIs. type Client struct { B stripe.Backend diff --git a/sub/client_test.go b/sub/client_test.go index 414e11bf87..567be7cc2a 100644 --- a/sub/client_test.go +++ b/sub/client_test.go @@ -34,11 +34,14 @@ func TestSubscriptionNew(t *testing.T) { subscription, err := New(&stripe.SubscriptionParams{ Customer: stripe.String("cus_123"), Items: []*stripe.SubscriptionItemsParams{ - {Plan: "plan_123", Quantity: stripe.Int64(10)}, + { + Plan: stripe.String("plan_123"), + Quantity: stripe.Int64(10), + }, }, TaxPercent: stripe.Float64(20.0), BillingCycleAnchor: stripe.Int64(time.Now().AddDate(0, 0, 12).Unix()), - Billing: stripe.String("send_invoice"), + Billing: stripe.String(string(stripe.SubscriptionBillingSendInvoice)), DaysUntilDue: stripe.Int64(30), }) assert.Nil(t, err) diff --git a/token.go b/token.go index 90732051f8..900513dcf3 100644 --- a/token.go +++ b/token.go @@ -1,9 +1,15 @@ package stripe // TokenType is the list of allowed values for a token's type. -// Allowed values are "card", "bank_account". type TokenType string +const ( + TokenTypeAccount TokenType = "account" + TokenTypeCard TokenType = "card" + TokenTypeBankAccount TokenType = "bank_account" + TokenTypePII TokenType = "pii" +) + // TokenParams is the set of parameters that can be used when creating a token. // For more details see https://stripe.com/docs/api#create_card_token and https://stripe.com/docs/api#create_bank_account_token. type TokenParams struct { diff --git a/token/client.go b/token/client.go index a85eafd3d0..36011cf750 100644 --- a/token/client.go +++ b/token/client.go @@ -6,12 +6,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - Card stripe.TokenType = "card" - Bank stripe.TokenType = "bank_account" - PII stripe.TokenType = "pii" -) - // Client is used to invoke /tokens APIs. type Client struct { B stripe.Backend diff --git a/transfer.go b/transfer.go index 3b287243f5..81c6e35891 100644 --- a/transfer.go +++ b/transfer.go @@ -3,9 +3,15 @@ package stripe import "encoding/json" // TransferSourceType is the list of allowed values for the transfer's source_type field. -// Allowed values are "alipay_account", bank_account", "bitcoin_receiver", "card". type TransferSourceType string +const ( + TransferSourceTypeAlipayAccount TransferSourceType = "alipay_account" + TransferSourceTypeBankAccount TransferSourceType = "bank_account" + TransferSourceTypeBitcoinReceiver TransferSourceType = "bitcoin_receiver" + TransferSourceTypeCard TransferSourceType = "card" +) + // TransferDestination describes the destination of a Transfer. // The Type should indicate which object is fleshed out // For more details see https://stripe.com/docs/api/go#transfer_object @@ -52,6 +58,7 @@ type Transfer struct { Reversals *ReversalList `json:"reversals"` Reversed bool `json:"reversed"` SourceTransaction *BalanceTransactionSource `json:"source_transaction"` + SourceType TransferSourceType `json:"source_type"` TransferGroup string `json:"transfer_group"` } diff --git a/transfer/client.go b/transfer/client.go index 259be7a88c..dfacdfb2cc 100644 --- a/transfer/client.go +++ b/transfer/client.go @@ -6,13 +6,6 @@ import ( "github.com/stripe/stripe-go/form" ) -const ( - SourceAlipay stripe.TransferSourceType = "alipay_account" - SourceBank stripe.TransferSourceType = "bank_account" - SourceBitcoin stripe.TransferSourceType = "bitcoin_receiver" - SourceCard stripe.TransferSourceType = "card" -) - // Client is used to invoke /transfers APIs. type Client struct { B stripe.Backend diff --git a/transfer/client_test.go b/transfer/client_test.go index aa1226b26e..1bff282a2c 100644 --- a/transfer/client_test.go +++ b/transfer/client_test.go @@ -30,7 +30,7 @@ func TestTransferNew(t *testing.T) { Currency: stripe.String(string(currency.USD)), Destination: stripe.String("acct_123"), SourceTransaction: stripe.String("ch_123"), - SourceType: stripe.String(string(SourceCard)), + SourceType: stripe.String(string(stripe.TransferSourceTypeCard)), }) assert.Nil(t, err) assert.NotNil(t, transfer) diff --git a/usage_record.go b/usage_record.go index 57c6c5e310..013a1a48a1 100644 --- a/usage_record.go +++ b/usage_record.go @@ -1,14 +1,8 @@ package stripe const ( - // UsageRecordParamsActionIncrement indicates that if two usage records conflict - // (i.E. are reported a the same timestamp), their Quantity will be summed - UsageRecordParamsActionIncrement string = "increment" - - // UsageRecordParamsActionSet indicates that if two usage records conflict - // (i.E. are reported a the same timestamp), the Quantity of the most recent - // usage record will overwrite any other quantity. - UsageRecordParamsActionSet string = "set" + UsageRecordActionIncrement string = "increment" + UsageRecordActionSet string = "set" ) // UsageRecord represents a usage record. diff --git a/usagerecord/client_test.go b/usagerecord/client_test.go index d112636ffb..9ed13fc9a1 100644 --- a/usagerecord/client_test.go +++ b/usagerecord/client_test.go @@ -14,7 +14,7 @@ func TestUsageRecordNew(t *testing.T) { usageRecord, err := New(&stripe.UsageRecordParams{ Quantity: stripe.Int64(123), Timestamp: stripe.Int64(now), - Action: stripe.String(stripe.UsageRecordParamsActionIncrement), + Action: stripe.String(stripe.UsageRecordActionIncrement), SubscriptionItem: stripe.String("si_123"), }) assert.Nil(t, err)