-
Notifications
You must be signed in to change notification settings - Fork 0
/
irankish.go
65 lines (55 loc) · 1.75 KB
/
irankish.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
package irankish
import (
"fmt"
"net/http"
)
type IranKish struct {
merchantID string
sha1Key string
}
func New(merchantID, sha1Key string) *IranKish {
return &IranKish{merchantID: merchantID, sha1Key: sha1Key}
}
func (i *IranKish) NewToken(invoiceID string, amount int64, callbackUrl string) *token {
return &token{
merchantID: i.merchantID,
invoiceNumber: invoiceID,
amount: amount,
callbackUrl: callbackUrl,
}
}
func (i *IranKish) SimpleFromRedirectingToGateway(token string) string {
form := `<form id="redirectform" action="%s" method="POST"><input type="hidden" name="token" value="%s"/><input type="hidden" name="merchantId" value="%s"/></form><script>document.forms["redirectform"].submit();</script>`
return fmt.Sprintf(form, gatewayUrl, token, i.merchantID)
}
func (i *IranKish) CallbackHandler(data chan<- *CallbackData) (handler func(w http.ResponseWriter, r *http.Request)) {
handler = func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
cd := &CallbackData{
Token: r.Form.Get("token"),
MerchantID: r.Form.Get("merchantId"),
AcceptorID: r.Form.Get("acceptorId"),
ResultCode: r.Form.Get("resultCode"),
CardNo: r.Form.Get("cardNo"),
InvoiceNumber: r.Form.Get("InvoiceNumber"),
PaymentID: r.Form.Get("paymentId"),
Amount: r.Form.Get("amount"),
ReferenceID: r.Form.Get("referenceId"),
response: make(chan []byte, 1),
}
go func() {
data <- cd
}()
w.Write(<-cd.response)
}
return
}
func (i *IranKish) VerifyPayment(token string, referenceNumber int64) (*VerifyPaymentResult, error) {
p := &payment{
merchantID: i.merchantID,
sha1Key: i.sha1Key,
token: token,
referenceNumber: referenceNumber,
}
return p.verify()
}