Merchant
An Elixir client for the Revolut Merchant API (v2024-09-01). This library provides a type-safe and ergonomic interface for integrating with Revolut's payment processing services.
Features
- Complete API Coverage: Supports all major Revolut Merchant API endpoints
- Type Safety: Full Elixir type specifications for all data structures
- Structured Responses: Automatic conversion of JSON responses to Elixir structs
- Error Handling: Comprehensive error handling with proper error types
- Configuration: Easy configuration for different environments (sandbox/production)
Installation
Add merchant to your list of dependencies in mix.exs:
def deps do
[
{:merchant, "~> 0.1.0"}
]
endThen run:
mix deps.getConfiguration
API Keys
You'll need to configure your Revolut Merchant API credentials. Add the following to your configuration:
# config/config.exs
config :merchant,
api_key: System.get_env("REVOLUT_MERCHANT_API_KEY"),
base_url: System.get_env("REVOLUT_MERCHANT_BASE_URL", "https://sandbox-merchant.revolut.com")Environment Variables
Set your API credentials as environment variables:
# For sandbox testing
export REVOLUT_MERCHANT_API_KEY="your_sandbox_secret_key"
export REVOLUT_MERCHANT_BASE_URL="https://sandbox-merchant.revolut.com"
# For production
export REVOLUT_MERCHANT_API_KEY="your_production_secret_key"
export REVOLUT_MERCHANT_BASE_URL="https://merchant.revolut.com"Usage
Orders
Create, retrieve, update, and manage orders:
alias Merchant.Orders
# Create a new order
{:ok, order} = Orders.create(%{
amount: 1000, # Amount in minor units (e.g., cents)
currency: "USD",
description: "Test order",
capture_mode: "AUTOMATIC"
})
# Retrieve an order
{:ok, order} = Orders.retrieve("order_id")
# Update an order
{:ok, updated_order} = Orders.update("order_id", %{
description: "Updated description"
})API Versioning
This client supports the Revolut Merchant API version 2024-09-01. The API version is automatically included in requests where required.
Error Handling
All functions return either {:ok, result} or {:error, error} tuples except the bang functions:
case Orders.create(order_params) do
{:ok, order} ->
# Handle successful order creation
IO.puts("Order created: #{order.id}")
{:error, error} ->
# Handle error
IO.puts("Error creating order: #{inspect(error)}")
endData Structures
The library provides comprehensive type definitions for all API data structures:
Merchant.OrderV4- Order objectsMerchant.Customer- Customer objectsMerchant.PaymentV2- Payment objectsMerchant.LineItem- Line item objectsMerchant.Shipping- Shipping informationMerchant.Metadata- Metadata objects- And more...
Development
Running Tests
mix testCode Quality
# Run all consistency checks
mix consistency
# Format code
mix format
# Run Credo for code analysis
mix credo
# Run Dialyzer for type checking
mix dialyzerAPI Documentation
For detailed information about the Revolut Merchant API, visit:
Contributing
- Fork the repository
-
Create a feature branch (
git checkout -b feature/amazing-feature) -
Commit your changes (
git commit -m 'Add amazing feature') -
Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues related to this Elixir client, please open an issue on GitHub.
For Revolut Merchant API support, visit the Revolut Developer Portal.