-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjuice.go
202 lines (178 loc) · 6.76 KB
/
juice.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
package juice
import (
"fmt"
"io/ioutil"
"net/http"
"time"
)
type Account struct {
BusinessAddress string `json:"business_address"`
BusinessName string `json:"business_name"`
Chain string `json:"chain"`
ContactNumber string `json:"contact_number"`
Country string `json:"country"`
Domain string `json:"domain"`
Email string `json:"email"`
FirstName string `json:"first_name"`
FloatCurrencies []string `json:"float_currencies"`
Id string `json:"id"`
LastName string `json:"last_name"`
RegistrationNumber string `json:"registration_number"`
UsdcAddress UsdcAddress `json:"usdc_address"`
}
type UsdcAddress struct {
Address string `json:"address"`
Chain string `json:"chain"`
Currency string `json:"currency"`
}
type User struct {
Address UserAddress `json:"address"`
Archived bool `json:"archived"`
CardIntegratorId string `json:"card_integrator_id"`
Email string `json:"email"`
FirstName string `json:"first_name"`
Id string `json:"id"`
IdNumber string `json:"id_number"`
IdType string `json:"id_type"`
LastName string `json:"last_name"`
PhoneNumber string `json:"phone_number"`
Verified bool `json:"verified"`
}
type UserAddress struct {
City string `json:"city"`
Country string `json:"country"`
Line1 string `json:"line1"`
Line2 interface{} `json:"line2"`
State interface{} `json:"state"`
ZipCode string `json:"zip_code"`
}
type Card struct {
Balance int `json:"balance"`
BusinessId string `json:"business_id"`
CardName string `json:"card_name"`
CardNumber string `json:"card_number"`
CardType string `json:"card_type"`
Currency string `json:"currency"`
Cvv2 string `json:"cvv2"`
DesignType string `json:"design_type"`
Expiry time.Time `json:"expiry"`
Id string `json:"id"`
Provider string `json:"provider"`
SingleUse bool `json:"single_use"`
Status string `json:"status"`
UserId string `json:"user_id"`
Valid string `json:"valid"`
}
type Transaction struct {
Amount int `json:"amount"`
CardBalanceAfter int `json:"card_balance_after"`
CardBalanceBefore int `json:"card_balance_before"`
ConversionRate int `json:"conversion_rate"`
CreatedAt time.Time `json:"created_at"`
Currency string `json:"currency"`
Id string `json:"id"`
Narrative interface{} `json:"narrative"`
Type string `json:"type"`
}
// RegisterAccount creates a card integrator account
func (cl *Client) RegisterAccount(data RegisterAccountData) (AccountResp, error) {
var res AccountResp
err := cl.post("/card-integrators/register-integrator", data, &res)
return res, err
}
// UpdateAccount updates the card integrator account
func (cl *Client) UpdateAccount(webhook, businessAddress, domain string) (AccountResp, error) {
var res AccountResp
err := cl.patch("/card-integrators/update", &UpdateAccountData{WebhookUrl: webhook, BusinessAddress: businessAddress, Domain: domain}, &res)
return res, err
}
// TopUpFloat allows an integrator to top up float balance.
//This endpoint is only available in the sandbox environment.
func (cl *Client) TopUpFloat(amount int) (Resp, error) {
var res Resp
err := cl.patch("/card-integrators/top-up-float", &TopUpFloatData{amount}, &res)
return res, err
}
// GetFloat allows an integrator get their float balance
func (cl *Client) GetFloat() (BalanceResp, error) {
var res BalanceResp
err := cl.get("/card-integrators/float", nil, &res)
return res, err
}
// RegisterUser creates an account for user requesting a card
func (cl *Client) RegisterUser(data RegisterUserData, accountId string) (UserResp, error) {
var res UserResp
err := cl.post(fmt.Sprintf("/card-integrators/%s/register-user", accountId), data, &res)
return res, err
}
// ListUsers gets list of card users attached to an account
func (cl *Client) ListUsers(limit, page int) (UsersResp, error) {
var res UsersResp
err := cl.get("/card-integrators/card-users", Param{Limit: limit, Page: page}, &res)
return res, err
}
// CreateCard creates a card for a user
func (cl *Client) CreateCard(data CreateCardData) (CreateCardResp, error) {
var res CreateCardResp
err := cl.post("/cards/create-virtual-card", data, &res)
return res, err
}
// ListCards gets a list of cards of a user
func (cl *Client) ListCards(limit, page int, userId string) ([]CardResp, error) {
var res []CardResp
err := cl.get(fmt.Sprintf("/cards?user_id=%s&limit=%d&page=%d", userId, limit, page), nil, &res)
return res, err
}
// GetCard gets a particular card
func (cl *Client) GetCard(cardId string) (CardResp, error) {
var res CardResp
err := cl.get(fmt.Sprintf("/cards/%s", cardId), nil, &res)
return res, err
}
// CreditCard top-up a card for a user
func (cl *Client) CreditCard(data PaymentData) (CardResp, error) {
var res CardResp
err := cl.patch("/cards/credit/balance", data, &res)
return res, err
}
// DebitCard debits a card for a user
func (cl *Client) DebitCard(data PaymentData) (CardResp, error) {
var res CardResp
err := cl.patch("/cards/debit/balance", data, &res)
return res, err
}
// FreezeCard freezes a card for a user
func (cl *Client) FreezeCard(cardId string) (CardResp, error) {
var res CardResp
err := cl.patch(fmt.Sprintf("/cards/%s/freeze", cardId), nil, &res)
return res, err
}
// UnfreezeCard unfreezes a card for a user
func (cl *Client) UnfreezeCard(cardId string) (CardResp, error) {
var res CardResp
err := cl.patch(fmt.Sprintf("/cards/%s/unfreeze", cardId), nil, &res)
return res, err
}
// ListTransactions gets paginated transactions for the given card
func (cl *Client) ListTransactions(cardId string, param Param) (TransactionsResp, error) {
var res TransactionsResp
err := cl.get(fmt.Sprintf("/cards/%s/transactions", cardId), param, &res)
return res, err
}
// GetTransaction gets a particular transaction
func (cl *Client) GetTransaction(trxId string) (TransactionResp, error) {
var res TransactionResp
err := cl.get(fmt.Sprintf("/cards/transaction/%s", trxId), nil, &res)
return res, err
}
//MockTransaction mocks card transaction. This endpoint is only available in the sandbox environment.
func (cl *Client) MockTransaction(data MockTransactionData, cardId string) (Resp, error) {
var res Resp
err := cl.post(fmt.Sprintf("/cards/%s/mock-transaction", cardId), data, &res)
return res, err
}
func (cl Client) Health() (string, error) {
resp, err := http.Get(fmt.Sprintf("%s/health/live", cl.baseURL))
body, _ := ioutil.ReadAll(resp.Body)
return string(body), err
}