-
Notifications
You must be signed in to change notification settings - Fork 5
/
preauth_txn.go
77 lines (66 loc) · 2.84 KB
/
preauth_txn.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
package ravepay
// FIXME: Done to enable testing
var (
capturePreAuthURL = buildURL(capturePreAuthPaymentURL)
voidorRefundPreAuthURL = buildURL(voidOrRefundPreAuthURL)
)
// CapturePreAuthPayment makes request to rave's capture endpoint to claim preauth payments
// It takes the flwRef as param and returns the capture response and any error that occures
// https://flutterwavedevelopers.readme.io/v2.0/reference#capture
func CapturePreAuthPayment(ref string) (*ChargeResponse, error) {
resp := &ChargeResponse{}
payload := struct {
SECKEY string `json:"SECKEY"`
FlwRef string `json:"flwRef"`
}{SecretKey, ref}
err := sendRequestAndParseResponse("POST", capturePreAuthURL, payload, resp)
return resp, err
}
// PreAuthResponse is a type of rave response for refund or void preauth payment response
type PreAuthResponse struct {
Data struct {
Data struct {
AuthorizeID string `json:"authorizeId"`
Avsresponsecode interface{} `json:"avsresponsecode"`
Avsresponsemessage interface{} `json:"avsresponsemessage"`
Otptransactionidentifier interface{} `json:"otptransactionidentifier"`
Redirecturl interface{} `json:"redirecturl"`
Responsecode string `json:"responsecode"`
Responsehtml interface{} `json:"responsehtml"`
Responsemessage string `json:"responsemessage"`
Responsetoken interface{} `json:"responsetoken"`
Transactionreference string `json:"transactionreference"`
} `json:"data"`
Status string `json:"status"`
} `json:"data"`
Message string `json:"message"`
Status string `json:"status"`
}
// RefundPreAuthPayment fullfiles the raves preauth feature by refunding the preauthorized paymemnt
// It takes the flwRef and makes a request to refund the txn
// It returns the response and any error that occurs
// https://flutterwavedevelopers.readme.io/v2.0/reference#refund-or-void
func RefundPreAuthPayment(ref string) (*PreAuthResponse, error) {
resp := &PreAuthResponse{}
payload := struct {
Action string `json:"action"`
FlwRef string `json:"ref"`
SECKEY string `json:"SECKEY"`
}{"refund", SecretKey, ref}
err := sendRequestAndParseResponse("POST", voidorRefundPreAuthURL, payload, resp)
return resp, err
}
// VoidPreAuthPayment fullfiles the raves preauth feature by voiding the preauthorized paymemnt
// It takes the flwRef and makes a request to void the txn
// It returns the response and any error that occurs
// https://flutterwavedevelopers.readme.io/v2.0/reference#refund-or-void
func VoidPreAuthPayment(ref string) (*PreAuthResponse, error) {
resp := &PreAuthResponse{}
payload := struct {
Action string `json:"action"`
FlwRef string `json:"ref"`
SECKEY string `json:"SECKEY"`
}{"void", SecretKey, ref}
err := sendRequestAndParseResponse("POST", voidorRefundPreAuthURL, payload, resp)
return resp, err
}