Packages

Elixir client for Mercado Pago API

Current section

Files

Jump to
meli lib meli.ex
Raw

lib/meli.ex

defmodule Meli do
@moduledoc """
Elixir client for Mercado Pago API.
## Configuration
Add your Mercado Pago credentials to your application config:
config :meli,
access_token: "YOUR_ACCESS_TOKEN",
sandbox: true # Set to false in production
## Usage
# Create a payment
{:ok, payment} = Meli.Payment.create(%{
transaction_amount: 100.0,
token: "card_token",
description: "Product description",
payment_method_id: "visa",
payer: %{email: "customer@email.com"}
})
# Using bang functions (raises on error)
payment = Meli.Payment.create!(%{...})
## Per-request configuration
For multi-tenant applications, you can pass client options:
Meli.Payment.create(params, access_token: "tenant_token")
Or create a client explicitly:
client = Meli.client(access_token: "tenant_token", sandbox: false)
Meli.Payment.create(params, client: client)
## Resources
Available resource modules:
* `Meli.Resources.Payment` - Payment operations
* `Meli.Resources.Refund` - Refund operations
* `Meli.Resources.Customer` - Customer management
* `Meli.Resources.Card` - Saved cards
* `Meli.Resources.CardToken` - Card tokenization
* `Meli.Resources.Preference` - Checkout preferences
* `Meli.Resources.Subscription` - Recurring payments
* `Meli.Resources.PaymentMethod` - Available payment methods
* `Meli.Resources.IdentificationType` - ID types (RFC, CURP, etc.)
"""
@doc """
Creates a new client with the given options.
Useful for multi-tenant applications where each tenant has different
Mercado Pago credentials.
## Options
* `:access_token` - Mercado Pago access token
* `:sandbox` - Enable sandbox mode (default: from config)
* `:base_url` - Override base URL
* `:timeout` - Request timeout in milliseconds
* `:recv_timeout` - Receive timeout in milliseconds
## Examples
client = Meli.client(access_token: "tenant_token")
{:ok, payment} = Meli.Payment.create(params, client: client)
"""
@spec client(keyword()) :: Meli.Client.t()
def client(opts \\ []) do
Meli.Client.new(opts)
end
@doc """
Returns the configured access token.
"""
@spec access_token() :: String.t() | nil
def access_token do
Application.get_env(:meli, :access_token)
end
@doc """
Returns whether sandbox mode is enabled.
"""
@spec sandbox?() :: boolean()
def sandbox? do
Application.get_env(:meli, :sandbox, false)
end
end