sdk-go

module
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT

README

Mercado Pago SDK for Go

Go Reference

mercado-pago-image-7130x2250

Overview

A comprehensive Go client library for integrating with the Mercado Pago API.

💡 Requirements

The SDK requires Go 1.23 or higher.

📲 Installation

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.

🌟 Getting Started

Simple usage looks like:

package main

import (
	"context"
	"fmt"

	"github.com/mercadopago/sdk-go/pkg/config"
	"github.com/mercadopago/sdk-go/pkg/order"
)

func main() {
	accessToken := "{{ACCESS_TOKEN}}"
	c, err := config.New(accessToken)
	if err != nil {
		fmt.Println(err)
		return
	}

	client := order.NewClient(c)
	request := order.Request{
		Type:              "online",
		TotalAmount:       "1000.00",
		ExternalReference: "ext_ref_1234",
		Currency:          "BRL",
		Transactions: &order.TransactionRequest{
			Payments: []order.PaymentRequest{
				{
					Amount: "1000.00",
					PaymentMethod: &order.PaymentMethodRequest{
						ID:           "master",
						Token:        "{{CARD_TOKEN}}",
						Type:         "credit_card",
						Installments: 1,
					},
				},
			},
		},
		Payer: &order.PayerRequest{
			Email: "{{PAYER_EMAIL}}",
		},
	}

	resource, err := client.Create(context.Background(), request)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(resource)
}
SDK Configuration

Before making API requests, you need to initialize the SDK with your access token:

	accessToken := "{{ACCESS_TOKEN}}"

	cfg, err := config.New(accessToken)
Making API Requests

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())
Exception throwing handling

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.

📚 Documentation

See our documentation for more details.

🤝 Contributing

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.

❤️ Support

If you require technical support, please contact our support team at our developers site: English | Portuguese | Spanish

Directories

Path Synopsis
examples
advancedpayment command
apis/order/createpse command
Package main shows how to create an Order using PSE (Pagos Seguros en Línea — Colombia).
Package main shows how to create an Order using PSE (Pagos Seguros en Línea — Colombia).
apis/order/get command
apis/point/get command
apis/refund/get command
apis/user/get command
chargeback command
custom_timeout command
mp_error_parse command
pkg
advancedpayment
Package advancedpayment provides a client for the MercadoPago Advanced Payments API.
Package advancedpayment provides a client for the MercadoPago Advanced Payments API.
cardtoken
Package cardtoken provides a client for creating card tokens via the MercadoPago Card Tokens API.
Package cardtoken provides a client for creating card tokens via the MercadoPago Card Tokens API.
chargeback
Package chargeback provides a client for the MercadoPago Chargebacks API.
Package chargeback provides a client for the MercadoPago Chargebacks API.
config
Package config provides SDK-level configuration for the MercadoPago Go SDK.
Package config provides SDK-level configuration for the MercadoPago Go SDK.
customer
Package customer provides a client for managing customers in the MercadoPago Customers API.
Package customer provides a client for managing customers in the MercadoPago Customers API.
customercard
Package customercard provides a client for managing saved payment cards associated with customers in the MercadoPago Customer Cards API.
Package customercard provides a client for managing saved payment cards associated with customers in the MercadoPago Customer Cards API.
disbursementrefund
Package disbursementrefund provides a client for managing refunds on disbursements within MercadoPago advanced (split) payments.
Package disbursementrefund provides a client for managing refunds on disbursements within MercadoPago advanced (split) payments.
identificationtype
Package identificationtype provides a client for retrieving accepted identification document types from the MercadoPago Identification Types API.
Package identificationtype provides a client for retrieving accepted identification document types from the MercadoPago Identification Types API.
internal/defaultrequester
Package defaultrequester provides the SDK's built-in requester.Requester implementation.
Package defaultrequester provides the SDK's built-in requester.Requester implementation.
internal/httpclient
Package httpclient is an internal package that provides HTTP request construction, header management, and JSON marshalling/unmarshalling helpers used by the MercadoPago Go SDK's resource clients.
Package httpclient is an internal package that provides HTTP request construction, header management, and JSON marshalling/unmarshalling helpers used by the MercadoPago Go SDK's resource clients.
invoice
Package invoice provides a client for interacting with the MercadoPago Authorized Payments (Invoice) API.
Package invoice provides a client for interacting with the MercadoPago Authorized Payments (Invoice) API.
merchantorder
Package merchantorder provides a client for interacting with the MercadoPago Merchant Orders API.
Package merchantorder provides a client for interacting with the MercadoPago Merchant Orders API.
mperror
Package mperror defines error types returned by the MercadoPago Go SDK.
Package mperror defines error types returned by the MercadoPago Go SDK.
oauth
Package oauth provides a client for interacting with the MercadoPago OAuth API.
Package oauth provides a client for interacting with the MercadoPago OAuth API.
order
Package order provides a client for the MercadoPago Orders API (v1).
Package order provides a client for the MercadoPago Orders API (v1).
payment
Package payment provides a client for the MercadoPago Payments API.
Package payment provides a client for the MercadoPago Payments API.
paymentmethod
Package paymentmethod provides a client for the MercadoPago Payment Methods API.
Package paymentmethod provides a client for the MercadoPago Payment Methods API.
point
Package point provides a client for interacting with the MercadoPago Point Integration API.
Package point provides a client for interacting with the MercadoPago Point Integration API.
preapproval
Package preapproval provides a client for the MercadoPago Subscriptions (Pre-Approval) API.
Package preapproval provides a client for the MercadoPago Subscriptions (Pre-Approval) API.
preapprovalplan
Package preapprovalplan provides a client for the MercadoPago Subscription Plan (Pre-Approval Plan) API.
Package preapprovalplan provides a client for the MercadoPago Subscription Plan (Pre-Approval Plan) API.
preference
Package preference provides a client for interacting with the MercadoPago Checkout Preferences API.
Package preference provides a client for interacting with the MercadoPago Checkout Preferences API.
refund
Package refund provides a client for the MercadoPago Refunds API.
Package refund provides a client for the MercadoPago Refunds API.
requester
Package requester defines the HTTP transport abstraction used by the MercadoPago Go SDK.
Package requester defines the HTTP transport abstraction used by the MercadoPago Go SDK.
user
Package user provides a client for retrieving the authenticated MercadoPago user's information.
Package user provides a client for retrieving the authenticated MercadoPago user's information.
webhook
Package webhook provides utilities to verify the authenticity of incoming MercadoPago webhook notifications.
Package webhook provides utilities to verify the authenticity of incoming MercadoPago webhook notifications.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL