-
Notifications
You must be signed in to change notification settings - Fork 1
/
payouts.go
executable file
·92 lines (75 loc) · 2.89 KB
/
payouts.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
// Code generated by `gogenitor`. DO NOT EDIT.
package sumup
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
// FinancialPayout is the type definition for a FinancialPayout.
type FinancialPayout struct {
Amount *float64 `json:"amount,omitempty"`
Currency *string `json:"currency,omitempty"`
Date *time.Time `json:"date,omitempty"`
Fee *float64 `json:"fee,omitempty"`
Id *int `json:"id,omitempty"`
Reference *string `json:"reference,omitempty"`
Status *FinancialPayoutStatus `json:"status,omitempty"`
TransactionCode *string `json:"transaction_code,omitempty"`
Type *FinancialPayoutType `json:"type,omitempty"`
}
type FinancialPayoutStatus string
const (
FinancialPayoutStatusFailed FinancialPayoutStatus = "FAILED"
FinancialPayoutStatusSuccessful FinancialPayoutStatus = "SUCCESSFUL"
)
type FinancialPayoutType string
const (
FinancialPayoutTypeBalanceDeduction FinancialPayoutType = "BALANCE_DEDUCTION"
FinancialPayoutTypeChargeBackDeduction FinancialPayoutType = "CHARGE_BACK_DEDUCTION"
FinancialPayoutTypeDdReturnDeduction FinancialPayoutType = "DD_RETURN_DEDUCTION"
FinancialPayoutTypePayout FinancialPayoutType = "PAYOUT"
FinancialPayoutTypeRefundDeduction FinancialPayoutType = "REFUND_DEDUCTION"
)
// FinancialPayouts is the type definition for a FinancialPayouts.
type FinancialPayouts []FinancialPayout
// ListPayoutsParams are query parameters for ListPayouts
type ListPayoutsParams struct {
EndDate time.Time `json:"end_date"`
Format *string `json:"format,omitempty"`
Limit *int `json:"limit,omitempty"`
Order *string `json:"order,omitempty"`
StartDate time.Time `json:"start_date"`
}
type PayoutsService service
// List: List payouts
// Lists ordered payouts for the merchant profile.
func (s *PayoutsService) List(ctx context.Context, params ListPayoutsParams) (*FinancialPayouts, error) {
path := fmt.Sprintf("/v0.1/me/financials/payouts")
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 500 {
return nil, fmt.Errorf("invalid response: %d - %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
dec := json.NewDecoder(resp.Body)
if resp.StatusCode >= 400 {
var apiErr APIError
if err := dec.Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
}
var v FinancialPayouts
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
}