-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
103 lines (96 loc) · 2.8 KB
/
client_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
package yigim_test
import (
"os"
"regexp"
"testing"
"github.com/paladium/yigim-gateway-go"
"github.com/stretchr/testify/assert"
)
func getAppConfig() *yigim.Configuration {
return &yigim.Configuration{
Secret: os.Getenv("YIGIM_SECRET"),
Merchant: os.Getenv("YIGIM_MERCHANT"),
Address: "https://sandbox.api.pay.yigim.az",
}
}
func TestYigimClientCreate(t *testing.T) {
client := yigim.NewClient(getAppConfig())
reference := client.GetRef()
result, err := client.Create(&yigim.PaymentCreate{
Reference: reference,
Type: "SMS",
Save: "y",
Amount: 100,
Currency: "944",
Biller: os.Getenv("YIGIM_BILLER"),
Description: "Test",
Template: "TPL0001",
Language: "en",
Callback: "http://test.com",
})
assert.Nil(t, err)
assert.Equal(t, yigim.ResponseCode0, result.Code)
assert.Equal(t, "OK (No error)", result.Message)
assert.Regexp(t, regexp.MustCompile(`https:\/\/sandbox\.pay\.yigim\.az\/payment\/[0-9A-Z]+`), result.URL)
}
func TestYigimClientStatus(t *testing.T) {
client := yigim.NewClient(getAppConfig())
reference := client.GetRef()
//Create the payment first, then extract the payment status
_, err := client.Create(&yigim.PaymentCreate{
Reference: reference,
Type: "SMS",
Save: "y",
Amount: 100,
Currency: "944",
Biller: os.Getenv("YIGIM_BILLER"),
Description: "Test",
Template: "TPL0001",
Language: "en",
Callback: "http://test.com",
})
assert.Nil(t, err)
result, err := client.Status(&yigim.PaymentStatus{
Reference: reference,
})
assert.Nil(t, err)
assert.Equal(t, yigim.ResponseCode0, result.Code)
assert.Equal(t, "SMS", result.Type)
assert.Equal(t, float64(1), result.Amount)
assert.Equal(t, "AZN", result.Currency)
}
func TestYigimClientExecute(t *testing.T) {
client := yigim.NewClient(getAppConfig())
reference := client.GetRef()
//Create the payment first, then extract the payment status
result, err := client.Execute(&yigim.PaymentExecute{
Reference: reference,
Type: "SMS",
Token: os.Getenv("YIGIM_TOKEN"),
Amount: 100,
Currency: "944",
Biller: os.Getenv("YIGIM_BILLER"),
})
assert.Nil(t, err)
assert.Equal(t, yigim.ResponseCode0, result.Code)
assert.Equal(t, "OK (No error)", result.Message)
}
func TestYigimClientRefund(t *testing.T) {
client := yigim.NewClient(getAppConfig())
reference := client.GetRef()
//Create the payment first, then extract the payment status
_, err := client.Execute(&yigim.PaymentExecute{
Reference: reference,
Type: "SMS",
Token: os.Getenv("YIGIM_TOKEN"),
Amount: 100,
Currency: "944",
Biller: os.Getenv("YIGIM_BILLER"),
})
assert.Nil(t, err)
result, err := client.Refund(&yigim.PaymentRefund{
Reference: reference,
})
assert.Nil(t, err)
assert.Equal(t, "OK (No error)", result.Message)
}