sdk-go

module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 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.18 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/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)
}
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

Jump to

Keyboard shortcuts

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