-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
91 lines (83 loc) · 2.7 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
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
package gopaymill
import (
"encoding/json"
)
type Transaction struct {
ID string `json:"id"`
AppId string `json:"app_id"`
CreatedAt int32 `json:"created_at"`
UpdatedAt int32 `json:"updated_at"`
Amount string `json:"amount"`
OriginAmount int32 `json:"origin_amount"`
Status string `json:"status"`
Description string `json:"description"`
Livemode bool `json:"livemode"`
Refunds []interface{} `json:"-"`
Client Client `json:"client"`
Currency string `json:"currency"`
ResponseCode int `json:"response_code"`
ShortID string `json:"short_id"`
IsFraud bool `json:"is_fraud"`
Invoices []interface{} `json:"invoices"`
Items []interface{} `json:"items"`
ShippingAddress interface{} `json:"-"`
BillingAddress interface{} `json:"-"`
Preauthorization interface{} `json:"-"`
Fees []interface{} `json:"-"`
Payment Payment `json:"payemnt"`
MandateReference interface{} `json:"-"`
IsRefundable bool `json:"is_redfundable"`
IsMarkableAsFraud bool `json:"is_markable_as_fraud"`
Token string `json:"-"`
}
type TransactionResponse struct {
Data Transaction `json:"data"`
Mode string `json:"mode"`
}
type TransactionAllResponse struct {
Data []Transaction `json:"data"`
DataCount string `json:"data_count"`
Mode string `json:"mode"`
}
func (t Transaction) Get(p *Paymill) Transaction {
pr := NewRequest()
pr.SetMethod("GET")
pr.SetUri(APIURI + ServiceUri["Transaction"] + "/" + t.ID)
response := p.ClientRequest(&pr)
obj := TransactionResponse{}
json.Unmarshal([]byte(response), &obj)
return obj.Data
}
func (t Transaction) All(p *Paymill) []Transaction {
pr := NewRequest()
pr.SetMethod("GET")
pr.SetUri(APIURI + ServiceUri["Transaction"])
response := p.ClientRequest(&pr)
obj := TransactionAllResponse{}
json.Unmarshal([]byte(response), &obj)
return obj.Data
}
func (t Transaction) New(p *Paymill) Transaction {
pr := NewRequest()
pr.SetMethod("POST")
pr.SetUri(APIURI + ServiceUri["Transaction"])
params := map[string]interface{}{
"amount": t.Amount,
"currency": t.Currency,
"description": t.Description,
}
if len(t.Client.ID) > 0 {
params["client"] = t.Client
}
if len(t.Payment.ID) > 0 {
params["payment"] = t.Payment
}
if len(t.Token) > 0 {
params["token"] = t.Token
}
pr.SetParams(params)
response := p.ClientRequest(&pr)
obj := TransactionResponse{}
json.Unmarshal([]byte(response), &obj)
return obj.Data
}