-
Notifications
You must be signed in to change notification settings - Fork 525
Expand file tree
/
Copy pathclient.go
More file actions
104 lines (91 loc) · 4.31 KB
/
Copy pathclient.go
File metadata and controls
104 lines (91 loc) · 4.31 KB
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
98
99
100
101
102
103
104
//
//
// File generated from our OpenAPI spec
//
//
// Package source provides the /v1/sources APIs
package source
import (
"fmt"
"net/http"
stripe "github.com/stripe/stripe-go/v86"
)
// Client is used to invoke /v1/sources APIs.
// Deprecated: Use [stripe.Client] instead. See the [migration guide] for more info.
//
// [migration guide]: https://github.com/stripe/stripe-go/wiki/Migration-guide-for-Stripe-Client
type Client struct {
B stripe.Backend
Key string
}
// Creates a new source object.
func New(params *stripe.SourceParams) (*stripe.Source, error) {
return getC().New(params)
}
// Creates a new source object.
//
// Deprecated: Client methods are deprecated. This should be accessed instead through [stripe.Client]. See the [migration guide] for more info.
//
// [migration guide]: https://github.com/stripe/stripe-go/wiki/Migration-guide-for-Stripe-Client
func (c Client) New(params *stripe.SourceParams) (*stripe.Source, error) {
source := &stripe.Source{}
err := c.B.Call(http.MethodPost, "/v1/sources", c.Key, params, source)
return source, err
}
// Retrieves an existing source object. Supply the unique source ID from a source creation request and Stripe will return the corresponding up-to-date source object information.
func Get(id string, params *stripe.SourceParams) (*stripe.Source, error) {
return getC().Get(id, params)
}
// Retrieves an existing source object. Supply the unique source ID from a source creation request and Stripe will return the corresponding up-to-date source object information.
//
// Deprecated: Client methods are deprecated. This should be accessed instead through [stripe.Client]. See the [migration guide] for more info.
//
// [migration guide]: https://github.com/stripe/stripe-go/wiki/Migration-guide-for-Stripe-Client
func (c Client) Get(id string, params *stripe.SourceParams) (*stripe.Source, error) {
path := stripe.FormatURLPath("/v1/sources/%s", id)
source := &stripe.Source{}
err := c.B.Call(http.MethodGet, path, c.Key, params, source)
return source, err
}
// Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
//
// This request accepts the metadata and owner as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our [payment method guides](https://docs.stripe.com/docs/sources) for more detail.
func Update(id string, params *stripe.SourceParams) (*stripe.Source, error) {
return getC().Update(id, params)
}
// Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
//
// This request accepts the metadata and owner as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our [payment method guides](https://docs.stripe.com/docs/sources) for more detail.
//
// Deprecated: Client methods are deprecated. This should be accessed instead through [stripe.Client]. See the [migration guide] for more info.
//
// [migration guide]: https://github.com/stripe/stripe-go/wiki/Migration-guide-for-Stripe-Client
func (c Client) Update(id string, params *stripe.SourceParams) (*stripe.Source, error) {
path := stripe.FormatURLPath("/v1/sources/%s", id)
source := &stripe.Source{}
err := c.B.Call(http.MethodPost, path, c.Key, params, source)
return source, err
}
// Delete a specified source for a given customer.
func Detach(id string, params *stripe.SourceDetachParams) (*stripe.Source, error) {
return getC().Detach(id, params)
}
// Delete a specified source for a given customer.
//
// Deprecated: Client methods are deprecated. This should be accessed instead through [stripe.Client]. See the [migration guide] for more info.
//
// [migration guide]: https://github.com/stripe/stripe-go/wiki/Migration-guide-for-Stripe-Client
func (c Client) Detach(id string, params *stripe.SourceDetachParams) (*stripe.Source, error) {
if params.Customer == nil {
return nil, fmt.Errorf(
"invalid source detach params: Customer needs to be set")
}
path := stripe.FormatURLPath(
"/v1/customers/%s/sources/%s", stripe.StringValue(params.Customer), id)
source := &stripe.Source{}
err := c.B.Call(http.MethodDelete, path, c.Key, params, source)
return source, err
}
func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}