-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathauthorizecim.go
94 lines (87 loc) · 2.27 KB
/
authorizecim.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
package AuthorizeCIM
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
var api_endpoint string = "https://apitest.authorize.net/xml/v1/request.api"
var apiName *string
var apiKey *string
var testMode string
var showLogs bool = true
var connected bool = false
func SetAPIInfo(name string, key string, mode string) {
apiKey = &key
apiName = &name
if mode == "live" {
showLogs = false
testMode = "liveMode"
api_endpoint = "https://api.authorize.net/xml/v1/request.api"
} else {
showLogs = true
testMode = "testMode"
api_endpoint = "https://apitest.authorize.net/xml/v1/request.api"
}
}
func IsConnected() (bool, error) {
info, err := GetMerchantDetails()
if err != nil {
return false, err
}
if info.Ok() {
return true, err
}
return false, err
}
func GetAuthentication() MerchantAuthentication {
auth := MerchantAuthentication{
Name: apiName,
TransactionKey: apiKey,
}
return auth
}
func SendRequest(input []byte) ([]byte, error) {
req, err := http.NewRequest("POST", api_endpoint, bytes.NewBuffer(input))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body = bytes.TrimPrefix(body, []byte("\xef\xbb\xbf"))
if showLogs {
fmt.Println(string(body))
}
return body, err
}
func (r AVS) Text() string {
var response string
switch r.avsResultCode {
case "E":
response = "AVS data provided is invalid or AVS is not allowed for the card type that was used."
case "R":
response = "The AVS system was unavailable at the time of processing."
case "G":
response = "The card issuing bank is of non-U.S. origin and does not support AVS"
case "U":
response = "The address information for the cardholder is unavailable."
case "S":
response = "The U.S. card issuing bank does not support AVS."
case "N":
response = "Address: No Match ZIP Code: No Match"
case "A":
response = "Address: Match ZIP Code: No Match"
case "Z":
response = "Address: No Match ZIP Code: Match"
case "W":
response = "Address: No Match ZIP Code: Matched 9 digits"
case "X":
response = "Address: Match ZIP Code: Matched 9 digits"
case "Y":
response = "Address: Match ZIP: Matched first 5 digits"
}
return response
}