-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment.go
75 lines (67 loc) · 2.3 KB
/
payment.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
package gopaymill
import (
"encoding/json"
)
type Payment struct {
ID string `json:"id"`
AppId string `json:"app_id"`
CreatedAt int `json:"created_at"`
UpdatedAt int `json:"updated_at"`
PaymentType string `json:"type"`
Client interface{} `json:"client"`
IsRecurring bool `json:"is_recurring"`
IsUsableForPreauthorization bool `json:"is_usable_for_preauthorization"`
CardType string `json:"card_type"`
Country string `json:"country"`
ExpireMonth string `json:"expire_month"`
ExpireYear string `json:"expire_year"`
CardHolder string `json:"card_holder"`
Last4 string `json:"last4"`
Code string `json:"code"`
Account string `json:"account"`
Holder string `json:"holder"`
Iban string `json:"iban"`
Bic string `json:"bic"`
Token string `json:"-"`
}
type PaymentResponse struct {
Data Payment `json:"data"`
Mode string `json:"mode"`
}
type PaymentAllResponse struct {
Data []Payment `json:"data"`
DataCount string `json:"data_count"`
Mode string `json:"mode"`
}
func (py Payment) Get(p *Paymill) Payment {
pr := NewRequest()
pr.SetMethod("GET")
pr.SetUri(APIURI + ServiceUri["Payment"] + "/" + py.ID)
response := p.ClientRequest(&pr)
obj := PaymentResponse{}
json.Unmarshal([]byte(response), &obj)
return obj.Data
}
func (py Payment) All(p *Paymill) []Payment {
pr := NewRequest()
pr.SetMethod("GET")
pr.SetUri(APIURI + ServiceUri["Payment"])
response := p.ClientRequest(&pr)
obj := PaymentAllResponse{}
json.Unmarshal([]byte(response), &obj)
return obj.Data
}
func (py Payment) New(p *Paymill) Payment {
pr := NewRequest()
pr.SetMethod("POST")
pr.SetUri(APIURI + ServiceUri["Payment"])
params := map[string]interface{}{
"token": py.Token,
"client": py.Client,
}
pr.SetParams(params)
response := p.ClientRequest(&pr)
obj := PaymentResponse{}
json.Unmarshal([]byte(response), &obj)
return obj.Data
}