A comprehensive Go client library for integrating with the Mercado Pago API.
The SDK requires Go 1.18 or higher.
First time using Mercado Pago? Create your Mercado Pago account, if you don't have one already.
Install the Mercado Pago SDK for Go:
$ go install github.com/mercadopago/sdk-go
That's it! The Mercado Pago SDK for Go has been successfully installed.
Simple usage looks like:
package main
import (
"context"
"fmt"
"github.com/mercadopago/sdk-go/pkg/config"
"github.com/mercadopago/sdk-go/pkg/payment"
)
func main() {
accessToken := "{{ACCESS_TOKEN}}"
cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}
client := payment.NewClient(cfg)
request := payment.Request{
TransactionAmount: 105.1,
Payer: &payment.PayerRequest{
Email: "{{EMAIL}}",
},
Token: "{{CARD_TOKEN}}",
Installments: 1,
}
resource, err := client.Create(context.Background(), request)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resource)
}
Before making API requests, you need to initialize the SDK with your access token:
accessToken := "{{ACCESS_TOKEN}}"
cfg, err := config.New(accessToken)
To make requests to the Mercado Pago APIs, you can use the packages provided by the SDK. For example, to list payment methods, you can use the paymentmethod
package:
client := paymentmethod.NewClient(cfg)
resources, err := client.List(context.Background())
Every package methods returns two variables: response (type of the package) and error (type of the std lib), which will contain any error thrown. It is important to handle these errors in the best possible way.
resources, err := client.List(context.Background())
if err != nil {
// appropriate treatment
}
For more details on the available methods and request parameters, please refer to the Go Reference documentation.
See our documentation for more details.
- Mercado Pago API Reference: English | Portuguese | Spanish
All contributions are welcome, ranging from people wanting to triage issues, others wanting to write documentation, to people wanting to contribute with code.
Please read and follow our contribution guidelines. Contributions not following these guidelines will be disregarded. The guidelines are in place to make all of our lives easier and make contribution a consistent process for everyone.
If you require technical support, please contact our support team at our developers site: English | Portuguese | Spanish