-
Notifications
You must be signed in to change notification settings - Fork 3
/
transaction.go
42 lines (37 loc) · 1.41 KB
/
transaction.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
package whmcs
import (
"errors"
)
// Various error responses
var (
ErrTransactionAmountsEmpty = errors.New("Transaction amounts empty")
ErrTransactionPaymentMethodEmpty = errors.New("Transaction payment method empty")
ErrTransactionDateEmpty = errors.New("Transaction date empty")
)
// Transaction is a struct containing parameters which can be sent to create a new transaction.
type Transaction struct {
// Required fields
AmountIn float64 `json:"amountin,string" xml:"amountin"`
AmountOut float64 `json:"amountout,string" xml:"amountout"`
PaymentMethod string `json:"paymentmethod" xml:"paymentmethod"`
Date Date `json:"date" xml:"date"`
// Optional fields
UserID int64 `json:"userid,string,omitempty" xml:"userid,omitempty"`
InvoiceID int64 `json:"invoiceid,string,omitempty" xml:"invoiceid,omitempty"`
Description string `json:"description,omitempty" xml:"description,omitempty"`
Fees float64 `json:"fees,string,omitempty" xml:"fees,omitempty"`
TransID string `json:"transid,omitempty" xml:"transid,omitempty"`
Credit bool `json:"credit,string,omitempty" xml:"credit,omitempty"`
}
func (t *Transaction) Error() error {
if t.AmountIn == 0 && t.AmountOut == 0 {
return ErrTransactionAmountsEmpty
}
if t.PaymentMethod == "" {
return ErrTransactionPaymentMethodEmpty
}
if t.Date.Time().IsZero() {
return ErrTransactionDateEmpty
}
return nil
}