-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefund.go
311 lines (288 loc) · 13.7 KB
/
refund.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package dodopayments
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/dodopayments/dodopayments-go/internal/apijson"
"github.com/dodopayments/dodopayments-go/internal/apiquery"
"github.com/dodopayments/dodopayments-go/internal/param"
"github.com/dodopayments/dodopayments-go/internal/requestconfig"
"github.com/dodopayments/dodopayments-go/option"
"github.com/dodopayments/dodopayments-go/packages/pagination"
)
// RefundService contains methods and other services that help with interacting
// with the Dodo Payments 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 [NewRefundService] method instead.
type RefundService struct {
Options []option.RequestOption
}
// NewRefundService 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 NewRefundService(opts ...option.RequestOption) (r *RefundService) {
r = &RefundService{}
r.Options = opts
return
}
func (r *RefundService) New(ctx context.Context, body RefundNewParams, opts ...option.RequestOption) (res *Refund, err error) {
opts = append(r.Options[:], opts...)
path := "refunds"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
func (r *RefundService) Get(ctx context.Context, refundID string, opts ...option.RequestOption) (res *Refund, err error) {
opts = append(r.Options[:], opts...)
if refundID == "" {
err = errors.New("missing required refund_id parameter")
return
}
path := fmt.Sprintf("refunds/%s", refundID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
func (r *RefundService) List(ctx context.Context, query RefundListParams, opts ...option.RequestOption) (res *pagination.DefaultPageNumberPagination[Refund], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "refunds"
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
}
func (r *RefundService) ListAutoPaging(ctx context.Context, query RefundListParams, opts ...option.RequestOption) *pagination.DefaultPageNumberPaginationAutoPager[Refund] {
return pagination.NewDefaultPageNumberPaginationAutoPager(r.List(ctx, query, opts...))
}
type Refund struct {
BusinessID string `json:"business_id,required"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
PaymentID string `json:"payment_id,required"`
RefundID string `json:"refund_id,required"`
Status RefundStatus `json:"status,required"`
Amount int64 `json:"amount,nullable"`
Currency RefundCurrency `json:"currency,nullable"`
Reason string `json:"reason,nullable"`
JSON refundJSON `json:"-"`
}
// refundJSON contains the JSON metadata for the struct [Refund]
type refundJSON struct {
BusinessID apijson.Field
CreatedAt apijson.Field
PaymentID apijson.Field
RefundID apijson.Field
Status apijson.Field
Amount apijson.Field
Currency apijson.Field
Reason apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Refund) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r refundJSON) RawJSON() string {
return r.raw
}
type RefundStatus string
const (
RefundStatusSucceeded RefundStatus = "succeeded"
RefundStatusFailed RefundStatus = "failed"
RefundStatusPending RefundStatus = "pending"
RefundStatusReview RefundStatus = "review"
)
func (r RefundStatus) IsKnown() bool {
switch r {
case RefundStatusSucceeded, RefundStatusFailed, RefundStatusPending, RefundStatusReview:
return true
}
return false
}
type RefundCurrency string
const (
RefundCurrencyAed RefundCurrency = "AED"
RefundCurrencyAll RefundCurrency = "ALL"
RefundCurrencyAmd RefundCurrency = "AMD"
RefundCurrencyAng RefundCurrency = "ANG"
RefundCurrencyAoa RefundCurrency = "AOA"
RefundCurrencyArs RefundCurrency = "ARS"
RefundCurrencyAud RefundCurrency = "AUD"
RefundCurrencyAwg RefundCurrency = "AWG"
RefundCurrencyAzn RefundCurrency = "AZN"
RefundCurrencyBam RefundCurrency = "BAM"
RefundCurrencyBbd RefundCurrency = "BBD"
RefundCurrencyBdt RefundCurrency = "BDT"
RefundCurrencyBgn RefundCurrency = "BGN"
RefundCurrencyBhd RefundCurrency = "BHD"
RefundCurrencyBif RefundCurrency = "BIF"
RefundCurrencyBmd RefundCurrency = "BMD"
RefundCurrencyBnd RefundCurrency = "BND"
RefundCurrencyBob RefundCurrency = "BOB"
RefundCurrencyBrl RefundCurrency = "BRL"
RefundCurrencyBsd RefundCurrency = "BSD"
RefundCurrencyBwp RefundCurrency = "BWP"
RefundCurrencyByn RefundCurrency = "BYN"
RefundCurrencyBzd RefundCurrency = "BZD"
RefundCurrencyCad RefundCurrency = "CAD"
RefundCurrencyChf RefundCurrency = "CHF"
RefundCurrencyClp RefundCurrency = "CLP"
RefundCurrencyCny RefundCurrency = "CNY"
RefundCurrencyCop RefundCurrency = "COP"
RefundCurrencyCrc RefundCurrency = "CRC"
RefundCurrencyCup RefundCurrency = "CUP"
RefundCurrencyCve RefundCurrency = "CVE"
RefundCurrencyCzk RefundCurrency = "CZK"
RefundCurrencyDjf RefundCurrency = "DJF"
RefundCurrencyDkk RefundCurrency = "DKK"
RefundCurrencyDop RefundCurrency = "DOP"
RefundCurrencyDzd RefundCurrency = "DZD"
RefundCurrencyEgp RefundCurrency = "EGP"
RefundCurrencyEtb RefundCurrency = "ETB"
RefundCurrencyEur RefundCurrency = "EUR"
RefundCurrencyFjd RefundCurrency = "FJD"
RefundCurrencyFkp RefundCurrency = "FKP"
RefundCurrencyGbp RefundCurrency = "GBP"
RefundCurrencyGel RefundCurrency = "GEL"
RefundCurrencyGhs RefundCurrency = "GHS"
RefundCurrencyGip RefundCurrency = "GIP"
RefundCurrencyGmd RefundCurrency = "GMD"
RefundCurrencyGnf RefundCurrency = "GNF"
RefundCurrencyGtq RefundCurrency = "GTQ"
RefundCurrencyGyd RefundCurrency = "GYD"
RefundCurrencyHkd RefundCurrency = "HKD"
RefundCurrencyHnl RefundCurrency = "HNL"
RefundCurrencyHrk RefundCurrency = "HRK"
RefundCurrencyHtg RefundCurrency = "HTG"
RefundCurrencyHuf RefundCurrency = "HUF"
RefundCurrencyIdr RefundCurrency = "IDR"
RefundCurrencyIls RefundCurrency = "ILS"
RefundCurrencyInr RefundCurrency = "INR"
RefundCurrencyIqd RefundCurrency = "IQD"
RefundCurrencyJmd RefundCurrency = "JMD"
RefundCurrencyJod RefundCurrency = "JOD"
RefundCurrencyJpy RefundCurrency = "JPY"
RefundCurrencyKes RefundCurrency = "KES"
RefundCurrencyKgs RefundCurrency = "KGS"
RefundCurrencyKhr RefundCurrency = "KHR"
RefundCurrencyKmf RefundCurrency = "KMF"
RefundCurrencyKrw RefundCurrency = "KRW"
RefundCurrencyKwd RefundCurrency = "KWD"
RefundCurrencyKyd RefundCurrency = "KYD"
RefundCurrencyKzt RefundCurrency = "KZT"
RefundCurrencyLak RefundCurrency = "LAK"
RefundCurrencyLbp RefundCurrency = "LBP"
RefundCurrencyLkr RefundCurrency = "LKR"
RefundCurrencyLrd RefundCurrency = "LRD"
RefundCurrencyLsl RefundCurrency = "LSL"
RefundCurrencyLyd RefundCurrency = "LYD"
RefundCurrencyMad RefundCurrency = "MAD"
RefundCurrencyMdl RefundCurrency = "MDL"
RefundCurrencyMga RefundCurrency = "MGA"
RefundCurrencyMkd RefundCurrency = "MKD"
RefundCurrencyMmk RefundCurrency = "MMK"
RefundCurrencyMnt RefundCurrency = "MNT"
RefundCurrencyMop RefundCurrency = "MOP"
RefundCurrencyMru RefundCurrency = "MRU"
RefundCurrencyMur RefundCurrency = "MUR"
RefundCurrencyMvr RefundCurrency = "MVR"
RefundCurrencyMwk RefundCurrency = "MWK"
RefundCurrencyMxn RefundCurrency = "MXN"
RefundCurrencyMyr RefundCurrency = "MYR"
RefundCurrencyMzn RefundCurrency = "MZN"
RefundCurrencyNad RefundCurrency = "NAD"
RefundCurrencyNgn RefundCurrency = "NGN"
RefundCurrencyNio RefundCurrency = "NIO"
RefundCurrencyNok RefundCurrency = "NOK"
RefundCurrencyNpr RefundCurrency = "NPR"
RefundCurrencyNzd RefundCurrency = "NZD"
RefundCurrencyOmr RefundCurrency = "OMR"
RefundCurrencyPab RefundCurrency = "PAB"
RefundCurrencyPen RefundCurrency = "PEN"
RefundCurrencyPgk RefundCurrency = "PGK"
RefundCurrencyPhp RefundCurrency = "PHP"
RefundCurrencyPkr RefundCurrency = "PKR"
RefundCurrencyPln RefundCurrency = "PLN"
RefundCurrencyPyg RefundCurrency = "PYG"
RefundCurrencyQar RefundCurrency = "QAR"
RefundCurrencyRon RefundCurrency = "RON"
RefundCurrencyRsd RefundCurrency = "RSD"
RefundCurrencyRub RefundCurrency = "RUB"
RefundCurrencyRwf RefundCurrency = "RWF"
RefundCurrencySar RefundCurrency = "SAR"
RefundCurrencySbd RefundCurrency = "SBD"
RefundCurrencyScr RefundCurrency = "SCR"
RefundCurrencySek RefundCurrency = "SEK"
RefundCurrencySgd RefundCurrency = "SGD"
RefundCurrencyShp RefundCurrency = "SHP"
RefundCurrencySle RefundCurrency = "SLE"
RefundCurrencySll RefundCurrency = "SLL"
RefundCurrencySos RefundCurrency = "SOS"
RefundCurrencySrd RefundCurrency = "SRD"
RefundCurrencySsp RefundCurrency = "SSP"
RefundCurrencyStn RefundCurrency = "STN"
RefundCurrencySvc RefundCurrency = "SVC"
RefundCurrencySzl RefundCurrency = "SZL"
RefundCurrencyThb RefundCurrency = "THB"
RefundCurrencyTnd RefundCurrency = "TND"
RefundCurrencyTop RefundCurrency = "TOP"
RefundCurrencyTry RefundCurrency = "TRY"
RefundCurrencyTtd RefundCurrency = "TTD"
RefundCurrencyTwd RefundCurrency = "TWD"
RefundCurrencyTzs RefundCurrency = "TZS"
RefundCurrencyUah RefundCurrency = "UAH"
RefundCurrencyUgx RefundCurrency = "UGX"
RefundCurrencyUsd RefundCurrency = "USD"
RefundCurrencyUyu RefundCurrency = "UYU"
RefundCurrencyUzs RefundCurrency = "UZS"
RefundCurrencyVes RefundCurrency = "VES"
RefundCurrencyVnd RefundCurrency = "VND"
RefundCurrencyVuv RefundCurrency = "VUV"
RefundCurrencyWst RefundCurrency = "WST"
RefundCurrencyXaf RefundCurrency = "XAF"
RefundCurrencyXcd RefundCurrency = "XCD"
RefundCurrencyXof RefundCurrency = "XOF"
RefundCurrencyXpf RefundCurrency = "XPF"
RefundCurrencyYer RefundCurrency = "YER"
RefundCurrencyZar RefundCurrency = "ZAR"
RefundCurrencyZmw RefundCurrency = "ZMW"
)
func (r RefundCurrency) IsKnown() bool {
switch r {
case RefundCurrencyAed, RefundCurrencyAll, RefundCurrencyAmd, RefundCurrencyAng, RefundCurrencyAoa, RefundCurrencyArs, RefundCurrencyAud, RefundCurrencyAwg, RefundCurrencyAzn, RefundCurrencyBam, RefundCurrencyBbd, RefundCurrencyBdt, RefundCurrencyBgn, RefundCurrencyBhd, RefundCurrencyBif, RefundCurrencyBmd, RefundCurrencyBnd, RefundCurrencyBob, RefundCurrencyBrl, RefundCurrencyBsd, RefundCurrencyBwp, RefundCurrencyByn, RefundCurrencyBzd, RefundCurrencyCad, RefundCurrencyChf, RefundCurrencyClp, RefundCurrencyCny, RefundCurrencyCop, RefundCurrencyCrc, RefundCurrencyCup, RefundCurrencyCve, RefundCurrencyCzk, RefundCurrencyDjf, RefundCurrencyDkk, RefundCurrencyDop, RefundCurrencyDzd, RefundCurrencyEgp, RefundCurrencyEtb, RefundCurrencyEur, RefundCurrencyFjd, RefundCurrencyFkp, RefundCurrencyGbp, RefundCurrencyGel, RefundCurrencyGhs, RefundCurrencyGip, RefundCurrencyGmd, RefundCurrencyGnf, RefundCurrencyGtq, RefundCurrencyGyd, RefundCurrencyHkd, RefundCurrencyHnl, RefundCurrencyHrk, RefundCurrencyHtg, RefundCurrencyHuf, RefundCurrencyIdr, RefundCurrencyIls, RefundCurrencyInr, RefundCurrencyIqd, RefundCurrencyJmd, RefundCurrencyJod, RefundCurrencyJpy, RefundCurrencyKes, RefundCurrencyKgs, RefundCurrencyKhr, RefundCurrencyKmf, RefundCurrencyKrw, RefundCurrencyKwd, RefundCurrencyKyd, RefundCurrencyKzt, RefundCurrencyLak, RefundCurrencyLbp, RefundCurrencyLkr, RefundCurrencyLrd, RefundCurrencyLsl, RefundCurrencyLyd, RefundCurrencyMad, RefundCurrencyMdl, RefundCurrencyMga, RefundCurrencyMkd, RefundCurrencyMmk, RefundCurrencyMnt, RefundCurrencyMop, RefundCurrencyMru, RefundCurrencyMur, RefundCurrencyMvr, RefundCurrencyMwk, RefundCurrencyMxn, RefundCurrencyMyr, RefundCurrencyMzn, RefundCurrencyNad, RefundCurrencyNgn, RefundCurrencyNio, RefundCurrencyNok, RefundCurrencyNpr, RefundCurrencyNzd, RefundCurrencyOmr, RefundCurrencyPab, RefundCurrencyPen, RefundCurrencyPgk, RefundCurrencyPhp, RefundCurrencyPkr, RefundCurrencyPln, RefundCurrencyPyg, RefundCurrencyQar, RefundCurrencyRon, RefundCurrencyRsd, RefundCurrencyRub, RefundCurrencyRwf, RefundCurrencySar, RefundCurrencySbd, RefundCurrencyScr, RefundCurrencySek, RefundCurrencySgd, RefundCurrencyShp, RefundCurrencySle, RefundCurrencySll, RefundCurrencySos, RefundCurrencySrd, RefundCurrencySsp, RefundCurrencyStn, RefundCurrencySvc, RefundCurrencySzl, RefundCurrencyThb, RefundCurrencyTnd, RefundCurrencyTop, RefundCurrencyTry, RefundCurrencyTtd, RefundCurrencyTwd, RefundCurrencyTzs, RefundCurrencyUah, RefundCurrencyUgx, RefundCurrencyUsd, RefundCurrencyUyu, RefundCurrencyUzs, RefundCurrencyVes, RefundCurrencyVnd, RefundCurrencyVuv, RefundCurrencyWst, RefundCurrencyXaf, RefundCurrencyXcd, RefundCurrencyXof, RefundCurrencyXpf, RefundCurrencyYer, RefundCurrencyZar, RefundCurrencyZmw:
return true
}
return false
}
type RefundNewParams struct {
PaymentID param.Field[string] `json:"payment_id,required"`
Amount param.Field[int64] `json:"amount"`
Reason param.Field[string] `json:"reason"`
}
func (r RefundNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type RefundListParams struct {
// Page number default is 0
PageNumber param.Field[int64] `query:"page_number"`
// Page size default is 10 max is 100
PageSize param.Field[int64] `query:"page_size"`
}
// URLQuery serializes [RefundListParams]'s query parameters as `url.Values`.
func (r RefundListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}