-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the Person resource and fix broken tests
- Loading branch information
1 parent
08bc5b8
commit 76a79b5
Showing
10 changed files
with
350 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package stripe | ||
|
||
import "encoding/json" | ||
|
||
// RelationshipParams is used to set the relationship between an account and a person. | ||
type RelationshipParams struct { | ||
AccountOpener *bool `form:"account_opener"` | ||
Director *bool `form:"director"` | ||
Executive *bool `form:"executive"` | ||
Owner *bool `form:"owner"` | ||
PercentOwnership *float64 `form:"percent_ownership"` | ||
Title *string `form:"title"` | ||
} | ||
|
||
// PersonParams is the set of parameters that can be used when creating or updating a person. | ||
// For more details see https://stripe.com/docs/api#create_person. | ||
type PersonParams struct { | ||
Params `form:"*"` | ||
Account *string `form:"-"` // Included in URL | ||
Address *AccountAddressParams `form:"address"` | ||
AddressKana *AccountAddressParams `form:"address_kana"` | ||
AddressKanji *AccountAddressParams `form:"address_kanji"` | ||
DOB *DOBParams `form:"dob"` | ||
Email *string `form:"email"` | ||
FirstName *string `form:"first_name"` | ||
FirstNameKana *string `form:"first_name_kana"` | ||
FirstNameKanji *string `form:"first_name_kanji"` | ||
Gender *string `form:"gender"` | ||
IDNumber *string `form:"id_number"` | ||
LastName *string `form:"last_name"` | ||
LastNameKana *string `form:"last_name_kana"` | ||
LastNameKanji *string `form:"last_name_kanji"` | ||
MaidenName *string `form:"maiden_name"` | ||
Phone *string `form:"phone"` | ||
Relationship *RelationshipParams `form:"relationship"` | ||
SSNLast4 *string `form:"ssn_last_4"` | ||
} | ||
|
||
// RelationshipListParams is used to filter persons by the relationship | ||
type RelationshipListParams struct { | ||
AccountOpener *bool `form:"account_opener"` | ||
Director *bool `form:"director"` | ||
Executive *bool `form:"executive"` | ||
Owner *bool `form:"owner"` | ||
} | ||
|
||
// PersonListParams is the set of parameters that can be used when listing persons. | ||
// For more detail see https://stripe.com/docs/api#list_persons. | ||
type PersonListParams struct { | ||
ListParams `form:"*"` | ||
Account *string `form:"-"` // Included in URL | ||
Relationship *RelationshipListParams `form:"relationship"` | ||
} | ||
|
||
// Relationship represents extra information needed for a Person. | ||
type Relationship struct { | ||
AccountOpener bool `json:"account_opener"` | ||
Director bool `json:"director"` | ||
Executive bool `json:"executive"` | ||
Owner bool `json:"owner"` | ||
PercentOwnership float64 `json:"percent_ownership"` | ||
Title string `json:"title"` | ||
} | ||
|
||
// Requirements represents what's missing to verify a Person. | ||
type Requirements struct { | ||
CurrentlyDue []string `json:"currently_due"` | ||
EventuallyDue []string `json:"eventually_due"` | ||
PastDue []string `json:"past_due"` | ||
} | ||
|
||
// Person is the resource representing a Stripe person. | ||
// For more details see https://stripe.com/docs/api#persons. | ||
type Person struct { | ||
Account string `json:"account"` | ||
Address *AccountAddress `json:"address"` | ||
AddressKana *AccountAddress `json:"address_kana"` | ||
AddressKanji *AccountAddress `json:"address_kanji"` | ||
Deleted bool `json:"deleted"` | ||
DOB *DOB `json:"dob"` | ||
Email string `json:"email"` | ||
FirstName string `json:"first_name"` | ||
FirstNameKana string `json:"first_name_kana"` | ||
FirstNameKanji string `json:"first_name_kanji"` | ||
Gender string `json:"gender"` | ||
ID string `json:"id"` | ||
IDNumberProvided bool `json:"id_number_provided"` | ||
LastName string `json:"last_name"` | ||
LastNameKana string `json:"last_name_kana"` | ||
LastNameKanji string `json:"last_name_kanji"` | ||
MaidenName string `json:"maiden_name"` | ||
Metadata map[string]string `json:"metadata"` | ||
Object string `json:"object"` | ||
Phone string `json:"phone"` | ||
Relationship *Relationship `json:"relationship"` | ||
Requirements *Requirements `json:"requirements"` | ||
SSNLast4Provided bool `json:"ssn_last_4_provided"` | ||
Verification *IdentityVerification `json:"verification"` | ||
} | ||
|
||
// PersonList is a list of persons as retrieved from a list endpoint. | ||
type PersonList struct { | ||
ListMeta | ||
Data []*Person `json:"data"` | ||
} | ||
|
||
// UnmarshalJSON handles deserialization of a Person. | ||
// This custom unmarshaling is needed because the resulting | ||
// property may be an id or the full struct if it was expanded. | ||
func (c *Person) UnmarshalJSON(data []byte) error { | ||
if id, ok := ParseID(data); ok { | ||
c.ID = id | ||
return nil | ||
} | ||
|
||
type person Person | ||
var v person | ||
if err := json.Unmarshal(data, &v); err != nil { | ||
return err | ||
} | ||
|
||
*c = Person(v) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Package person provides the /accounts/persons APIs | ||
package person | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
stripe "github.com/stripe/stripe-go" | ||
"github.com/stripe/stripe-go/form" | ||
) | ||
|
||
// Client is used to invoke /accounts/persons APIs. | ||
type Client struct { | ||
B stripe.Backend | ||
Key string | ||
} | ||
|
||
// New creates a new account person. | ||
func New(params *stripe.PersonParams) (*stripe.Person, error) { | ||
return getC().New(params) | ||
} | ||
|
||
// New creates a new account person. | ||
func (c Client) New(params *stripe.PersonParams) (*stripe.Person, error) { | ||
path := stripe.FormatURLPath("/accounts/%s/persons", stripe.StringValue(params.Account)) | ||
person := &stripe.Person{} | ||
err := c.B.Call(http.MethodPost, path, c.Key, params, person) | ||
return person, err | ||
} | ||
|
||
// Get returns the details of a account person. | ||
func Get(id string, params *stripe.PersonParams) (*stripe.Person, error) { | ||
return getC().Get(id, params) | ||
} | ||
|
||
// Get returns the details of a account person. | ||
func (c Client) Get(id string, params *stripe.PersonParams) (*stripe.Person, error) { | ||
if params == nil { | ||
return nil, fmt.Errorf("params cannot be nil, and params.Account must be set") | ||
} | ||
|
||
path := stripe.FormatURLPath("/accounts/%s/persons/%s", | ||
stripe.StringValue(params.Account), id) | ||
person := &stripe.Person{} | ||
err := c.B.Call(http.MethodGet, path, c.Key, params, person) | ||
return person, err | ||
} | ||
|
||
// Update updates a account person's properties. | ||
func Update(id string, params *stripe.PersonParams) (*stripe.Person, error) { | ||
return getC().Update(id, params) | ||
} | ||
|
||
// Update updates a account person's properties. | ||
func (c Client) Update(id string, params *stripe.PersonParams) (*stripe.Person, error) { | ||
path := stripe.FormatURLPath("/accounts/%s/persons/%s", | ||
stripe.StringValue(params.Account), id) | ||
person := &stripe.Person{} | ||
err := c.B.Call(http.MethodPost, path, c.Key, params, person) | ||
return person, err | ||
} | ||
|
||
// Del removes a person. | ||
func Del(id string, params *stripe.PersonParams) (*stripe.Person, error) { | ||
return getC().Del(id, params) | ||
} | ||
|
||
// Del removes a person. | ||
func (c Client) Del(id string, params *stripe.PersonParams) (*stripe.Person, error) { | ||
path := stripe.FormatURLPath("/accounts/%s/persons/%s", | ||
stripe.StringValue(params.Account), id) | ||
person := &stripe.Person{} | ||
err := c.B.Call(http.MethodDelete, path, c.Key, params, person) | ||
return person, err | ||
} | ||
|
||
// List returns a list of account persons. | ||
func List(params *stripe.PersonListParams) *Iter { | ||
return getC().List(params) | ||
} | ||
|
||
// List returns a list of account persons. | ||
func (c Client) List(listParams *stripe.PersonListParams) *Iter { | ||
path := stripe.FormatURLPath("/accounts/%s/persons", stripe.StringValue(listParams.Account)) | ||
|
||
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) { | ||
list := &stripe.PersonList{} | ||
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) | ||
|
||
ret := make([]interface{}, len(list.Data)) | ||
for i, v := range list.Data { | ||
ret[i] = v | ||
} | ||
|
||
return ret, list.ListMeta, err | ||
})} | ||
} | ||
|
||
// Iter is an iterator for account persons. | ||
type Iter struct { | ||
*stripe.Iter | ||
} | ||
|
||
// Person returns the account person which the iterator is currently pointing to. | ||
func (i *Iter) Person() *stripe.Person { | ||
return i.Current().(*stripe.Person) | ||
} | ||
|
||
func getC() Client { | ||
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} | ||
} |
Oops, something went wrong.