Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cjavilla-stripe committed Jul 10, 2019
1 parent 3c92581 commit ca72804
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 323 deletions.
3 changes: 2 additions & 1 deletion form/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (f *Values) Encode() string {
return buf.String()
}

// Encode encodes only the values into “URL encoded” form
// EncodeValues encodes only the values into “URL encoded” form
// ("bar=baz&foo=quux") so that we can have keys like `stripe_user[email]=test`
func (f *Values) EncodeValues() string {
var buf bytes.Buffer
Expand All @@ -513,6 +513,7 @@ func (f *Values) EncodeValues() string {
}
return buf.String()
}

// Empty returns true if no parameters have been set.
func (f *Values) Empty() bool {
return len(f.values) == 0
Expand Down
175 changes: 87 additions & 88 deletions oauth.go
Original file line number Diff line number Diff line change
@@ -1,150 +1,149 @@
package stripe

// Type of OAuth scope.
// OAuthScopeType is the type of OAuth scope.
type OAuthScopeType string

// List of possible values for OAuth scopes.
const (
OAuthScopeTypeReadOnly OAuthScopeType = "read_only"
OAuthScopeTypeReadWrite OAuthScopeType = "read_write"
OAuthScopeTypeReadOnly OAuthScopeType = "read_only"
OAuthScopeTypeReadWrite OAuthScopeType = "read_write"
)

// Type of token. This will always be "bearer."
// OAuthTokenType is the type of token. This will always be "bearer."
type OAuthTokenType string

// List of possible OAuthTokenType values.
const (
OAuthTokenTypeBearer OAuthTokenType = "bearer"
OAuthTokenTypeBearer OAuthTokenType = "bearer"
)

// Type of the business for the Stripe oauth user.
// OAuthStripeUserBusinessType is the business type for the Stripe oauth user.
type OAuthStripeUserBusinessType string

// List of supported values for business type.
const (
OAuthStripeUserBusinessTypeCorporation OAuthStripeUserBusinessType = "corporation"
OAuthStripeUserBusinessTypeLLC OAuthStripeUserBusinessType = "llc"
OAuthStripeUserBusinessTypeNonProfit OAuthStripeUserBusinessType = "non_profit"
OAuthStripeUserBusinessTypePartnership OAuthStripeUserBusinessType = "partnership"
OAuthStripeUserBusinessTypeSoleProp OAuthStripeUserBusinessType = "sole_prop"
OAuthStripeUserBusinessTypeCorporation OAuthStripeUserBusinessType = "corporation"
OAuthStripeUserBusinessTypeLLC OAuthStripeUserBusinessType = "llc"
OAuthStripeUserBusinessTypeNonProfit OAuthStripeUserBusinessType = "non_profit"
OAuthStripeUserBusinessTypePartnership OAuthStripeUserBusinessType = "partnership"
OAuthStripeUserBusinessTypeSoleProp OAuthStripeUserBusinessType = "sole_prop"
)

// The gender of the person who will be filling out a Stripe application.
// (International regulations require either male or female.)
// OAuthStripeUserGender of the person who will be filling out a Stripe
// application. (International regulations require either male or female.)
type OAuthStripeUserGender string

// The gender of the person who will be filling out a Stripe application.
// (International regulations require either male or female.)
const (
OAuthStripeUserGenderFemale OAuthStripeUserGender = "female"
OAuthStripeUserGenderMale OAuthStripeUserGender = "male"
OAuthStripeUserGenderFemale OAuthStripeUserGender = "female"
OAuthStripeUserGenderMale OAuthStripeUserGender = "male"
)

// Type of Errors raised when failing authorization.
// OAuthError is the type of errors raised when failing authorization.
type OAuthError string

// List of supported OAuthError values.
const (
OAuthErrorInvalidGrant OAuthError = "invalid_grant"
OAuthErrorInvalidRequest OAuthError = "invalid_request"
OAuthErrorInvalidScope OAuthError = "invalid_scope"
OAuthErrorUnsupportedGrantType OAuthError = "unsupported_grant_type"
OAuthErrorUnsupportedResponseType OAuthError = "unsupported_response_type"
OAuthErrorInvalidGrant OAuthError = "invalid_grant"
OAuthErrorInvalidRequest OAuthError = "invalid_request"
OAuthErrorInvalidScope OAuthError = "invalid_scope"
OAuthErrorUnsupportedGrantType OAuthError = "unsupported_grant_type"
OAuthErrorUnsupportedResponseType OAuthError = "unsupported_response_type"
)


// Type of Errors raised when failing authorization.
// DeauthorizationError the type of errors raised when failing authorization.
type DeauthorizationError string

// List of supported DeauthorizationError values.
const (
DeauthorizationErrorInvalidClient DeauthorizationError = "invalid_client"
DeauthorizationErrorInvalidRequest DeauthorizationError = "invalid_request"
DeauthorizationErrorInvalidClient DeauthorizationError = "invalid_client"
DeauthorizationErrorInvalidRequest DeauthorizationError = "invalid_request"
)

// Params for the stripe_user OAuth Authorize params.
// OAuthStripeUserParams for the stripe_user OAuth Authorize params.
type OAuthStripeUserParams struct {
BlockKana *string `form:"block_kana"`
BlockKanji *string `form:"block_kanji"`
BuildingKana *string `form:"building_kana"`
BuildingKanji *string `form:"building_kanji"`
BusinessName *string `form:"business_name"`
BusinessType OAuthStripeUserBusinessType `form:"business_type"`
City *string `form:"city"`
Country *string `form:"country"`
Currency *string `form:"currency"`
DobDay uint64 `form:"dob_day"`
DobMonth uint64 `form:"dob_month"`
DobYear uint64 `form:"dob_year"`
Email *string `form:"email"`
FirstName *string `form:"first_name"`
FirstNameKana *string `form:"first_name_kana"`
FirstNameKanji *string `form:"first_name_kanji"`
Gender OAuthStripeUserGender `form:"gender"`
LastName *string `form:"last_name"`
LastNameKana *string `form:"last_name_kana"`
LastNameKanji *string `form:"last_name_kanji"`
PhoneNumber *string `form:"phone_number"`
PhysicalProduct *bool `form:"physical_product"`
ProductDescription *string `form:"product_description"`
State *string `form:"state"`
StreetAddress *string `form:"street_address"`
Url *string `form:"url"`
Zip *string `form:"zip"`
BlockKana *string `form:"block_kana"`
BlockKanji *string `form:"block_kanji"`
BuildingKana *string `form:"building_kana"`
BuildingKanji *string `form:"building_kanji"`
BusinessName *string `form:"business_name"`
BusinessType OAuthStripeUserBusinessType `form:"business_type"`
City *string `form:"city"`
Country *string `form:"country"`
Currency *string `form:"currency"`
DobDay uint64 `form:"dob_day"`
DobMonth uint64 `form:"dob_month"`
DobYear uint64 `form:"dob_year"`
Email *string `form:"email"`
FirstName *string `form:"first_name"`
FirstNameKana *string `form:"first_name_kana"`
FirstNameKanji *string `form:"first_name_kanji"`
Gender OAuthStripeUserGender `form:"gender"`
LastName *string `form:"last_name"`
LastNameKana *string `form:"last_name_kana"`
LastNameKanji *string `form:"last_name_kanji"`
PhoneNumber *string `form:"phone_number"`
PhysicalProduct *bool `form:"physical_product"`
ProductDescription *string `form:"product_description"`
State *string `form:"state"`
StreetAddress *string `form:"street_address"`
URL *string `form:"url"`
Zip *string `form:"zip"`
}

// Params for creating OAuth AuthorizeURL's.
// AuthorizeURLParams for creating OAuth AuthorizeURL's.
type AuthorizeURLParams struct {
Params `form:"*"`
AlwaysPrompt *bool `form:"always_prompt"`
ClientID *string `form:"client_id"`
Express *bool `form:"-"`
RedirectURI *string `form:"redirect_uri"`
ResponseType *string `form:"response_type"`
Scope *string `form:"scope"`
State *string `form:"state"`
StripeLanding *string `form:"stripe_landing"`
StripeUser *OAuthStripeUserParams `form:"stripe_user"`
Params `form:"*"`
AlwaysPrompt *bool `form:"always_prompt"`
ClientID *string `form:"client_id"`
Express *bool `form:"-"`
RedirectURI *string `form:"redirect_uri"`
ResponseType *string `form:"response_type"`
Scope *string `form:"scope"`
State *string `form:"state"`
StripeLanding *string `form:"stripe_landing"`
StripeUser *OAuthStripeUserParams `form:"stripe_user"`
}

// Params for deauthorizing an account.
// DeauthorizeParams for deauthorizing an account.
type DeauthorizeParams struct {
Params `form:"*"`
ClientID *string `form:"client_id"`
StripeUserID *string `form:"stripe_user_id"`
Params `form:"*"`
ClientID *string `form:"client_id"`
StripeUserID *string `form:"stripe_user_id"`
}

// OAuthTokenParams is the set of paramaters that can be used to request
// OAuthTokens.
type OAuthTokenParams struct {
Params `form:"*"`
ClientSecret *string `form:"client_secret"`
Code *string `form:"code"`
GrantType *string `form:"grant_type"`
RefreshToken *string `form:"refresh_token"`
Scope *string `form:"scope"`
Params `form:"*"`
ClientSecret *string `form:"client_secret"`
Code *string `form:"code"`
GrantType *string `form:"grant_type"`
RefreshToken *string `form:"refresh_token"`
Scope *string `form:"scope"`
}

// OAuthToken is the value of the OAuthToken from OAuth flow.
// https://stripe.com/docs/connect/oauth-reference#post-token
type OAuthToken struct {
Error OAuthError `json:"error"`
ErrorDescription string `json:"error_description"`
Livemode bool `json:"livemode"`
Scope OAuthScopeType `json:"scope"`
StripeUserID string `json:"stripe_user_id"`
TokenType OAuthTokenType `json:"token_type"`

// Deprecated, please use StripeUserID
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
StripePublishableKey string `json:"stripe_publishable_key"`
Error OAuthError `json:"error"`
ErrorDescription string `json:"error_description"`
Livemode bool `json:"livemode"`
Scope OAuthScopeType `json:"scope"`
StripeUserID string `json:"stripe_user_id"`
TokenType OAuthTokenType `json:"token_type"`

// Deprecated, please use StripeUserID
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
StripePublishableKey string `json:"stripe_publishable_key"`
}

// Deauthorization is the value of the return from deauthorizing.
// https://stripe.com/docs/connect/oauth-reference#post-deauthorize
type Deauthorization struct {
Error DeauthorizationError `json:"error"`
ErrorDescription string `json:"error_description"`
StripeUserID string `json:"stripe_user_id"`
Error DeauthorizationError `json:"error"`
ErrorDescription string `json:"error_description"`
StripeUserID string `json:"stripe_user_id"`
}
98 changes: 52 additions & 46 deletions oauth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,83 @@
package oauth

import (
"fmt"
"net/http"
"github.com/stripe/stripe-go/form"
stripe "github.com/stripe/stripe-go"
"fmt"
stripe "github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/form"
"net/http"
)

// Client is used to invoke /oauth and related APIs.
type Client struct {
B stripe.Backend
Key string
B stripe.Backend
Key string
}

// AuthorizeURL builds the OAuth authorize URL.
func AuthorizeURL(params *stripe.AuthorizeURLParams) string {
return getC().AuthorizeURL(params)
return getC().AuthorizeURL(params)
}

// AuthorizeURL builds the OAuth authorize URL.
func (c Client) AuthorizeURL(params *stripe.AuthorizeURLParams) string {
express := ""
if stripe.BoolValue(params.Express) {
express = "/express"
}
if params.ClientID == nil {
params.ClientID = stripe.String(stripe.ClientID)
}
if params.ResponseType == nil {
params.ResponseType = stripe.String("code")
}
qs := &form.Values{}
form.AppendTo(qs, params)
return fmt.Sprintf(
"https://connect.stripe.com%s/oauth/authorize?%s",
express,
qs.EncodeValues(),
)
express := ""
if stripe.BoolValue(params.Express) {
express = "/express"
}
if params.ClientID == nil {
params.ClientID = stripe.String(stripe.ClientID)
}
if params.ResponseType == nil {
params.ResponseType = stripe.String("code")
}
qs := &form.Values{}
form.AppendTo(qs, params)
return fmt.Sprintf(
"https://connect.stripe.com%s/oauth/authorize?%s",
express,
qs.EncodeValues(),
)
}

// New creates the OAuthToken using a code after successful redirection back.
func New(params *stripe.OAuthTokenParams) (*stripe.OAuthToken, error) {
return getC().New(params)
return getC().New(params)
}

// New creates the OAuthToken using a code after successful redirection back.
func (c Client) New(params *stripe.OAuthTokenParams) (*stripe.OAuthToken, error) {
// client_secret is sent in the post body for this endpoint.
if stripe.StringValue(params.ClientSecret) == "" {
params.ClientSecret = stripe.String(stripe.Key)
}
if stripe.StringValue(params.GrantType) == "" {
params.GrantType = stripe.String("authorization_code")
}
// client_secret is sent in the post body for this endpoint.
if stripe.StringValue(params.ClientSecret) == "" {
params.ClientSecret = stripe.String(stripe.Key)
}
if stripe.StringValue(params.GrantType) == "" {
params.GrantType = stripe.String("authorization_code")
}

oauth_token := &stripe.OAuthToken{}
err := c.B.Call(http.MethodPost, "/oauth/token", c.Key, params, oauth_token)
oauthToken := &stripe.OAuthToken{}
err := c.B.Call(http.MethodPost, "/oauth/token", c.Key, params, oauthToken)

return oauth_token, err
return oauthToken, err
}

// Del deauthorizes a connected account.
func Del(params *stripe.DeauthorizeParams) (*stripe.Deauthorization, error) {
return getC().Del(params)
return getC().Del(params)
}

// Del deauthorizes a connected account.
func (c Client) Del(params *stripe.DeauthorizeParams) (*stripe.Deauthorization, error) {
deauthorization := &stripe.Deauthorization{}
err := c.B.Call(
http.MethodPost,
"/oauth/deauthorize",
c.Key,
params,
deauthorization,
)
return deauthorization, err
deauthorization := &stripe.Deauthorization{}
err := c.B.Call(
http.MethodPost,
"/oauth/deauthorize",
c.Key,
params,
deauthorization,
)
return deauthorization, err
}

func getC() Client {
return Client{stripe.GetBackend(stripe.ConnectBackend), stripe.Key}
return Client{stripe.GetBackend(stripe.ConnectBackend), stripe.Key}
}
Loading

0 comments on commit ca72804

Please sign in to comment.