-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment.go
38 lines (31 loc) · 936 Bytes
/
payment.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/CamiloHernandez/go-flow"
"net/http"
)
func main() {
c := flow.NewClient("your api key", "your secret key")
c.SetSandbox()
result, err := c.CreateOrder(flow.OrderRequest{
CommerceOrder: "123123",
Subject: "Test Order",
Amount: 1000,
PayerEmail: "example@example.com",
ConfirmationURL: "http://example.com/confirmation",
ReturnURL: "http://example.com/return",
})
if err != nil {
panic(err)
}
fmt.Println("ID:", result.FlowID)
fmt.Println("Token:", result.Token)
fmt.Println("URL:", result.GetPaymentURL())
http.HandleFunc("/confirm", c.HTTPOrderConfirmationCallback(func(o *flow.Order) {
fmt.Println("Order", o.CommerceOrder, "confirmed with status", o.Status)
}))
http.HandleFunc("/return", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Order completed!"))
})
panic(http.ListenAndServe(":80", nil))
}