45 Mercado Pago API configurations
We will now integrate the Mercado Pago API into our project.
Access the link below, and if you do not have an account, click the 'Create your account' button in the top right corner.

Next, follow the steps on the site to validate your account. If you already have an account, simply log in directly. After logging in, the page should appear as follows:

Alternatively, you could choose any other payment system API, but we selected the Mercado Pago API specifically for its simplicity and intuitive design.
Another key reason for our choice is its use of "preferences" SDKs (Software Development Kits), which enable us to manage the entire payment process through a generated link. This allows for easy customization of the cost and other user preferences in a straightforward and user-friendly manner.
All API-related changes will be based on the official documentation.
First, install the Mercado Pago library in your terminal:
pip install mercadopago
Next, import the Mercado Pago library into the api_mercadopago.py
file.
import mercadopago
Before proceeding with the code development, generate your API key. Next to the "Your Account" button in the top right corner of the page, click on the "Your Integrations" button.

We are essentially creating an "app" within the Mercado Pago API that we will integrate into our project. Next, click on "Create Application," and after validating your account once more, you will be directed to this page:

Fill out the forms as shown below:

After creating the application, you will be redirected to the following page:

At this stage, we will test the payment functionalities using the testing accounts and credentials provided by the API. Once the project is completed, we will switch to production accounts.
(Note: You can create up to 15 testing accounts.)

Click on "Testing Accounts," and you will be redirected to the following page:

Click on "Create Testing Accounts" and fill out the forms, naming the account "buyer" and setting the bank balance to 50,000 reais.

Repeat the procedure to create an account named "seller" with a bank balance of 10,000 reais.

We will now set up the seller account.
First, open an incognito tab and enter the following link:
Click on "Sign In" (top right of the page) and log in using the username and password of the seller account. Once the project is completed, we will perform the same procedure with our real Mercado Pago account.

After signing in, repeat the same process as when creating an application:
Click on "Your Integrations."
Click on "Create Application."
Fill out the basic configuration forms with the same information as before (except for the name, which should be something like "Ecommerce Reserva Test").

After being redirected to the page for the new test application, click on "Production Credentials" located near the bottom left of the page.

This will take you to a page containing the API key and access token that we will use.

Copy and paste the public key and access token into the api_mercadopago.py
file.
Note: You must use your own API key and access token for it to work.
import mercadopago
public_key = "APP_USR-8e9c2811-1d99-4346-b8a0-9118201f7216"
token = "APP_USR-1378561128003766-083016-a08284dad9da4451cc196354af9f6722-1968090813"
When testing the payment system, ensure you are using a browser where the seller testing account is logged in to the Mercado Pago site. In some cases, the API might ask you to login once more in the payment screen on the top option.
Additionally, once the project is completed, you will use your own personal account's production credentials, with its own public key and access token, instead of the seller testing account.
Last updated