A Wrapper for use conekta's api v2 in golang
This tutorial assumes the next:
- Have a conekta account
- Have a frontend that tokenize cards
- Knowledge of conekta's api
First get the package
go get -u github.com/sait/go-conekta
Import in your project
import (
"github.com/sait/go-conekta/conekta"
)
conekta.ApiKey = "<My Secret ApiKey>"
order := new(conekta.Order)
item := conekta.LineItem{
Name: "Awesome item",
Description: "Super Awesome item",
UnitPrice: 20000,
Quantity: 2,
}
order.LineItems = append(order.LineItems, item)
order.Currency = "MXN"
charge := conekta.Charge{
PaymentMethod: conekta.PaymentMethod{
Type: "card",
TokenId: "<token generated by frontend>",
},
}
order.Charges = append(order.Charges, charge)
order.Metadata = conekta.Metadata{
"test": "extra_info",
"hola": "mundo",
}
order.CustomerInfo.Name = "Fulanito Pérez"
order.CustomerInfo.Email = "[email protected]"
order.CustomerInfo.Phone = "+52181818181"
statusCode, conektaError, conektaResponde := order.Create()
if statusCode != 200 {
fmt.Println("There's a problem :(")
panic(conektaError)
}
fmt.Println(conektaResponde)
fmt.Println("Congratulations!!")
https://developers.conekta.com/libraries/javascript