UniRate-API

payload plugin unirate

by UniRate-API
Third-party services
v3
>=3.0.0
MIT

Overview

Summary generated from the README

Connects Payload v3 to the UniRate API for currency exchange rates and VAT data. It adds four custom endpoints under /api/unirate and keeps the API key on the server. It also exports a currency select field helper and a typed client with error classes. Requires a UniRate API key and Payload 3.0.0 or later.

Features

  • Endpoints for exchange rate, amount conversion, supported currencies and VAT rates
  • API key stays server-side, read from an option or the UNIRATE_API_KEY environment variable
  • currencyField helper builds a select field prefilled with ISO-4217 codes
  • Exported UniRateClient with typed errors for auth, rate limit and Pro plan requirements
  • Upstream errors mapped to HTTP statuses; returns 503 when no key is configured
  • Configurable base URL, request timeout and a disabled switch; no runtime dependencies

Use cases

  • Convert product prices between currencies from the frontend without exposing the API key
  • Add a currency code select to product or order collections
  • Look up VAT rates by country in custom hooks or endpoints

From the author

Payload CMS v3 plugin for the UniRate currency-exchange API — server-side proxy endpoints (rate/convert/currencies/vat) and a prefilled currency select field. Zero runtime deps.

Installation

npm i payload-plugin-unirate

0

Stars

0

Forks

0

Open Issues

3 months ago

Last Updated

0

Weekly Downloads

v0.1.0

npm Version

49.3 KB

Unpacked Size

0

Dependencies

GitHub stars

Trends appear after 7 days of data. Collecting since Oct 22 — 6 daily snapshots so far.

npm weekly downloads

Trends appear after 7 days of data. Collecting since Oct 22 — 6 daily snapshots so far.

Each point is npm's rolling 7-day download count.

Health Score

48/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1315674283-root.svg)](https://payloaddirectory.dev/plugins/1315674283-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1315674283-root"><img src="https://payloaddirectory.dev/badge/1315674283-root.svg" alt="Payload Directory"></a>
Updated Jul 29, 2026Created Jul 29, 2026Published Jul 29, 2026

README

payload-plugin-unirate

A Payload CMS v3 plugin that integrates the UniRate API for currency exchange rates and VAT data. It appends four server-side endpoints under /api/unirate and ships an optional prefilled currency select field — your API key stays server-side, never exposed to clients. Zero runtime dependencies (payload is a peer).

Install

npm install payload-plugin-unirate

Requires Payload >=3.0.0 (peer dependency) and Node >=18.20.

Quick start

// payload.config.ts
import { buildConfig } from "payload";
import { uniratePlugin } from "payload-plugin-unirate";

export default buildConfig({
  // ...your usual config
  plugins: [
    uniratePlugin({
      apiKey: process.env.UNIRATE_API_KEY, // or omit and set the env var
    }),
  ],
});

Set your key (recommended over inlining it):

UNIRATE_API_KEY=your_key_here

Options

uniratePlugin(options):

OptionTypeDefaultDescription
apiKeystringprocess.env.UNIRATE_API_KEYUniRate API key (stays server-side).
baseUrlstringhttps://api.unirateapi.comAPI base URL.
disabledbooleanfalseWhen true, the plugin is a no-op and adds no endpoints.
timeoutMsnumber30000Per-request timeout.

Endpoints

The plugin appends these custom endpoints (Payload serves custom endpoints under the /api prefix):

MethodPathDescription
GET/api/unirate/rate?from=USD&to=EURExchange rate (single, or all rates for a base when to is omitted)
GET/api/unirate/convert?from=USD&to=EUR&amount=100Convert an amount
GET/api/unirate/currenciesList supported currencies
GET/api/unirate/vat?country=DEVAT rates (optional country filter)

Example:

curl "http://localhost:3000/api/unirate/convert?from=USD&to=EUR&amount=100"
# → { "from": "USD", "to": "EUR", "amount": 100, "result": 92.00 }

When no API key is configured, the endpoints respond 503 (and log a warning) rather than crashing at boot.

Currency select field

An exported helper builds a Payload select field prefilled with common ISO-4217 currency codes:

import { currencyField } from "payload-plugin-unirate";

const Products = {
  slug: "products",
  fields: [
    { name: "title", type: "text" },
    currencyField({ name: "priceCurrency", defaultValue: "USD", required: true }),
  ],
};

Pass options: ["USD", "EUR", ...] to override the code list, or fetch the live list from /api/unirate/currencies.

Error handling

Endpoint responses map upstream UniRate errors to the appropriate HTTP status:

StatusMeaning
400Invalid request parameters
401Missing or invalid API key
403Endpoint requires a Pro subscription
404Currency not found / no data
429Rate limit exceeded
503Service unavailable / plugin not configured
502Upstream/transport failure

The internal client and its typed error classes are also exported for direct use in hooks or custom endpoints:

import { UniRateClient, AuthenticationError, RateLimitError, ProRequiredError } from "payload-plugin-unirate";

const client = new UniRateClient({ apiKey: process.env.UNIRATE_API_KEY! });
try {
  const rate = await client.getRate("USD", "EUR"); // → 0.92
} catch (err) {
  if (err instanceof AuthenticationError) { /* invalid key */ }
  if (err instanceof RateLimitError)      { /* slow down */   }
  if (err instanceof ProRequiredError)    { /* upgrade plan */ }
}

Free vs Pro tier

Free-tier endpoints: rates, convert, currencies, VAT rates. Historical data and time series require a Pro subscription.

UniRate API client libraries: Python · Node.js · Go · Rust · Ruby · PHP · Java · Swift · .NET

Framework integrations: Next.js · Nuxt · SvelteKit · Astro · NestJS · Eleventy · React · Vue · tRPC

CMS & e-commerce: WordPress · Directus · Strapi · Payload (this package) · Medusa · Hugo · Jekyll

Data & AI: LangChain Python · LangChain.js · FastAPI · Flask · Django REST · dbt · Airflow

Other: MCP server · CLI · Obsidian · money gem · laravel-money

License

MIT © Unirate Team

Similar plugins