-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_card.go
55 lines (38 loc) · 971 Bytes
/
check_card.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
package gogojudo
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"path"
)
type CheckCardResponse struct{}
func (jp *JudoPay) CheckCard(rcp RegisterCardModel) (ret CheckCardResponse, err error) {
var requestURL *url.URL = jp.APIUrl
requestBody, err := json.Marshal(rcp)
if err != nil {
return ret, err
}
requestURL.Path = path.Join(requestURL.Path, "checkcard")
request, err := http.NewRequest(http.MethodPost, requestURL.String(), bytes.NewBuffer(requestBody))
jp.SetHeaders(request)
if err != nil {
return ret, err
}
resp, err := jp.HttpClient.Do(request)
if err != nil {
return ret, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
var jerror = &JudoError{}
json.NewDecoder(resp.Body).Decode(&jerror)
fmt.Printf("%+v", jerror)
return ret, jerror.GetError()
}
var response map[string]interface{}
json.NewDecoder(resp.Body).Decode(&response)
fmt.Printf("\n\n%+v\n", response)
return ret, nil
}