-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
59 lines (53 loc) · 1.82 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Package contractus implements the transaction struct and its methods.
package contractus
import (
"fmt"
"time"
)
// TransactionResponse have the fields that represent the transactions API response.
type TransactionResponse struct {
Transactions []Transaction `json:"transactions"`
Total int `json:"total"`
}
// BalanceResponse have the fields that represent the seller balance API response.
type BalanceResponse struct {
Balance int64 `json:"balance"`
SellerName string `json:"seller_name"`
}
// Transaction have the fields that represent a single transaction.
type Transaction struct {
Email string `json:"email" db:"email"`
Type int `json:"type" db:"type"`
Date time.Time `json:"date" db:"date"`
ProductDescription string `json:"product_description" db:"product_description"`
ProductPriceCents int64 `json:"product_price_cents" db:"product_price_cents"`
SellerName string `json:"seller_name" db:"seller_name"`
SellerType string `json:"seller_type" db:"seller_type"`
Action string `json:"action" db:"action"`
}
// ConvertType convert the transaction type from his code to the string representation.
func (t *Transaction) ConvertType() (string, error) {
switch t.Type {
case 1:
return "venda produtor", nil
case 2:
return "venda afiliado", nil
case 3:
return "comissao paga", nil
case 4:
return "comissao recebida", nil
default:
return "", fmt.Errorf("invalid transaction type: %d", t.Type)
}
}
// ConvertSellerType convert the seller type from his code to the string representation.
func (t *Transaction) ConvertSellerType() (string, error) {
switch t.Type {
case 1, 3:
return "producer", nil
case 2, 4:
return "affiliate", nil
default:
return "", fmt.Errorf("invalid seller type: %d", t.Type)
}
}