A LangChain tool for generating MercadoPago payment links
Project description
langchain-mercadopago-link
A LangChain tool for generating MercadoPago payment links. This package provides a reusable LangChain Tool that can be integrated into LangChain agents and chains to generate payment links dynamically.
Installation
pip install langchain-mercadopago-link
Quick Start
from langchain_mercadopago_link import MercadoPagoPaymentTool
# Initialize the tool with your MercadoPago credentials
tool = MercadoPagoPaymentTool(
access_token="YOUR_MERCADOPAGO_ACCESS_TOKEN",
local_id="YOUR_LOCAL_ID" # Optional
)
# Use the tool directly
result = tool.run({
"title": "Development Consulting",
"description": "Web development consulting services",
"amount": 5000.0,
"currency": "ARS"
})
print(result)
Usage with LangChain Agents
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from langchain_mercadopago_link import MercadoPagoPaymentTool
# Initialize LLM
llm = ChatOpenAI(temperature=0)
# Initialize the MercadoPago tool
payment_tool = MercadoPagoPaymentTool(
access_token="YOUR_ACCESS_TOKEN",
local_id="YOUR_LOCAL_ID"
)
# Create an agent with the payment tool
agent = initialize_agent(
tools=[payment_tool],
llm=llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True
)
# Use the agent to generate a payment link
response = agent.run(
"I need to generate a payment link for $10000 Argentine pesos "
"for graphic design services"
)
Usage in LangChain Chains
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain_openai import ChatOpenAI
from langchain_mercadopago_link import MercadoPagoPaymentTool
# Create a chain that uses the payment tool
llm = ChatOpenAI(temperature=0)
payment_tool = MercadoPagoPaymentTool(
access_token="YOUR_ACCESS_TOKEN"
)
# Define a prompt that extracts payment information
prompt = PromptTemplate(
input_variables=["user_request"],
template="""
Analyze the following request and extract payment information:
{user_request}
Then use the MercadoPago tool to generate the link.
"""
)
chain = LLMChain(llm=llm, prompt=prompt)
# ... integrate with tool execution
Tool Parameters
The MercadoPagoPaymentTool accepts the following parameters:
- access_token (required): Your MercadoPago Access Token
- local_id (optional): Your MercadoPago Local ID
Tool Input Schema
When calling the tool, you can provide:
- title (required): Title of the product or service
- description (required): Detailed description
- amount (required): Payment amount
- currency (optional, default: "ARS"): Currency code (ARS, USD, EUR, BRL, MXN, etc.). Can be changed to any supported MercadoPago currency.
- quantity (optional, default: 1): Quantity of items
- success_url (optional): Redirect URL after successful payment. If not provided, no redirect URL will be set.
- failure_url (optional): Redirect URL after failed payment. If not provided, no redirect URL will be set.
- pending_url (optional): Redirect URL for pending payment. If not provided, no redirect URL will be set.
- external_reference (optional): External reference for the payment
Note: All URL parameters are completely optional. If you don't provide any URLs, MercadoPago will handle the payment flow without custom redirect URLs. You can provide one, two, or all three URLs as needed.
Example: Complete Integration
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from langchain_mercadopago_link import MercadoPagoPaymentTool
import os
# Get credentials from environment variables
access_token = os.getenv("MERCADOPAGO_ACCESS_TOKEN")
local_id = os.getenv("MERCADOPAGO_LOCAL_ID")
# Initialize tool
payment_tool = MercadoPagoPaymentTool(
access_token=access_token,
local_id=local_id
)
# Initialize agent
llm = ChatOpenAI(temperature=0)
agent = initialize_agent(
tools=[payment_tool],
llm=llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True
)
# Generate payment link from natural language
result = agent.run(
"The client needs to pay $15000 pesos for a Python course. "
"Generate the payment link."
)
Requirements
- Python >= 3.9
- langchain >= 0.2.0
- mercadopago >= 2.2.0
- pydantic >= 2.0.0
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Sebastian Martin Artaza
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_mercadopago_link-0.1.0.tar.gz.
File metadata
- Download URL: langchain_mercadopago_link-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39314724723af6afb8e0333f9f7f679112f26bf34aa4bf6f245ff084ab2083c3
|
|
| MD5 |
66baf8871935146b49f71b28b728cdea
|
|
| BLAKE2b-256 |
d44c26385c78b7bb5f905a74c4110cab38b575fe085cda14846134ad88f7ea19
|
File details
Details for the file langchain_mercadopago_link-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_mercadopago_link-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bced350eb6611002a4d68ff27bc9c71fe45cdb05bf01f7f65fcebcd4ba40cebb
|
|
| MD5 |
8a59b04f79fea9d9ca8abb1d3b592f09
|
|
| BLAKE2b-256 |
19237375fc415fc75260bf697f9d9a994f08aa177024cb2d64f2506fb897999f
|