~evanj/cms

ref: 99a3bb7fc511e3f448a358691896ba1300f73a93 cms/vendor/github.com/stripe/stripe-go/v71/recipient.go -rw-r--r-- 3.3 KiB
99a3bb7fEvan M Jones WIP(rbac): Decorator object complete. TODO: Specify role in invite. 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package stripe

import (
	"encoding/json"

	"github.com/stripe/stripe-go/v71/form"
)

// RecipientType is the list of allowed values for the recipient's type.
type RecipientType string

// List of values that RecipientType can take.
const (
	RecipientTypeIndividual  RecipientType = "individual"
	RecipientTypeCorporation RecipientType = "corporation"
)

// RecipientParams is the set of parameters that can be used when creating or updating recipients.
// For more details see https://stripe.com/docs/api#create_recipient and https://stripe.com/docs/api#update_recipient.
type RecipientParams struct {
	Params `form:"*"`

	BankAccount *BankAccountParams `form:"-"` // Kind of an abberation because a bank account's token will be replace the rest of its data. Keep this in a custom AppendTo for now.
	Card        *CardParams        `form:"card"`
	DefaultCard *string            `form:"default_card"`
	Description *string            `form:"description"`
	Email       *string            `form:"email"`
	Name        *string            `form:"name"`
	TaxID       *string            `form:"tax_id"`
	Token       *string            `form:"card"`
	Type        *string            `form:"-"` // Doesn't seem to be used anywhere
}

// AppendTo implements some custom behavior around a recipient's bank account.
// This was probably the wrong way to go about this, but grandfather the
// behavior for the time being.
func (p *RecipientParams) AppendTo(body *form.Values, keyParts []string) {
	if p.BankAccount != nil {
		if p.BankAccount.Token != nil {
			body.Add("bank_account", StringValue(p.BankAccount.Token))
		} else {
			form.AppendToPrefixed(body, p.BankAccount, append(keyParts, "bank_account"))
		}
	}
}

// RecipientListParams is the set of parameters that can be used when listing recipients.
// For more details see https://stripe.com/docs/api#list_recipients.
type RecipientListParams struct {
	ListParams `form:"*"`
	Verified   *bool `form:"verified"`
}

// Recipient is the resource representing a Stripe recipient.
// For more details see https://stripe.com/docs/api#recipients.
type Recipient struct {
	APIResource
	ActiveAccount *BankAccount      `json:"active_account"`
	Cards         *CardList         `json:"cards"`
	Created       int64             `json:"created"`
	DefaultCard   *Card             `json:"default_card"`
	Deleted       bool              `json:"deleted"`
	Description   string            `json:"description"`
	Email         string            `json:"email"`
	ID            string            `json:"id"`
	Livemode      bool              `json:"livemode"`
	Metadata      map[string]string `json:"metadata"`
	MigratedTo    *Account          `json:"migrated_to"`
	Name          string            `json:"name"`
	Type          RecipientType     `json:"type"`
}

// RecipientList is a list of recipients as retrieved from a list endpoint.
type RecipientList struct {
	APIResource
	ListMeta
	Data []*Recipient `json:"data"`
}

// UnmarshalJSON handles deserialization of a Recipient.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (r *Recipient) UnmarshalJSON(data []byte) error {
	if id, ok := ParseID(data); ok {
		r.ID = id
		return nil
	}

	type recipient Recipient
	var v recipient
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}

	*r = Recipient(v)
	return nil
}