forked from veritrans/go-midtrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_test.go
139 lines (122 loc) · 3.04 KB
/
core_test.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package midtrans_test
import (
"log"
"strconv"
"testing"
"time"
"github.com/cheekybits/is"
midtrans "github.com/veritrans/go-midtrans"
)
var orderId1 string
func TestCoreCharge(t *testing.T) {
is := is.New(t)
now := time.Now()
timestamp := strconv.FormatInt(now.Unix(), 10)
orderId1 = "order-id-go-" + timestamp
midclient := midtrans.NewClient()
midclient.ServerKey = "SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA"
midclient.ClientKey = "SB-Mid-client-61XuGAwQ8Bj8LxSS"
midclient.APIEnvType = midtrans.Sandbox
midclient.LogLevel = 3
coreGateway := midtrans.CoreGateway{
Client: midclient,
}
chargeReq := &midtrans.ChargeReq{
PaymentType: midtrans.SourceGopay,
TransactionDetails: midtrans.TransactionDetails{
OrderID: orderId1,
GrossAmt: 200000,
},
Gopay: &midtrans.GopayDetail{
EnableCallback: true,
CallbackUrl: "https://example.org",
},
Items: &[]midtrans.ItemDetail{
{
ID: "ITEM1",
Price: 200000,
Qty: 1,
Name: "Some item",
},
},
}
log.Println("Charge:")
chargeResp, err := coreGateway.Charge(chargeReq)
if err != nil {
log.Println("Fail w/ err:")
log.Fatal(err)
log.Println(err)
} else {
log.Println("Success w/ res:")
log.Println(chargeResp)
is.OK(chargeResp)
is.OK(chargeResp.Actions)
}
}
func TestCoreChargeWithMap(t *testing.T) {
is := is.New(t)
now := time.Now()
timestamp := strconv.FormatInt(now.Unix(), 10)
orderId1 = "order-id-go-" + timestamp
midclient := midtrans.NewClient()
midclient.ServerKey = "SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA"
midclient.ClientKey = "SB-Mid-client-61XuGAwQ8Bj8LxSS"
midclient.APIEnvType = midtrans.Sandbox
midclient.LogLevel = 3
coreGateway := midtrans.CoreGateway{
Client: midclient,
}
chargeReq := &midtrans.ChargeReqWithMap{
"payment_type": midtrans.SourceGopay,
"transaction_details": midtrans.TransactionDetails{
OrderID: orderId1,
GrossAmt: 200000,
},
"gopay": &midtrans.GopayDetail{
EnableCallback: true,
CallbackUrl: "https://example.org",
},
"item_details": &[]midtrans.ItemDetail{
midtrans.ItemDetail{
ID: "ITEM1",
Price: 200000,
Qty: 1,
Name: "Map Interface",
},
},
}
log.Println("Charge:")
chargeResp, err := coreGateway.ChargeWithMap(chargeReq)
if err != nil {
log.Println("Fail w/ err:")
log.Fatal(err)
log.Println(err)
} else {
log.Println("Success w/ res:")
log.Println(chargeResp)
is.OK(chargeResp["actions"])
}
}
func TestCoreStatus(t *testing.T) {
is := is.New(t)
midclient := midtrans.NewClient()
midclient.ServerKey = "SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA"
midclient.ClientKey = "SB-Mid-client-61XuGAwQ8Bj8LxSS"
midclient.APIEnvType = midtrans.Sandbox
midclient.LogLevel = 3
coreGateway := midtrans.CoreGateway{
Client: midclient,
}
log.Println("Status:")
statusResp, err := coreGateway.Status(orderId1)
if err != nil {
log.Println("Fail w/ err:")
log.Fatal(err)
log.Println(err)
} else {
log.Println("Success w/ res:")
log.Println(statusResp)
is.OK(statusResp)
is.Equal("pending", statusResp.TransactionStatus)
}
}