forked from sait/go-conekta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconekta-example.go
49 lines (46 loc) · 1.24 KB
/
conekta-example.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
package main
import (
"fmt"
"github.com/grodriguez85/go-conekta/conekta"
)
func main() {
fmt.Println("Hello conekta")
conekta.APIKey = "<My Secret APIKey>"
fmt.Println("Creating an order")
order := new(conekta.Order)
fmt.Println("Creating an item")
item := conekta.LineItem{
Name: "Awesome item",
Description: "Super Awesome item",
UnitPrice: 20000,
Quantity: 2,
}
order.LineItems = append(order.LineItems, item)
fmt.Println("Setting currency")
order.Currency = "MXN"
fmt.Println("Creating charge")
charge := conekta.Charge{
PaymentMethod: conekta.PaymentMethod{
Type: "card",
TokenId: "<token generated by frontend>",
},
}
order.Charges = append(order.Charges, charge)
fmt.Println("Adding some metadata")
order.Metadata = conekta.Metadata{
"test": "extra_info",
"hola": "mundo",
}
fmt.Println("Setting customer info")
order.CustomerInfo.Name = "Fulanito Pérez"
order.CustomerInfo.Email = "[email protected]"
order.CustomerInfo.Phone = "+52181818181"
fmt.Println("Sending order to conekta")
statusCode, conektaError, conektaResponde := order.Create()
if statusCode != 200 {
fmt.Println("There's a problem :(")
panic(conektaError)
}
fmt.Println(conektaResponde)
fmt.Println("Congratulations!!")
}