diff --git a/balance.go b/balance.go index 4cc080c8dd..73a6bb38c3 100644 --- a/balance.go +++ b/balance.go @@ -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. @@ -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. 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 7d3c34a65b..8826a7e23f 100644 --- a/bankaccount.go +++ b/bankaccount.go @@ -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. // @@ -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. 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 7d83beb210..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(AccountHolderTypeIndividual))} + 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 781f352497..0d973ea48f 100644 --- a/card.go +++ b/card.go @@ -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. // @@ -145,21 +148,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 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. // @@ -167,12 +170,12 @@ type Card struct { // 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". // @@ -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. 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..3f3057a336 100644 --- a/charge.go +++ b/charge.go @@ -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 { @@ -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. diff --git a/charge/client.go b/charge/client.go index 8ed79ef06f..dcf189d677 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.ChargeFraudReportFraudulent)), }, }, ) @@ -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.ChargeFraudReportSafe)), }, }, ) diff --git a/countryspec.go b/countryspec.go index f24c8fadb3..cff8ef1648 100644 --- a/countryspec.go +++ b/countryspec.go @@ -1,8 +1,5 @@ package stripe -// Country is the list of supported countries -type Country string - // VerificationFieldsList lists the fields needed for an account verification. // For more details see https://stripe.com/docs/api#country_spec_object-verification_fields. type VerificationFieldsList struct { @@ -15,7 +12,7 @@ type VerificationFieldsList struct { type CountrySpec struct { DefaultCurrency Currency `json:"default_currency"` ID string `json:"id"` - SupportedBankAccountCurrencies map[Currency][]Country `json:"supported_bank_account_currencies"` + SupportedBankAccountCurrencies map[Currency][]string `json:"supported_bank_account_currencies"` SupportedPaymentCurrencies []Currency `json:"supported_payment_currencies"` SupportedPaymentMethods []string `json:"supported_payment_methods"` VerificationFields map[string]VerificationFieldsList `json:"verification_fields"` diff --git a/coupon.go b/coupon.go index 2cec158b1d..61e8fc6713 100644 --- a/coupon.go +++ b/coupon.go @@ -2,9 +2,11 @@ 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 string = "forever" + CouponDurationOnce string = "once" + CouponDurationRepeating string = "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. @@ -35,7 +37,7 @@ type Coupon struct { Created int64 `json:"created"` Currency Currency `json:"currency"` Deleted bool `json:"deleted"` - Duration CouponDuration `json:"duration"` + Duration string `json:"duration"` DurationInMonths int64 `json:"duration_in_months"` ID string `json:"id"` Livemode bool `json:"livemode"` 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 faf93c2f1e..d737d4d2b5 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..bf6d5e01b3 100644 --- a/dispute.go +++ b/dispute.go @@ -4,17 +4,25 @@ import ( "encoding/json" ) -// 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 string = "credit_not_processed" + DisputeReasonDuplicate string = "duplicate" + DisputeReasonFraudulent string = "fraudulent" + DisputeReasonGeneral string = "general" + DisputeReasonProductNotReceived string = "product_not_received" + DisputeReasonProductUnacceptable string = "product_unacceptable" + DisputeReasonSubscriptionCanceled string = "subscription_canceled" + DisputeReasonUnrecognized string = "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 + DisputeStatusChargeRefunded string = "charge_refunded" + DisputeStatusLost string = "lost" + DisputeStatusNeedsResponse string = "needs_response" + DisputeStatusUnderReview string = "under_review" + DisputeStatusWarningClosed string = "warning_closed" + DisputeStatusWarningNeedsResponse string = "warning_needs_response" + DisputeStatusWarningUnderReview string = "warning_under_review" + DisputeStatusWon string = "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. @@ -78,8 +86,8 @@ type Dispute struct { IsChargeRefundable bool `json:"is_charge_refundable"` Livemode bool `json:"livemode"` Metadata map[string]string `json:"metadata"` - Reason DisputeReason `json:"reason"` - Status DisputeStatus `json:"status"` + Reason string `json:"reason"` + Status string `json:"status"` } // DisputeList is a list of disputes as retrieved from a list endpoint. diff --git a/dispute/client.go b/dispute/client.go index dbebfa2c43..6f3f792508 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..9bc7e23fce 100644 --- a/error.go +++ b/error.go @@ -2,41 +2,35 @@ package stripe 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" - ErrorTypeAuthentication ErrorType = "authentication_error" - ErrorTypeCard ErrorType = "card_error" - ErrorTypeInvalidRequest ErrorType = "invalid_request_error" - ErrorTypePermission ErrorType = "more_permissions_required" - ErrorTypeRateLimit ErrorType = "rate_limit_error" - - ErrorCodeCardDeclined ErrorCode = "card_declined" - ErrorCodeExpiredCard ErrorCode = "expired_card" - ErrorCodeIncorrectCVC ErrorCode = "incorrect_cvc" - ErrorCodeIncorrectZip ErrorCode = "incorrect_zip" - ErrorCodeIncorrectNumber ErrorCode = "incorrect_number" - ErrorCodeInvalidCVC ErrorCode = "invalid_cvc" - ErrorCodeInvalidExpiryMonth ErrorCode = "invalid_expiry_month" - ErrorCodeInvalidExpiryYear ErrorCode = "invalid_expiry_year" - ErrorCodeInvalidNumber ErrorCode = "invalid_number" - ErrorCodeInvalidSwipeData ErrorCode = "invalid_swipe_data" - ErrorCodeMissing ErrorCode = "missing" - ErrorCodeProcessingError ErrorCode = "processing_error" - ErrorCodeRateLimit ErrorCode = "rate_limit" + ErrorTypeAPI string = "api_error" + ErrorTypeAPIConnection string = "api_connection_error" + ErrorTypeAuthentication string = "authentication_error" + ErrorTypeCard string = "card_error" + ErrorTypeInvalidRequest string = "invalid_request_error" + ErrorTypePermission string = "more_permissions_required" + ErrorTypeRateLimit string = "rate_limit_error" + + ErrorCodeCardDeclined string = "card_declined" + ErrorCodeExpiredCard string = "expired_card" + ErrorCodeIncorrectCVC string = "incorrect_cvc" + ErrorCodeIncorrectZip string = "incorrect_zip" + ErrorCodeIncorrectNumber string = "incorrect_number" + ErrorCodeInvalidCVC string = "invalid_cvc" + ErrorCodeInvalidExpiryMonth string = "invalid_expiry_month" + ErrorCodeInvalidExpiryYear string = "invalid_expiry_year" + ErrorCodeInvalidNumber string = "invalid_number" + ErrorCodeInvalidSwipeData string = "invalid_swipe_data" + ErrorCodeMissing string = "missing" + ErrorCodeProcessingError string = "processing_error" + ErrorCodeRateLimit string = "rate_limit" ) // Error is the response returned when a call is unsuccessful. // For more details see https://stripe.com/docs/api#errors. type Error struct { - ChargeID string `json:"charge,omitempty"` - Code ErrorCode `json:"code,omitempty"` + ChargeID string `json:"charge,omitempty"` + Code string `json:"code,omitempty"` // Err contains an internal error with an additional level of granularity // that can be used in some cases to get more detailed information about @@ -44,11 +38,11 @@ type Error struct { // exactly what went wrong during a charge. Err error `json:"-"` - HTTPStatusCode int `json:"status,omitempty"` - Msg string `json:"message"` - Param string `json:"param,omitempty"` - RequestID string `json:"request_id,omitempty"` - Type ErrorType `json:"type"` + HTTPStatusCode int `json:"status,omitempty"` + Msg string `json:"message"` + Param string `json:"param,omitempty"` + RequestID string `json:"request_id,omitempty"` + Type string `json:"type"` } // Error serializes the error object to JSON and returns it as a string. diff --git a/fileupload.go b/fileupload.go index ce7ec78815..2feed919df 100644 --- a/fileupload.go +++ b/fileupload.go @@ -7,6 +7,11 @@ import ( "path/filepath" ) +const ( + FileUploadPurposeDisputeEvidence string = "dispute_evidence" + FileUploadPurposeIdentityDocument string = "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,19 +36,15 @@ 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 { - Created int64 `json:"created"` - ID string `json:"id"` - Purpose FileUploadPurpose `json:"purpose"` - Size int64 `json:"size"` - Type string `json:"type"` - URL string `json:"url"` + Created int64 `json:"created"` + ID string `json:"id"` + Purpose string `json:"purpose"` + Size int64 `json:"size"` + Type string `json:"type"` + URL string `json:"url"` } // FileUploadList is a list of file uploads as retrieved from a list endpoint. 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 f16482df42..adc0b7bb5c 100644 --- a/fileupload/client_test.go +++ b/fileupload/client_test.go @@ -37,7 +37,7 @@ func TestFileUploadNewThenGet(t *testing.T) { } uploadParams := &stripe.FileUploadParams{ - Purpose: stripe.String(string(DisputeEvidenceFile)), + Purpose: stripe.String(stripe.FileUploadPurposeDisputeEvidence), FileReader: f, Filename: stripe.String(f.Name()), } @@ -62,7 +62,7 @@ func TestFileUploadList(t *testing.T) { } uploadParams := &stripe.FileUploadParams{ - Purpose: stripe.String(string(DisputeEvidenceFile)), + Purpose: stripe.String(stripe.FileUploadPurposeDisputeEvidence), FileReader: f, Filename: stripe.String(f.Name()), } diff --git a/invoice.go b/invoice.go index be5cf79479..7f75792125 100644 --- a/invoice.go +++ b/invoice.go @@ -2,13 +2,10 @@ package stripe import "encoding/json" -// InvoiceLineType is the list of allowed values for the invoice line's type. -// Allowed values are "invoiceitem", "subscription". -type InvoiceLineType string - -// InvoiceBilling is the type of billing method for this invoice. -// Currently supported values are "send_invoice" and "charge_automatically". -type InvoiceBilling string +const ( + InvoiceLineTypeTypeInvoiceItem string = "invoiceitem" + InvoiceLineTypeTypeSubscription string = "subscription" +) // 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. @@ -69,7 +66,7 @@ type Invoice struct { ApplicationFee int64 `json:"application_fee"` AttemptCount int64 `json:"attempt_count"` Attempted bool `json:"attempted"` - Billing InvoiceBilling `json:"billing"` + Billing string `json:"billing"` Charge *Charge `json:"charge"` Closed bool `json:"closed"` Currency Currency `json:"currency"` @@ -121,7 +118,7 @@ type InvoiceLine struct { Proration bool `json:"proration"` Quantity int64 `json:"quantity"` Subscription string `json:"subscription"` - Type InvoiceLineType `json:"type"` + Type string `json:"type"` } // Period is a structure representing a start and end dates. 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/order.go b/order.go index 243d29cd45..c94d3ce75c 100644 --- a/order.go +++ b/order.go @@ -4,15 +4,20 @@ import ( "encoding/json" ) -// OrderStatus represents the statuses of an order object. -type OrderStatus string - const ( - StatusCanceled OrderStatus = "canceled" - StatusCreated OrderStatus = "created" - StatusFulfilled OrderStatus = "fulfilled" - StatusPaid OrderStatus = "paid" - StatusReturned OrderStatus = "returned" + OrderStatusCanceled string = "canceled" + OrderStatusCreated string = "created" + OrderStatusFulfilled string = "fulfilled" + OrderStatusPaid string = "paid" + OrderStatusReturned string = "returned" + + OrderEstimateTypeExact string = "exact" + OrderEstimateTypeRange string = "range" + + OrderItemTeypeDiscount string = "discount" + OrderItemTeypeShipping string = "shipping" + OrderItemTeypeSKU string = "sku" + OrderItemTeypeTax string = "tax" ) type OrderParams struct { @@ -67,20 +72,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 string `json:"type"` } type Order struct { @@ -101,7 +99,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 +142,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 string `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..4ec7f9f323 100644 --- a/paymentsource.go +++ b/paymentsource.go @@ -7,6 +7,14 @@ import ( "github.com/stripe/stripe-go/form" ) +const ( + PaymentSourceTypeAccount string = "account" + PaymentSourceTypeBankAccount string = "bank_account" + PaymentSourceTypeBitcoinReceiver string = "bitcoin_receiver" + PaymentSourceTypeCard string = "card" + PaymentSourceTypeObject string = "source" +) + // SourceParams is a union struct used to describe an // arbitrary payment source. type SourceParams struct { @@ -70,42 +78,17 @@ 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 type PaymentSource struct { - BankAccount *BankAccount `json:"-"` - BitcoinReceiver *BitcoinReceiver `json:"-"` - Card *Card `json:"-"` - Deleted bool `json:"deleted"` - ID string `json:"id"` - SourceObject *Source `json:"-"` - Type PaymentSourceType `json:"object"` + BankAccount *BankAccount `json:"-"` + BitcoinReceiver *BitcoinReceiver `json:"-"` + Card *Card `json:"-"` + Deleted bool `json:"deleted"` + ID string `json:"id"` + SourceObject *Source `json:"-"` + Type string `json:"object"` } // SourceList is a list object for cards. @@ -132,13 +115,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,20 +138,20 @@ 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"` + Type string `json:"object"` }{ BitcoinReceiver: s.BitcoinReceiver, Type: s.Type, } - case PaymentSourceCard: + case PaymentSourceTypeCard: var customerID *string if s.Card.Customer != nil { customerID = &s.Card.Customer.ID @@ -176,22 +159,22 @@ func (s *PaymentSource) MarshalJSON() ([]byte, error) { target = struct { *Card - Customer *string `json:"customer"` - Type PaymentSourceType `json:"object"` + Customer *string `json:"customer"` + Type string `json:"object"` }{ Card: s.Card, Customer: customerID, Type: s.Type, } - case PaymentSourceAccount: + case PaymentSourceTypeAccount: target = struct { - ID string `json:"id"` - Type PaymentSourceType `json:"object"` + ID string `json:"id"` + Type string `json:"object"` }{ ID: s.ID, Type: s.Type, } - case PaymentSourceBankAccount: + case PaymentSourceTypeBankAccount: var customerID *string if s.BankAccount.Customer != nil { customerID = &s.BankAccount.Customer.ID @@ -199,8 +182,8 @@ func (s *PaymentSource) MarshalJSON() ([]byte, error) { target = struct { *BankAccount - Customer *string `json:"customer"` - Type PaymentSourceType `json:"object"` + Customer *string `json:"customer"` + Type string `json:"object"` }{ BankAccount: s.BankAccount, Customer: customerID, 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..5639312b7f 100644 --- a/payout.go +++ b/payout.go @@ -2,56 +2,47 @@ package stripe import "encoding/json" -// PayoutDestinationType consts represent valid payout destinations. -type PayoutDestinationType string - -// 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 - -// 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 - -// PayoutStatus is the list of allowed values for the payout's status. -// Allowed values are "paid", "pending", "in_transit", "failed", "canceled". -type PayoutStatus string - -// 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" -) - -// 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 - PayoutMethodStandard PayoutMethodType = "standard" + PayoutDestinationTypeBankAccount string = "bank_account" + PayoutDestinationTypeCard string = "card" + + PayoutTypeBank string = "bank_account" + PayoutTypeCard string = "card" + + PayoutFailureCodeAccountClosed string = "account_closed" + PayoutFailureCodeAccountFrozen string = "account_frozen" + PayoutFailureCodeBankAccountRestricted string = "bank_account_restricted" + PayoutFailureCodeBankOwnershipChanged string = "bank_ownership_changed" + PayoutFailureCodeCouldNotProcess string = "could_not_process" + PayoutFailureCodeDebitNotAuthorized string = "debit_not_authorized" + PayoutFailureCodeInsufficientFunds string = "insufficient_funds" + PayoutFailureCodeInvalidAccountNumber string = "invalid_account_number" + PayoutFailureCodeInvalidCurrency string = "invalid_currency" + PayoutFailureCodeNoAccount string = "no_account" + + PayoutMethodInstant string = "instant" + PayoutMethodStandard string = "standard" + + PayoutSourceTypeAlipayAccount string = "alipay_account" + PayoutSourceTypeBankAccount string = "bank_account" + PayoutSourceTypeBitcoinReceiver string = "bitcoin_receiver" + PayoutSourceTypeCard string = "card" + + PayoutStatusCanceled string = "canceled" + PayoutStatusFailed string = "failed" + PayoutStatusInTransit string = "in_transit" + PayoutStatusPaid string = "paid" + PayoutStatusPending string = "pending" ) // PayoutDestination describes the destination of a Payout. // The Type should indicate which object is fleshed out // For more details see https://stripe.com/docs/api/go#payout_object type PayoutDestination struct { - BankAccount *BankAccount `json:"-"` - Card *Card `json:"-"` - ID string `json:"id"` - Type PayoutDestinationType `json:"object"` + BankAccount *BankAccount `json:"-"` + Card *Card `json:"-"` + ID string `json:"id"` + Type string `json:"object"` } // PayoutParams is the set of parameters that can be used when creating or updating a payout. @@ -89,18 +80,18 @@ 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"` + FailureCode string `json:"failure_code"` FailureMessage string `json:"failure_message"` ID string `json:"id"` Livemode bool `json:"livemode"` Metadata map[string]string `json:"metadata"` - Method PayoutMethodType `json:"method"` - SourceType PayoutSourceType `json:"source_type"` + Method string `json:"method"` + SourceType string `json:"source_type"` StatementDescriptor string `json:"statement_descriptor"` - Status PayoutStatus `json:"status"` - Type PayoutType `json:"type"` + Status string `json:"status"` + Type string `json:"type"` } // PayoutList is a list of payouts as retrieved from a list endpoint. @@ -137,9 +128,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..b4ba9cea45 100644 --- a/plan.go +++ b/plan.go @@ -6,17 +6,14 @@ import ( "github.com/stripe/stripe-go/form" ) -// 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" + PlanBillingSchemeTiered string = "tiered" + + PlanIntervalDay string = "day" + PlanIntervalWeek string = "week" + PlanIntervalMonth string = "month" + PlanIntervalYear string = "year" ) const ( @@ -46,7 +43,7 @@ type Plan struct { Currency Currency `json:"currency"` Deleted bool `json:"deleted"` ID string `json:"id"` - Interval PlanInterval `json:"interval"` + Interval string `json:"interval"` IntervalCount int64 `json:"interval_count"` Livemode bool `json:"livemode"` Metadata map[string]string `json:"metadata"` 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..22266c98fc 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(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(stripe.PlanIntervalMonth), ProductID: stripe.String("prod_12345abc"), }) assert.Nil(t, err) diff --git a/product.go b/product.go index 3b9d1baff7..f3e149a050 100644 --- a/product.go +++ b/product.go @@ -2,17 +2,9 @@ package stripe import "encoding/json" -// ProductType is the type of a product. -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. - ProductTypeService ProductType = "service" + ProductTypeGood string = "good" + ProductTypeService string = "service" ) // PackageDimensions represents the dimension of a product or a sku from the @@ -72,7 +64,7 @@ type Product struct { Shippable bool `json:"shippable"` Skus *SKUList `json:"skus"` StatementDescriptor string `json:"statement_descriptor"` - Type ProductType `json:"type"` + Type string `json:"type"` URL string `json:"url"` Updated int64 `json:"updated"` } diff --git a/recipient.go b/recipient.go index 8f7cc5eac3..5285e94f65 100644 --- a/recipient.go +++ b/recipient.go @@ -6,9 +6,10 @@ import ( "github.com/stripe/stripe-go/form" ) -// RecipientType is the list of allowed values for the recipient's type. -// Allowed values are "individual", "corporation". -type RecipientType string +const ( + RecipientTypeIndividual string = "individual" + RecipientTypeCorp string = "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. @@ -61,7 +62,7 @@ type Recipient struct { Metadata map[string]string `json:"metadata"` MigratedTo *Account `json:"migrated_to"` Name string `json:"name"` - Type RecipientType `json:"type"` + Type string `json:"type"` } // RecipientList is a list of recipients as retrieved from a list endpoint. 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..ad830474d6 100644 --- a/recipienttransfer.go +++ b/recipienttransfer.go @@ -2,85 +2,75 @@ package stripe 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 - -// 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 - -// RecipientTransferStatus is the list of allowed values for the recipient_transfer's status. -// Allowed values are "paid", "pending", "in_transit", "failed". -type RecipientTransferStatus string - -// 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" -) - -// 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 - RecipientTransferMethodStandard RecipientTransferMethodType = "standard" + RecipientTransferDestinationBankAccount string = "bank_account" + RecipientTransferDestinationCard string = "card" + + RecipientTransferFailureCodeAccountClosed string = "account_closed" + RecipientTransferFailureCodeAccountFrozen string = "account_frozen" + RecipientTransferFailureCodeBankAccountRestricted string = "bank_account_restricted" + RecipientTransferFailureCodeBankOwnershipChanged string = "bank_ownership_changed" + RecipientTransferFailureCodeDebitNotAuthorized string = "debit_not_authorized" + RecipientTransferFailureCodeCouldNotProcess string = "could_not_process" + RecipientTransferFailureCodeInsufficientFunds string = "insufficient_funds" + RecipientTransferFailureCodeInvalidAccountNumber string = "invalid_account_number" + RecipientTransferFailureCodeInvalidCurrency string = "invalid_currency" + RecipientTransferFailureCodeNoAccount string = "no_account" + + RecipientTransferMethodInstant string = "instant" + RecipientTransferMethodStandard string = "standard" + + RecipientTransferSourceTypeAlipayAccount string = "alipay_account" + RecipientTransferSourceTypeBankAccount string = "bank_account" + RecipientTransferSourceTypeBitcoinReceiver string = "bitcoin_receiver" + RecipientTransferSourceTypeCard string = "card" + + RecipientTransferStatusFailed string = "failed" + RecipientTransferStatusInTransit string = "in_transit" + RecipientTransferStatusPaid string = "paid" + RecipientTransferStatusPending string = "pending" + + RecipientTransferTypeBank string = "bank_account" + RecipientTransferTypeCard string = "card" ) // RecipientTransferDestination describes the destination of a RecipientTransfer. // The Type should indicate which object is fleshed out // For more details see https://stripe.com/docs/api/go#recipient_transfer_object type RecipientTransferDestination struct { - BankAccount *BankAccount `json:"-"` - Card *Card `json:"-"` - ID string `json:"id"` - Type RecipientTransferDestinationType `json:"object"` + BankAccount *BankAccount `json:"-"` + Card *Card `json:"-"` + ID string `json:"id"` + Type string `json:"object"` } // RecipientTransfer is the resource representing a Stripe recipient_transfer. // For more details see https://stripe.com/docs/api#recipient_transfers. type RecipientTransfer struct { - Amount int64 `json:"amount"` - AmountReversed int64 `json:"amount_reversed"` - BalanceTransaction *BalanceTransaction `json:"balance_transaction"` - BankAccount *BankAccount `json:"bank_account"` - Card *Card `json:"card"` - Created int64 `json:"created"` - Currency Currency `json:"currency"` - Date int64 `json:"date"` - Description string `json:"description"` - Destination RecipientTransferDestination `json:"destination"` - FailureCode RecipientTransferFailCode `json:"failure_code"` - FailureMessage string `json:"failure_message"` - ID string `json:"id"` - Livemode bool `json:"livemode"` - Metadata map[string]string `json:"metadata"` - Method RecipientTransferMethodType `json:"method"` - Recipient *Recipient `json:"recipient"` - Reversals *ReversalList `json:"reversals"` - Reversed bool `json:"reversed"` - SourceTransaction *BalanceTransactionSource `json:"source_transaction"` - SourceType RecipientTransferSourceType `json:"source_type"` - StatementDescriptor string `json:"statement_descriptor"` - Status RecipientTransferStatus `json:"status"` - Type RecipientTransferType `json:"type"` + Amount int64 `json:"amount"` + AmountReversed int64 `json:"amount_reversed"` + BalanceTransaction *BalanceTransaction `json:"balance_transaction"` + BankAccount *BankAccount `json:"bank_account"` + Card *Card `json:"card"` + Created int64 `json:"created"` + Currency Currency `json:"currency"` + Date int64 `json:"date"` + Description string `json:"description"` + Destination string `json:"destination"` + FailureCode string `json:"failure_code"` + FailureMessage string `json:"failure_message"` + ID string `json:"id"` + Livemode bool `json:"livemode"` + Metadata map[string]string `json:"metadata"` + Method string `json:"method"` + Recipient *Recipient `json:"recipient"` + Reversals *ReversalList `json:"reversals"` + Reversed bool `json:"reversed"` + SourceTransaction *BalanceTransactionSource `json:"source_transaction"` + SourceType string `json:"source_type"` + StatementDescriptor string `json:"statement_descriptor"` + Status string `json:"status"` + Type string `json:"type"` } // UnmarshalJSON handles deserialization of a RecipientTransfer. 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..61aa31ab9b 100644 --- a/refund.go +++ b/refund.go @@ -2,14 +2,16 @@ 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". -type RefundReason string +const ( + RefundReasonDuplicate string = "duplicate" + RefundReasonFraudulent string = "fraudulent" + RefundReasonRequestedByCustomer string = "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 + RefundStatusCanceled string = "canceled" + RefundStatusFailed string = "failed" + RefundStatusPending string = "pending" + RefundStatusSucceeded string = "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. @@ -38,9 +40,9 @@ type Refund struct { Currency Currency `json:"currency"` ID string `json:"id"` Metadata map[string]string `json:"metadata"` - Reason RefundReason `json:"reason"` + Reason string `json:"reason"` ReceiptNumber string `json:"receipt_number"` - Status RefundStatus `json:"status"` + Status string `json:"status"` } // RefundList is a list object for refunds. 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..0517c9343b 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(stripe.RefundReasonDuplicate), }) assert.Nil(t, err) assert.NotNil(t, refund) diff --git a/review.go b/review.go index 8fd5c3c8e6..ebdd215725 100644 --- a/review.go +++ b/review.go @@ -2,27 +2,22 @@ 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 - const ( - ReasonApproved ReasonType = "approved" - ReasonDisputed ReasonType = "disputed" - ReasonManual ReasonType = "manual" - ReasonRefunded ReasonType = "refunded" - ReasonRefundedAsFraud ReasonType = "refunded_as_fraud" - ReasonRule ReasonType = "rule" + ReviewReasonApproved string = "approved" + ReviewReasonDisputed string = "disputed" + ReviewReasonManual string = "manual" + ReviewReasonRefunded string = "refunded" + ReviewReasonRefundedAsFraud string = "refunded_as_fraud" + ReviewReasonRule string = "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 string `json:"reason"` } func (r *Review) UnmarshalJSON(data []byte) error { diff --git a/source.go b/source.go index 72c0631fd9..b9741b01ea 100644 --- a/source.go +++ b/source.go @@ -6,62 +6,40 @@ import ( "github.com/stripe/stripe-go/form" ) -// SourceStatus represents the possible statuses of a source object. -type SourceStatus 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" - - // SourceStatusChargeable the source is ready to be charged (once if usage - // is `single_use`, repeatedly otherwise). - SourceStatusChargeable SourceStatus = "chargeable" - - // SourceStatusConsumed the source is `single_use` usage and has been - // charged already. - SourceStatusConsumed SourceStatus = "consumed" - - // SourceStatusFailed the source is no longer usable. - SourceStatusFailed SourceStatus = "failed" - - // SourceStatusPending the source is freshly created and not yet - // chargeable. The flow should indicate how to authenticate it with your - // customer. - SourceStatusPending SourceStatus = "pending" -) - -// SourceFlow represents the possible flows of a source object. -type SourceFlow string - -const ( - // FlowCodeVerification a verification code should be communicated by the - // customer to authenticate the source. - FlowCodeVerification SourceFlow = "code_verification" - - // FlowNone no particular authentication is involved the source should - // become chargeable directly or asyncrhonously. - FlowNone SourceFlow = "none" - - // FlowReceiver a receiver address should be communicated to the customer - // to push funds to it. - FlowReceiver SourceFlow = "receiver" - - // FlowRedirect a redirect is required to authenticate the source. - FlowRedirect SourceFlow = "redirect" -) - -// 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" + SourceCodeVerificationFlowStatusFailed string = "failed" + SourceCodeVerificationFlowStatusPending string = "pending" + SourceCodeVerificationFlowStatusSucceeded string = "succeeded" + + SourceFlowCodeVerification string = "code_verification" + SourceFlowNone string = "none" + SourceFlowReceiver string = "receiver" + SourceFlowRedirect string = "redirect" + + SourceRedirectFlowFailureReasonDeclined string = "declined" + SourceRedirectFlowFailureReasonProcessingError string = "processing_error" + SourceRedirectFlowFailureReasonUserAbort string = "user_abort" + + SourceRedirectFlowStatusFailed string = "failed" + SourceRedirectFlowStatusNotRequired string = "not_required" + SourceRedirectFlowStatusPending string = "pending" + SourceRedirectFlowStatusSucceeded string = "succeeded" + + SourceRefundAttributesMethodEmail string = "email" + SourceRefundAttributesMethodManual string = "manual" + + SourceRefundAttributesStatusAvailable string = "available" + SourceRefundAttributesStatusMissing string = "missing" + SourceRefundAttributesStatusRequested string = "requested" + + SourceStatusCanceled string = "canceled" + SourceStatusChargeable string = "chargeable" + SourceStatusConsumed string = "consumed" + SourceStatusFailed string = "failed" + SourceStatusPending string = "pending" + + SourceUsageReusable string = "reusable" + SourceUsageSingleUse string = "single_use" ) type SourceOwnerParams struct { @@ -109,84 +87,28 @@ 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 string `json:"failure_reason"` + ReturnURL string `json:"return_url"` + Status string `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 string `json:"refund_attributes_method"` + RefundAttributesStatus string `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 string `json:"status"` } type SourceMandateAcceptance struct { @@ -209,7 +131,7 @@ type Source struct { CodeVerification *CodeVerificationFlow `json:"code_verification,omitempty"` Created int64 `json:"created"` Currency Currency `json:"currency"` - Flow SourceFlow `json:"flow"` + Flow string `json:"flow"` ID string `json:"id"` Livemode bool `json:"livemode"` Mandate SourceMandate `json:"mandate"` @@ -218,10 +140,10 @@ type Source struct { Receiver *ReceiverFlow `json:"receiver,omitempty"` Redirect *RedirectFlow `json:"redirect,omitempty"` StatementDescriptor string `json:"statement_descriptor"` - Status SourceStatus `json:"status"` + Status string `json:"status"` Type string `json:"type"` TypeData map[string]interface{} - Usage SourceUsage `json:"usage"` + Usage string `json:"usage"` } // AppendTo implements custom encoding logic for SourceObjectParams so that the special diff --git a/source/client_test.go b/source/client_test.go index e18ec65963..5a08a549d2 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(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(stripe.SourceUsageReusable), } params.SetStripeAccount("acct_123") source, err := New(params) diff --git a/stripe.go b/stripe.go index 5bca240266..d49bdbd613 100644 --- a/stripe.go +++ b/stripe.go @@ -372,14 +372,14 @@ func (s *BackendConfiguration) ResponseToError(res *http.Response, resBody []byt root := e.(map[string]interface{}) stripeErr := &Error{ - Type: ErrorType(root["type"].(string)), + Type: string(root["type"].(string)), Msg: root["message"].(string), HTTPStatusCode: res.StatusCode, RequestID: res.Header.Get("Request-Id"), } if code, ok := root["code"]; ok { - stripeErr.Code = ErrorCode(code.(string)) + stripeErr.Code = string(code.(string)) } if param, ok := root["param"]; ok { diff --git a/sub.go b/sub.go index a53731a2dc..11acaaf6be 100644 --- a/sub.go +++ b/sub.go @@ -6,13 +6,14 @@ import ( "github.com/stripe/stripe-go/form" ) -// 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 - -// 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 ( + SubscriptionStatusActive string = "active" + SubscriptionStatusAll string = "all" + SubscriptionStatusCanceled string = "canceled" + SubscriptionStatusPastDue string = "past_due" + SubscriptionStatusTrialing string = "trialing" + SubscriptionStatusUnpaid string = "unpaid" +) // 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. @@ -77,19 +78,19 @@ 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. // For more details see https://stripe.com/docs/api#subscriptions. type Subscription struct { ApplicationFeePercent float64 `json:"application_fee_percent"` - Billing SubscriptionBilling `json:"billing"` + Billing string `json:"billing"` BillingCycleAnchor int64 `json:"billing_cycle_anchor"` CanceledAt int64 `json:"canceled_at"` Created int64 `json:"created"` @@ -106,7 +107,7 @@ type Subscription struct { Plan *Plan `json:"plan"` Quantity int64 `json:"quantity"` Start int64 `json:"start"` - Status SubscriptionStatus `json:"status"` + Status string `json:"status"` TaxPercent float64 `json:"tax_percent"` TrialEnd int64 `json:"trial_end"` TrialStart int64 `json:"trial_start"` 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/threedsecure.go b/threedsecure.go index 2a2a621e5a..6c49bbd1dd 100644 --- a/threedsecure.go +++ b/threedsecure.go @@ -1,7 +1,5 @@ package stripe -type ThreeDSecureStatus string - // ThreeDSecureParams is the set of parameters that can be used when creating a 3DS object. // For more details see https://stripe.com/docs/api#create_three_d_secure. type ThreeDSecureParams struct { @@ -16,14 +14,14 @@ type ThreeDSecureParams struct { // ThreeDSecure is the resource representing a Stripe 3DS object // For more details see https://stripe.com/docs/api#three_d_secure. type ThreeDSecure struct { - Amount int64 `json:"amount"` - Authenticated bool `json:"authenticated"` - Card *Card `json:"card"` - Created int64 `json:"created"` - Currency Currency `json:"currency"` - ID string `json:"id"` - Livemode bool `json:"livemode"` - RedirectURL string `json:"redirect_url"` - Status ThreeDSecureStatus `json:"status"` - Supported string `json:"supported"` + Amount int64 `json:"amount"` + Authenticated bool `json:"authenticated"` + Card *Card `json:"card"` + Created int64 `json:"created"` + Currency Currency `json:"currency"` + ID string `json:"id"` + Livemode bool `json:"livemode"` + RedirectURL string `json:"redirect_url"` + Status string `json:"status"` + Supported string `json:"supported"` } diff --git a/token.go b/token.go index 90732051f8..2ea5a89b17 100644 --- a/token.go +++ b/token.go @@ -1,8 +1,10 @@ package stripe -// TokenType is the list of allowed values for a token's type. -// Allowed values are "card", "bank_account". -type TokenType string +const ( + TokenTypeCard string = "card" + TokenTypeBankAccount string = "bank_account" + TokenTypePII string = "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. @@ -31,10 +33,10 @@ type Token struct { // with Stripe Checkout. Email string `json:"email"` - ID string `json:"id"` - Livemode bool `json:"livemode"` - Type TokenType `json:"type"` - Used bool `json:"used"` + ID string `json:"id"` + Livemode bool `json:"livemode"` + Type string `json:"type"` + Used bool `json:"used"` } // PIIParams are parameters for personal identifiable information (PII). 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..9316e33667 100644 --- a/transfer.go +++ b/transfer.go @@ -2,9 +2,12 @@ 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 string = "alipay_account" + TransferSourceTypeBankAccount string = "bank_account" + TransferSourceTypeBitcoinReceiver string = "bitcoin_receiver" + TransferSourceTypeCard string = "card" +) // TransferDestination describes the destination of a Transfer. // The Type should indicate which object is fleshed out @@ -44,7 +47,7 @@ type Transfer struct { BalanceTransaction *BalanceTransaction `json:"balance_transaction"` Created int64 `json:"created"` Currency Currency `json:"currency"` - Destination TransferDestination `json:"destination"` + Destination string `json:"destination"` DestinationPayment *Charge `json:"destination_payment"` ID string `json:"id"` Livemode bool `json:"livemode"` 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..66d89d4525 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(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)