forked from mychaelgo/go-midtrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_test.go
90 lines (78 loc) · 1.9 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
package midtrans_test
import (
"log"
"testing"
"time"
"strconv"
"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{
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 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)
}
}