/
dispute.go
90 lines (82 loc) · 1.91 KB
/
dispute.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
package operations
import (
"github.com/omise/omise-go"
"github.com/omise/omise-go/internal"
)
// Example:
//
// disputes, list := &omise.DisputeList{}, &ListDisputes{
// State: omise.Open,
// }
// if e := client.Do(disputes, list); e != nil {
// panic(e)
// }
//
// fmt.Println("# of open disputes:", len(disputes.Data))
//
type ListDisputes struct {
State omise.DisputeStatus
List
}
func (req *ListDisputes) Describe() *internal.Description {
path := "/disputes"
switch req.State {
case omise.Open:
path += "/open"
case omise.Pending:
path += "/pending"
case omise.Won, omise.Lost, omise.Closed:
path += "/closed"
}
return &internal.Description{
Endpoint: internal.API,
Method: "GET",
Path: path,
ContentType: "application/json",
}
}
// Example:
//
// dispute, retrieve := &omise.Dispute{}, &RetrieveDispute{"dspt_123"}
// if e := client.Do(dispute, retrieve); e != nil {
// panic(e)
// }
//
// fmt.Printf("dispute #123: %#v\n", dispute)
//
type RetrieveDispute struct {
DisputeID string `json:"-"`
}
func (req *RetrieveDispute) Describe() *internal.Description {
return &internal.Description{
Endpoint: internal.API,
Method: "GET",
Path: "/disputes/" + req.DisputeID,
ContentType: "application/json",
}
}
// Example:
//
// dispute, update := &omise.Dispute{}, &UpdateDispute{
// DisputeID: "dspt_777",
// Message: "update me!",
// }
// if e := client.Do(dispute, update); e != nil {
// panic(e)
// }
//
// fmt.Printf("updated dispute: %#v\n", dispute)
//
type UpdateDispute struct {
DisputeID string `json:"-"`
Message string `json:"message"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
func (req *UpdateDispute) Describe() *internal.Description {
return &internal.Description{
Endpoint: internal.API,
Method: "PATCH",
Path: "/disputes/" + req.DisputeID,
ContentType: "application/json",
}
}