-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcharges.go
120 lines (111 loc) · 4.44 KB
/
charges.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
package coinbase
import "time"
// ACharge is a class hosted inside the APIClient providing methods about charge
type ACharge struct {
Api *APIClient
}
// APIChargeData is the golang struct equivalent of the Charge resource. It's findable inside APICharge object
type APIChargeData struct {
Id string `json:"id,omitempty"`
Ressource string `json:"ressource,omitempty"`
Code string `json:"code,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Logo_url string `json:"logo_url,omitempty"`
Redirect_url string `json:"redirect_url,omitempty"`
Hosted_url string `json:"Hosted_url,omitempty"`
Created_at *time.Time `json:"created_at,omitempty"`
Updated_at *time.Time `json:"updated_at,omitempty"`
Confirmed_at *time.Time `json:"confirmed_at,omitempty"`
Checkout struct {
Id string `json:"id,omitempty"`
} `json:"checkout,omitempty"`
Timeline []struct {
Time *time.Time `json:"id,omitempty"`
Status string `json:"status,omitempty"`
Context string `json:"context,omitempty"`
} `json:"timeline,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Pricing_type string `json:"pricing_type,omitempty"`
Pricing struct {
Local Money `json:"local,omitempty"`
Bitcoin Money `json:"bitcoin,omitempty"`
Bitcoincash Money `json:"bitcoincash,omitempty"`
Ethereum Money `json:"ethereum,omitempty"`
Litecoin Money `json:"litecoin,omitempty"`
} `json:"pricing,omitempty"`
Payments []struct {
Network string`json:"network,omitempty"`
Transaction_id string `json:"transaction_id,omitempty"`
Status string `json:"status,omitempty"`
Value struct {
Local struct {
Amount string `json:"amount,omitempty"`
Currency string `json:"currency,omitempty"`
}
Crypto struct {
Amount string `json:"amount,omitempty"`
Currency string `json:"currency,omitempty"`
}`json:"crypto,omitempty"`
} `json:"value,omitempty"`
Block struct {
Height int `json:"height,omitempty"`
Hash string `json:"hash,omitempty"`
Confirmations_accumulated int `json:"confirmations_accumulated ,omitempty"`
Confirmations_required int `json:"confirmations_required,omitempty"`
} `json:"block,omitempty"`
} `json:"payments,omitempty"`
Addresses struct {
Bitcoin string `json:"bitcoin,omitempty"`
Bitcoincash string `json:"bitcoincash,omitempty"`
Ethereum string `json:"ethereum,omitempty"`
Litecoin string `json:"litecoin,omitempty"`
} `json:"addresses,omitempty"`
Local_price Money `json:"local_price,omitempty"`
}
// APICharge is the object API object returned by the api routes.
type APICharge struct {
father *ACharge
Data APIChargeData `json:"data,omitempty"`
Errors []APIError `json:"errors,omitempty"`
}
// APICharges is the object API object filled with a list of APICharge object alongside of Pagination information and a list of Errors.
type APICharges struct {
Pagination APIPagination `json:"pagination,omitempty"`
Charges []APICharge `json:"data,omitempty"`
Errors []APIError `json:"errors,omitempty"`
}
// APICharge is the golang struct equivalent of the List charges routes
type APIChargesRequest struct {
Pagination APIPagination `json:"pagination,omitempty"`
Data []APIChargeData `json:"data,omitempty"`
Errors []APIError `json:"errors,omitempty"`
}
// Get provides the APICharge instance of the given charge id.
func (a *ACharge) Get(id string) (charge APICharge, err error) {
err = a.Api.Fetch("GET", "/charges/"+id, nil, &charge)
charge.father = a
return
}
// Refresh will update attributes and all nested data by making a fresh GET request to the relevant API endpoint.
func (a *APICharge) Refresh() (err error) {
err = a.father.Api.Fetch("GET", "/charges/"+a.Data.Id, nil, &a.Data)
return
}
// List create a APICharges object with a list of APICharge instance.
func (a *ACharge) List() (charges APICharges, err error) {
temp := APIChargesRequest{}
err = a.Api.Fetch("GET", "/charges/", nil, &temp)
charges.Pagination = temp.Pagination
charges.Errors = temp.Errors
for _, data := range temp.Data {
charges.Charges = append(charges.Charges, APICharge{father: a, Data: data, Errors: temp.Errors})
}
return
}
// Create a new charge and return his golang instance
func (a *ACharge) Create(data interface{}) (charge APICharge, err error) {
err = a.Api.Fetch("POST", "/charges/", data, &charge)
charge.father = a
return
}