-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththawani_test.go
64 lines (56 loc) · 1.4 KB
/
thawani_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
package thawani
import (
"log"
"net/url"
"testing"
"github.com/ahmkindi/go-thawani/types/mode"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type TestMetadata struct {
Hello string `json:"hello"`
Name string `json:"name"`
}
var (
testURL = "https://uatcheckout.thawani.om"
testAPI = "rRQ26GcsZzoEhbrP2HZvLYDbn9C9et"
testKey = "HGvTMLDssJghr9tlN9gr4DVYt0qyBy"
client *ThawaniClient
)
func init() {
host, err := url.Parse(testURL)
if err != nil {
log.Fatalf("failed to init thawanit: %s", err.Error())
}
client = NewClient(nil, host, testAPI, testKey)
}
func TestCreateSession(t *testing.T) {
id := "1234"
resp, err := client.CreateCustomer(CreateCustomerReq{
ClientCustomerId: "1234",
})
require.NoError(t, err)
require.True(t, resp.Success)
metadata := TestMetadata{
Hello: "world",
Name: "test",
}
req := CreateSessionReq{
ClientReferenceId: id,
CustomerId: resp.Data.Id,
Mode: mode.Payment,
Products: []Product{{
Name: "test",
Quantity: 10,
UnitAmount: 10,
}},
SuccessUrl: "https://test.com",
CancelUrl: "https://test.com",
Metadata: metadata,
}
sessionResp, _, err := client.CreateSession(req)
require.NoError(t, err)
assert.Equal(t, 2004, sessionResp.Code)
assert.Equal(t, metadata.Hello, sessionResp.Data.Metadata["hello"])
assert.Equal(t, metadata.Name, sessionResp.Data.Metadata["name"])
}