generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
payments.go
88 lines (79 loc) · 3.23 KB
/
payments.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
package coinpayments
// CreatePaymentResponse is the api response after creating a payment
type CreatePaymentResponse struct {
Error string `json:"error"`
Result CreatePaymentResult `json:"result"`
}
// CreatePaymentResult is the result of creating a payment
type CreatePaymentResult struct {
Amount string `json:"amount"`
Address string `json:"address"`
DestTag string `json:"dest_tag"`
TransactionID string `json:"txn_id"`
ConfirmsNeeded string `json:"confirms_needed"`
Timeout int `json:"timeout"`
CheckoutURL string `json:"checkout_url"`
StatusURL string `json:"status_url"`
QrcodeURL string `json:"qrcode_url"`
}
// CreatePaymentRequest are the parameters for creating a payment
type CreatePaymentRequest struct {
Amount string `json:"amount"`
OriginalCurrency string `json:"currency1"`
SendingCurrency string `json:"currency2"`
BuyerEmail string `json:"buyer_email"`
}
// PaymentIpnRequest is the response we expect back from the server when the command is "api"
type PaymentIpnRequest struct {
Status string `form:"status"`
StatusText string `form:"status_text"`
TxnID string `form:"txn_id"`
Currency1 string `form:"currency1"`
Currency2 string `form:"currency2"`
Amount1 string `form:"amount1"`
Amount2 string `form:"amount2"`
Fee string `form:"fee"`
IpnType string `form:"ipn_type"`
BuyerName string `form:"buyer_name"`
Email string `form:"email"`
ItemName string `form:"item_name"`
ItemNumber string `form:"item_number"`
Invoice string `form:"invoice"`
Custom string `form:"custom"`
ReceivedAmount string `form:"received_amount"`
ReceivedConfirms string `form:"received_confirms"`
}
// IsWaiting returns true when the payment is in the waiting state
func (request PaymentIpnRequest) IsWaiting() bool {
return request.Status == "0" || request.Status == "1" || request.Status == "2" || request.Status == "3"
}
// IsComplete returns true with the payment is completed
func (request PaymentIpnRequest) IsComplete() bool {
return request.Status == "100"
}
// IsFailed returns ttrue when the payment is failed
func (request PaymentIpnRequest) IsFailed() bool {
return request.Status == "-2" || request.Status == "-1"
}
// PaymentTransactionResponse is the response gotten when we fetch a transaction
type PaymentTransactionResponse struct {
Error string `json:"error"`
Result PaymentTransaction `json:"result"`
}
// PaymentTransaction is the transaction details
type PaymentTransaction struct {
TimeCreated int `json:"time_created"`
TimeExpires int `json:"time_expires"`
Status int `json:"status"`
StatusText string `json:"status_text"`
Type string `json:"type"`
Coin string `json:"coin"`
Amount int `json:"amount"`
AmountFormatted string `json:"amountf"`
Received int `json:"received"`
ReceivedFormatted string `json:"receivedf"`
ReceiveConfirms int `json:"recv_confirms"`
PaymentAddress string `json:"payment_address"`
TimeCompleted int `json:"time_completed"`
SenderIP string `json:"sender_ip"`
}