-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaybill.go
172 lines (154 loc) · 4.79 KB
/
paybill.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
package genesis
import (
"encoding/json"
"fmt"
"github.com/medeirosfalante/bankly-go-sdk"
)
type PayBill struct {
ID int32 `json:"id"`
Protocol string `json:"protocol"`
BarCode string `json:"bar_code"`
CreatedIn int64 `json:"created_in"`
UpdatedIn int64 `json:"updated_in"`
CompanyID int32 `json:"company_id"`
IntegrationID string `json:"integration_id"`
Amount float32 `json:"amount"`
Status string `json:"status"`
Object string `json:"object"`
Digitableline string `json:"digitable_line"`
AuthorizeID string `json:"authorize_id"`
Type string `json:"type"`
DueDate string `json:"dueDate"`
TypeAuthorize int32 `json:"type_authorize"`
ErrorMessage string `json:"error_message"`
DocumentPayer string `json:"document_payer"`
DocumentRecipient string `json:"document_recipient"`
LiquidIn int64 `json:"liquid_in"`
SendIn int64 `json:"send_in"`
Description string `json:"description"`
CorrelationID string `json:"correlation_id"`
}
type PayBillPagesQuery struct {
PerPage int `json:"per_page"`
Page int `json:"page"`
Query *PayBillQuery `json:"query"`
OrderBy *PayBillOrderBy `json:"order_by"`
}
type PayBillQuery struct {
Type string `json:"type"`
Status string `json:"status"`
To int64 `json:"to"`
From int64 `json:"from"`
CompanyID int32 `json:"-"`
}
type PayBillOrderBy struct {
Field string `json:"field"`
Direction string `json:"direction"`
}
type PayBillPagesResponse struct {
Data []*PayBill `json:"data"`
Page int `json:"page"`
Pages int `json:"pages"`
Total int `json:"total"`
}
type PayBillBoleto struct {
Digitableline string `json:"digitable_line"`
BarCode string `json:"bar_code"`
}
type CheckPayBillBoletoResponse struct {
Amount float32 `json:"amount"`
Balance float32 `json:"balance"`
HaveBalance bool `json:"have_balance"`
BoletoObject *bankly.ValidateBillResponse `json:"boleto_object"`
CorrelationID string `json:"correlation_id"`
}
type ConfirmPayBill struct {
Protocol string `json:"protocol"`
Type string `json:"type"`
PaymentCard *ConfirmPayBill `json:"paymentcard"`
}
type ConfirmPayBillCard struct {
}
type CreatePayBillResponse struct {
PayBills *PayBill `json:"billing"`
}
type CreatePayBillCard struct {
Protocol string `json:"protocol"`
Link string `json:"link"`
DueDate string `json:"due_date"`
}
// paybill is a structure manager all about paybill
type PayBillClient struct {
client *Genesis
}
//paybill - Instance de paybill
func (g *Genesis) PayBill() *PayBillClient {
return &PayBillClient{client: g}
}
//Create - create a
func (d *PayBillClient) Create(req PayBillBoleto) (*PayBill, *Error, error) {
data, _ := json.Marshal(req)
var response *PayBill
responseToken, err := d.client.RequestToken()
if err != nil {
return nil, nil, err
}
err, errAPI := d.client.Request(responseToken.AccessToken, "POST", "payment/v1/api/paybill/boleto", data, &response)
if err != nil {
return nil, nil, err
}
if errAPI != nil {
return nil, errAPI, nil
}
return response, nil, nil
}
//Create - paybill
func (d *PayBillClient) Check(req PayBillBoleto) (*CheckPayBillBoletoResponse, *Error, error) {
data, _ := json.Marshal(req)
var response *CheckPayBillBoletoResponse
responseToken, err := d.client.RequestToken()
if err != nil {
return nil, nil, err
}
err, errAPI := d.client.Request(responseToken.AccessToken, "POST", "payment/v1/api/paybill/boleto/check", data, &response)
if err != nil {
return nil, nil, err
}
if errAPI != nil {
return nil, errAPI, nil
}
return response, nil, nil
}
//Get - paybill details
func (d *PayBillClient) Get(token string) (*PayBill, *Error, error) {
var response *PayBill
responseToken, err := d.client.RequestToken()
if err != nil {
return nil, nil, err
}
err, errAPI := d.client.Request(responseToken.AccessToken, "GET", fmt.Sprintf("payment/v1/api/paybill/%s", token), nil, &response)
if err != nil {
return nil, nil, err
}
if errAPI != nil {
return nil, errAPI, nil
}
return response, nil, nil
}
//List - list alls paybills
func (d *PayBillClient) List(req PayBillPagesQuery) (*PayBillPagesResponse, *Error, error) {
data, _ := json.Marshal(req)
var response *PayBillPagesResponse
responseToken, err := d.client.RequestToken()
if err != nil {
return nil, nil, err
}
err, errAPI := d.client.Request(responseToken.AccessToken, "POST", "payment/v1/api/paybills", data, &response)
if err != nil {
return nil, nil, err
}
if errAPI != nil {
return nil, errAPI, nil
}
return response, nil, nil
}