-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtransaction.go
More file actions
85 lines (72 loc) · 1.98 KB
/
transaction.go
File metadata and controls
85 lines (72 loc) · 1.98 KB
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
package gobitlaunch
import (
"encoding/json"
"fmt"
"time"
)
// Transaction represents a transaction
type Transaction struct {
ID string `json:"id"`
TID string `json:"transactionId"`
Date time.Time `json:"date"`
Address string `json:"address"`
Symbol string `json:"cryptoSymbol"`
AmountUSD float64 `json:"amountUsd"`
AmountCrypto string `json:"amountCrypto"`
Status string `json:"status"`
StatusURL string `json:"statusUrl"`
QrCodeURL string `json:"qrCodeUrl"`
}
// CreateTransactionOptions represents options for create a new transaction
type CreateTransactionOptions struct {
AmountUSD int `json:"amountUsd"`
CryptoSymbol string `json:"cryptoSymbol"`
LightningNetwork bool `json:"lightningNetwork"`
}
// TransactionService manages account API actions
type TransactionService struct {
client *Client
}
// Create transaction
func (ss *TransactionService) Create(opts *CreateTransactionOptions) (*Transaction, error) {
b, err := json.Marshal(opts)
if err != nil {
return nil, err
}
req, err := ss.client.NewRequest("POST", "/transactions", b)
if err != nil {
return nil, err
}
s := Transaction{}
if err := ss.client.DoRequest(req, &s); err != nil {
return nil, err
}
return &s, nil
}
// Show transaction
func (ss *TransactionService) Show(id string) (*Transaction, error) {
req, err := ss.client.NewRequest("GET", "/transactions/"+id, nil)
if err != nil {
return nil, err
}
t := Transaction{}
if err := ss.client.DoRequest(req, &t); err != nil {
return nil, err
}
return &t, nil
}
// List transactions
func (ss *TransactionService) List(page, perPage int) ([]Transaction, error) {
q := fmt.Sprintf("?page=%d&items=%d", page, perPage)
req, err := ss.client.NewRequest("GET", "/transactions"+q, nil)
if err != nil {
return nil, err
}
a := struct {
History []Transaction
}{}
if err := ss.client.DoRequest(req, &a); err != nil {
return nil, err
}
return a.History, nil
}