-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (30 loc) · 929 Bytes
/
main.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
package main
import (
"fmt"
"github.com/chekalskiy/go-coingate"
"log"
"net/http"
)
var cg *coingate.Coingate
const (
AppID = 1015
APIKey = "WV5FGZRuoCstBiHayYXbp3"
APISecret = "ni6FmIUTxBSR8PK2JeDA5NVjpzc4tqZO"
)
// After running main.go execute:
// `curl -X POST -d "id=343&order_id=ORDER-1415020039&status=paid&price=1050.99¤cy=USD&receive_currency=EUR&receive_amount=926.73&btc_amount=4.81849315&created_at=2014-11-03T13:07:28%2B03:00" http://localhost:8000/payments/callback`
func main() {
cg = coingate.New(AppID, APIKey, APISecret, true)
http.HandleFunc("/payments/callback", receiveCallback)
log.Fatal(http.ListenAndServe(":8000", nil))
}
func receiveCallback(w http.ResponseWriter, r *http.Request) {
p, err := cg.ProcessCallback(r)
if err == nil {
log.Println("Order ID:", p.ID)
log.Println("Order status:", p.Status)
} else {
log.Fatalln("Error", err)
}
fmt.Fprintf(w, "ok")
}