-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
gateway.go
52 lines (43 loc) · 977 Bytes
/
gateway.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
package payment
import (
"fmt"
"strings"
)
// Gateway represent payment gateway used
type Gateway int
const (
// UnknownGateway gateway is unknown
UnknownGateway Gateway = iota
// GatewayMidtrans is midtrans payment gateway
GatewayMidtrans
// GatewayXendit is xendit payment gateway
GatewayXendit
)
func (g Gateway) String() string {
return []string{"unkown", "midtrans", "xendit"}[g]
}
// UnmarshalYAML convert string to Gateway enum
func (g *Gateway) UnmarshalYAML(unmarshal func(interface{}) error) error {
var n string
if err := unmarshal(&n); err != nil {
return err
}
*g = NewGateway(n)
if *g == UnknownGateway {
return fmt.Errorf("payment gateway is not recognized")
}
return nil
}
// NewGateway return a gateway for its string name
func NewGateway(name string) Gateway {
var g Gateway
switch strings.ToLower(name) {
case "midtrans":
g = GatewayMidtrans
case "xendit":
g = GatewayXendit
default:
g = UnknownGateway
}
return g
}