-
Notifications
You must be signed in to change notification settings - Fork 8
/
gc.go
167 lines (157 loc) · 5.19 KB
/
gc.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
package gocardless
import (
"bytes"
"errors"
"fmt"
)
type Service struct {
BankAuthorisations BankAuthorisationService
BankDetailsLookups BankDetailsLookupService
BillingRequests BillingRequestService
BillingRequestFlows BillingRequestFlowService
BillingRequestTemplates BillingRequestTemplateService
Blocks BlockService
Creditors CreditorService
CreditorBankAccounts CreditorBankAccountService
CurrencyExchangeRates CurrencyExchangeRateService
Customers CustomerService
CustomerBankAccounts CustomerBankAccountService
CustomerNotifications CustomerNotificationService
Events EventService
Exports ExportService
InstalmentSchedules InstalmentScheduleService
Institutions InstitutionService
Logos LogoService
Mandates MandateService
MandateImports MandateImportService
MandateImportEntries MandateImportEntryService
MandatePdfs MandatePdfService
NegativeBalanceLimits NegativeBalanceLimitService
PayerAuthorisations PayerAuthorisationService
PayerThemes PayerThemeService
Payments PaymentService
Payouts PayoutService
PayoutItems PayoutItemService
RedirectFlows RedirectFlowService
Refunds RefundService
ScenarioSimulators ScenarioSimulatorService
SchemeIdentifiers SchemeIdentifierService
Subscriptions SubscriptionService
TaxRates TaxRateService
TransferredMandates TransferredMandateService
VerificationDetails VerificationDetailService
Webhooks WebhookService
}
func init() {
initUserAgent()
}
func New(config Config) (*Service, error) {
if config == nil {
return nil, errors.New("invalid configuration")
}
s := &Service{
BankAuthorisations: &BankAuthorisationServiceImpl{
config: config,
}, BankDetailsLookups: &BankDetailsLookupServiceImpl{
config: config,
}, BillingRequests: &BillingRequestServiceImpl{
config: config,
}, BillingRequestFlows: &BillingRequestFlowServiceImpl{
config: config,
}, BillingRequestTemplates: &BillingRequestTemplateServiceImpl{
config: config,
}, Blocks: &BlockServiceImpl{
config: config,
}, Creditors: &CreditorServiceImpl{
config: config,
}, CreditorBankAccounts: &CreditorBankAccountServiceImpl{
config: config,
}, CurrencyExchangeRates: &CurrencyExchangeRateServiceImpl{
config: config,
}, Customers: &CustomerServiceImpl{
config: config,
}, CustomerBankAccounts: &CustomerBankAccountServiceImpl{
config: config,
}, CustomerNotifications: &CustomerNotificationServiceImpl{
config: config,
}, Events: &EventServiceImpl{
config: config,
}, Exports: &ExportServiceImpl{
config: config,
}, InstalmentSchedules: &InstalmentScheduleServiceImpl{
config: config,
}, Institutions: &InstitutionServiceImpl{
config: config,
}, Logos: &LogoServiceImpl{
config: config,
}, Mandates: &MandateServiceImpl{
config: config,
}, MandateImports: &MandateImportServiceImpl{
config: config,
}, MandateImportEntries: &MandateImportEntryServiceImpl{
config: config,
}, MandatePdfs: &MandatePdfServiceImpl{
config: config,
}, NegativeBalanceLimits: &NegativeBalanceLimitServiceImpl{
config: config,
}, PayerAuthorisations: &PayerAuthorisationServiceImpl{
config: config,
}, PayerThemes: &PayerThemeServiceImpl{
config: config,
}, Payments: &PaymentServiceImpl{
config: config,
}, Payouts: &PayoutServiceImpl{
config: config,
}, PayoutItems: &PayoutItemServiceImpl{
config: config,
}, RedirectFlows: &RedirectFlowServiceImpl{
config: config,
}, Refunds: &RefundServiceImpl{
config: config,
}, ScenarioSimulators: &ScenarioSimulatorServiceImpl{
config: config,
}, SchemeIdentifiers: &SchemeIdentifierServiceImpl{
config: config,
}, Subscriptions: &SubscriptionServiceImpl{
config: config,
}, TaxRates: &TaxRateServiceImpl{
config: config,
}, TransferredMandates: &TransferredMandateServiceImpl{
config: config,
}, VerificationDetails: &VerificationDetailServiceImpl{
config: config,
}, Webhooks: &WebhookServiceImpl{
config: config,
},
}
return s, nil
}
type APIError struct {
Message string `json:"message"`
DocumentationUrl string `json:"documentation_url"`
Type string `json:"type"`
RequestID string `json:"request_id"`
Errors []ValidationError `json:"errors"`
Code int `json:"code"`
}
func (err *APIError) Error() string {
if len(err.Errors) == 0 {
return err.Message
}
var msg bytes.Buffer
fmt.Fprintf(&msg, "%s:", err.Message)
for _, err := range err.Errors {
fmt.Fprintf(&msg, "\n * %s: %s", err.Field, err.Message)
}
return msg.String()
}
type ValidationError struct {
Message string `json:"message"`
Field string `json:"field"`
RequestPointer string `json:"request_pointer"`
Links ErrorLinks `json:"links"`
}
type ErrorLinks struct {
ConflictingResourceID string `json:"conflicting_resource_id"`
CustomerBankAccount string `json:"customer_bank_account"`
}