-
Notifications
You must be signed in to change notification settings - Fork 0
/
carddispute.go
275 lines (243 loc) · 10.4 KB
/
carddispute.go
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// File generated from our OpenAPI spec by Stainless.
package increase
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
"github.com/increase/increase-go/internal/apijson"
"github.com/increase/increase-go/internal/apiquery"
"github.com/increase/increase-go/internal/param"
"github.com/increase/increase-go/internal/requestconfig"
"github.com/increase/increase-go/internal/shared"
"github.com/increase/increase-go/option"
)
// CardDisputeService contains methods and other services that help with
// interacting with the increase API. Note, unlike clients, this service does not
// read variables from the environment automatically. You should not instantiate
// this service directly, and instead use the [NewCardDisputeService] method
// instead.
type CardDisputeService struct {
Options []option.RequestOption
}
// NewCardDisputeService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewCardDisputeService(opts ...option.RequestOption) (r *CardDisputeService) {
r = &CardDisputeService{}
r.Options = opts
return
}
// Create a Card Dispute
func (r *CardDisputeService) New(ctx context.Context, body CardDisputeNewParams, opts ...option.RequestOption) (res *CardDispute, err error) {
opts = append(r.Options[:], opts...)
path := "card_disputes"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieve a Card Dispute
func (r *CardDisputeService) Get(ctx context.Context, cardDisputeID string, opts ...option.RequestOption) (res *CardDispute, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("card_disputes/%s", cardDisputeID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List Card Disputes
func (r *CardDisputeService) List(ctx context.Context, query CardDisputeListParams, opts ...option.RequestOption) (res *shared.Page[CardDispute], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "card_disputes"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List Card Disputes
func (r *CardDisputeService) ListAutoPaging(ctx context.Context, query CardDisputeListParams, opts ...option.RequestOption) *shared.PageAutoPager[CardDispute] {
return shared.NewPageAutoPager(r.List(ctx, query, opts...))
}
// If unauthorized activity occurs on a card, you can create a Card Dispute and
// we'll return the funds if appropriate.
type CardDispute struct {
// The Card Dispute identifier.
ID string `json:"id,required"`
// If the Card Dispute's status is `accepted`, this will contain details of the
// successful dispute.
Acceptance CardDisputeAcceptance `json:"acceptance,required,nullable"`
// The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which
// the Card Dispute was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// The identifier of the Transaction that was disputed.
DisputedTransactionID string `json:"disputed_transaction_id,required"`
// Why you disputed the Transaction in question.
Explanation string `json:"explanation,required"`
// If the Card Dispute's status is `rejected`, this will contain details of the
// unsuccessful dispute.
Rejection CardDisputeRejection `json:"rejection,required,nullable"`
// The results of the Dispute investigation.
Status CardDisputeStatus `json:"status,required"`
// A constant representing the object's type. For this resource it will always be
// `card_dispute`.
Type CardDisputeType `json:"type,required"`
JSON cardDisputeJSON `json:"-"`
}
// cardDisputeJSON contains the JSON metadata for the struct [CardDispute]
type cardDisputeJSON struct {
ID apijson.Field
Acceptance apijson.Field
CreatedAt apijson.Field
DisputedTransactionID apijson.Field
Explanation apijson.Field
Rejection apijson.Field
Status apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardDispute) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
// If the Card Dispute's status is `accepted`, this will contain details of the
// successful dispute.
type CardDisputeAcceptance struct {
// The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which
// the Card Dispute was accepted.
AcceptedAt time.Time `json:"accepted_at,required" format:"date-time"`
// The identifier of the Card Dispute that was accepted.
CardDisputeID string `json:"card_dispute_id,required"`
// The identifier of the Transaction that was created to return the disputed funds
// to your account.
TransactionID string `json:"transaction_id,required"`
JSON cardDisputeAcceptanceJSON `json:"-"`
}
// cardDisputeAcceptanceJSON contains the JSON metadata for the struct
// [CardDisputeAcceptance]
type cardDisputeAcceptanceJSON struct {
AcceptedAt apijson.Field
CardDisputeID apijson.Field
TransactionID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardDisputeAcceptance) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
// If the Card Dispute's status is `rejected`, this will contain details of the
// unsuccessful dispute.
type CardDisputeRejection struct {
// The identifier of the Card Dispute that was rejected.
CardDisputeID string `json:"card_dispute_id,required"`
// Why the Card Dispute was rejected.
Explanation string `json:"explanation,required"`
// The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which
// the Card Dispute was rejected.
RejectedAt time.Time `json:"rejected_at,required" format:"date-time"`
JSON cardDisputeRejectionJSON `json:"-"`
}
// cardDisputeRejectionJSON contains the JSON metadata for the struct
// [CardDisputeRejection]
type cardDisputeRejectionJSON struct {
CardDisputeID apijson.Field
Explanation apijson.Field
RejectedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardDisputeRejection) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
// The results of the Dispute investigation.
type CardDisputeStatus string
const (
// The Card Dispute is pending review.
CardDisputeStatusPendingReviewing CardDisputeStatus = "pending_reviewing"
// The Card Dispute has been accepted and your funds have been returned.
CardDisputeStatusAccepted CardDisputeStatus = "accepted"
// The Card Dispute has been rejected.
CardDisputeStatusRejected CardDisputeStatus = "rejected"
)
// A constant representing the object's type. For this resource it will always be
// `card_dispute`.
type CardDisputeType string
const (
CardDisputeTypeCardDispute CardDisputeType = "card_dispute"
)
type CardDisputeNewParams struct {
// The Transaction you wish to dispute. This Transaction must have a `source_type`
// of `card_settlement`.
DisputedTransactionID param.Field[string] `json:"disputed_transaction_id,required"`
// Why you are disputing this Transaction.
Explanation param.Field[string] `json:"explanation,required"`
}
func (r CardDisputeNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CardDisputeListParams struct {
CreatedAt param.Field[CardDisputeListParamsCreatedAt] `query:"created_at"`
// Return the page of entries after this one.
Cursor param.Field[string] `query:"cursor"`
// Limit the size of the list that is returned. The default (and maximum) is 100
// objects.
Limit param.Field[int64] `query:"limit"`
Status param.Field[CardDisputeListParamsStatus] `query:"status"`
}
// URLQuery serializes [CardDisputeListParams]'s query parameters as `url.Values`.
func (r CardDisputeListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type CardDisputeListParamsCreatedAt struct {
// Return results after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
After param.Field[time.Time] `query:"after" format:"date-time"`
// Return results before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
Before param.Field[time.Time] `query:"before" format:"date-time"`
// Return results on or after this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrAfter param.Field[time.Time] `query:"on_or_after" format:"date-time"`
// Return results on or before this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrBefore param.Field[time.Time] `query:"on_or_before" format:"date-time"`
}
// URLQuery serializes [CardDisputeListParamsCreatedAt]'s query parameters as
// `url.Values`.
func (r CardDisputeListParamsCreatedAt) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type CardDisputeListParamsStatus struct {
// Filter Card Disputes for those with the specified status or statuses. For GET
// requests, this should be encoded as a comma-delimited string, such as
// `?in=one,two,three`.
In param.Field[[]CardDisputeListParamsStatusIn] `query:"in"`
}
// URLQuery serializes [CardDisputeListParamsStatus]'s query parameters as
// `url.Values`.
func (r CardDisputeListParamsStatus) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type CardDisputeListParamsStatusIn string
const (
// The Card Dispute is pending review.
CardDisputeListParamsStatusInPendingReviewing CardDisputeListParamsStatusIn = "pending_reviewing"
// The Card Dispute has been accepted and your funds have been returned.
CardDisputeListParamsStatusInAccepted CardDisputeListParamsStatusIn = "accepted"
// The Card Dispute has been rejected.
CardDisputeListParamsStatusInRejected CardDisputeListParamsStatusIn = "rejected"
)