forked from veritrans/go-midtrans
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnap_test.go
116 lines (103 loc) · 2.59 KB
/
snap_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
package midtrans_test
import (
"log"
"testing"
"time"
"strconv"
"github.com/cheekybits/is"
midtrans "github.com/veritrans/go-midtrans"
)
func TestSnapCreateTokenQuick(t *testing.T) {
// t.Skip("Temprorary Skipping")
is := is.New(t)
now := time.Now()
timestamp := strconv.FormatInt(now.Unix(), 10)
midclient := midtrans.NewClient()
midclient.ServerKey = "SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA"
midclient.ClientKey = "SB-Mid-client-61XuGAwQ8Bj8LxSS"
midclient.APIEnvType = midtrans.Sandbox
midclient.LogLevel = 3
var snapGateway midtrans.SnapGateway
snapGateway = midtrans.SnapGateway{
Client: midclient,
}
log.Println("CreateTokenQuick:")
snapTokenResp, err := snapGateway.GetTokenQuick("order-id-go-"+timestamp, 200000)
if err != nil {
log.Println("Fail w/ err:")
log.Fatal(err)
} else {
log.Println("Success w/ token:")
log.Println(snapTokenResp)
is.OK(snapTokenResp)
is.OK(snapTokenResp.Token)
is.OK(snapTokenResp.RedirectURL)
}
}
func TestSnapCreateToken(t *testing.T) {
is := is.New(t)
now := time.Now()
timestamp := strconv.FormatInt(now.Unix(), 10)
midclient := midtrans.NewClient()
midclient.ServerKey = "SB-Mid-server-GwUP_WGbJPXsDzsNEBRs8IYA"
midclient.ClientKey = "SB-Mid-client-61XuGAwQ8Bj8LxSS"
midclient.APIEnvType = midtrans.Sandbox
midclient.LogLevel = 3
var snapGateway midtrans.SnapGateway
snapGateway = midtrans.SnapGateway{
Client: midclient,
}
custAddress := &midtrans.CustAddress{
FName: "John",
LName: "Doe",
Phone: "081234567890",
Address: "Baker Street 97th",
City: "Jakarta",
Postcode: "16000",
CountryCode: "IDN",
}
snapReq := &midtrans.SnapReq{
TransactionDetails: midtrans.TransactionDetails{
OrderID: "order-id-go-"+timestamp,
GrossAmt: 200000,
},
CustomerDetail: &midtrans.CustDetail{
FName: "John",
LName: "Doe",
Email: "john@doe.com",
Phone: "081234567890",
BillAddr: custAddress,
ShipAddr: custAddress,
},
Items: &[]midtrans.ItemDetail{
midtrans.ItemDetail{
ID: "ITEM1",
Price: 200000,
Qty: 1,
Name: "Someitem",
},
},
Expiry: &midtrans.ExpiryDetail{
// StartTime: "2019-05-13 18:00:00 +0700",
Unit: "hour",
Duration: 48,
},
Gopay: &midtrans.GopayDetail{
EnableCallback: true,
CallbackUrl: "https://example.com/gopay/finish",
},
}
log.Println("GetToken:")
snapTokenResp, err := snapGateway.GetToken(snapReq)
if err != nil {
log.Println("Fail w/ err:")
log.Fatal(err)
log.Println(err)
} else {
log.Println("Success w/ res:")
log.Println(snapTokenResp)
is.OK(snapTokenResp)
is.OK(snapTokenResp.Token)
is.OK(snapTokenResp.RedirectURL)
}
}