lomi.

Produits

Gérez les produits, les tarifs et la configuration des abonnements.

L’API Products permet de gérer votre catalogue. Un produit représente un article ou un service ; chaque produit peut avoir jusqu’à 3 tarifs actifs.

Créer un produit

Crée un produit avec un ou plusieurs tarifs. Au moins un tarif est obligatoire.

Référence API (schéma complet) : Créer un produit

L’essentiel :

  • name, product_type (one_time, recurring, usage_based) et un tableau prices sont obligatoires.
  • Chaque tarif exige amount et currency_code. Pour un produit récurrent, ajoutez billing_interval sur le tarif.
  • Champs réservés au récurrent : trial_enabled, trial_period_days, failed_payment_action, charge_day, first_payment_type: voir la page API.
  • Produits à l’usage : usage_aggregation, usage_unit: voir la page API.

Métadonnées optionnelles pour les produits récurrents (via metadata à la création / mise à jour) : subscription_length ("automatic" par défaut) et fixed_charges (nombre entier de cycles avant expiration). Ce ne sont pas des champs API de premier niveau ; stockez-les dans metadata.

Payez ce que vous voulez (pricing_model: pay_what_you_want, ponctuel uniquement) : minimum_amount est obligatoire ; amount est le prix unitaire suggéré. Le serveur impose amount >= minimum_amount et le maximum_amount optionnel. Champs tarif complets : Créer un produit.

import { LomiSDK } from '@lomi./sdk';

const lomi = new LomiSDK({
  apiKey: process.env.LOMI_SECRET_KEY!,
  environment: 'live',
});

// One-time product
const product = await lomi.products.create({
  name: 'E-book Bundle',
  description: 'Collection de guides complète',
  product_type: 'one_time',
  prices: [
    {
      amount: 25000,
      currency_code: 'XOF',
      is_default: true,
    },
  ],
  display_on_storefront: true,
});

// Subscription product with trial
const subscription = await lomi.products.create({
  name: 'Premium Plan',
  description: 'Accès premium mensuel',
  product_type: 'recurring',
  prices: [
    {
      amount: 10000,
      currency_code: 'XOF',
      billing_interval: 'month',
      is_default: true,
    },
  ],
  trial_enabled: true,
  trial_period_days: 14,
  failed_payment_action: 'continue',
});

// Pay what you want (one-time only)
const tipJar = await lomi.products.create({
  name: 'Community tip jar',
  product_type: 'one_time',
  prices: [
    {
      pricing_model: 'pay_what_you_want',
      amount: 1000,
      minimum_amount: 500,
      maximum_amount: 5000,
      currency_code: 'XOF',
      is_default: true,
    },
  ],
});

console.log(`Product created: ${product.product_id}`);
from lomi import LomiClient
import os

client = LomiClient(
    api_key=os.environ["LOMI_SECRET_KEY"],
    environment="test"
)

# One-time product
product = client.products.create({
    "name": "E-book Bundle",
    "description": "Collection de guides complète",
    "product_type": "one_time",
    "prices": [
        {
            "amount": 25000,
            "currency_code": "XOF",
            "is_default": True
        }
    ],
    "display_on_storefront": True
})

# Pay what you want (one-time only)
tip_jar = client.products.create({
    "name": "Community tip jar",
    "product_type": "one_time",
    "prices": [
        {
            "pricing_model": "pay_what_you_want",
            "amount": 1000,
            "minimum_amount": 500,
            "maximum_amount": 5000,
            "currency_code": "XOF",
            "is_default": True
        }
    ]
})

print(f"Product created: {product['product_id']}")
curl -X POST "https://api.lomi.africa/products" \
  -H "X-API-KEY: $LOMI_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "E-book Bundle",
    "description": "Collection de guides complète",
    "product_type": "one_time",
    "prices": [
      {
        "amount": 25000,
        "currency_code": "XOF",
        "is_default": true
      }
    ],
    "display_on_storefront": true
  }'

# Pay what you want (one-time only)
curl -X POST "https://api.lomi.africa/products" \
  -H "X-API-KEY: $LOMI_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Community tip jar",
    "product_type": "one_time",
    "prices": [
      {
        "pricing_model": "pay_what_you_want",
        "amount": 1000,
        "minimum_amount": 500,
        "maximum_amount": 5000,
        "currency_code": "XOF",
        "is_default": true
      }
    ]
  }'

Lister les produits

Référence API : Lister les produits, isActive, limit et offset.

const products = await lomi.products.list({
  isActive: true,
  limit: 20,
});
products = client.products.list(isActive=True, limit=20)
curl -X GET "https://api.lomi.africa/products?isActive=true&limit=20" \
  -H "X-API-KEY: $LOMI_SECRET_KEY"

Obtenir un produit

Référence API : Obtenir un produit, renvoie le produit et tous ses tarifs.

const product = await lomi.products.get('prod_abc123...');
console.log(`Default price: ${product.prices.find(p => p.is_default)?.amount}`);
product = client.products.get('prod_abc123...')
curl -X GET "https://api.lomi.africa/products/prod_abc123..." \
  -H "X-API-KEY: $LOMI_SECRET_KEY"

Ajouter un tarif à un produit

Référence API : Ajouter un tarif

Un produit peut compter au maximum 3 tarifs actifs. Les tarifs existants ne se modifient pas, créez-en un nouveau.

const price = await lomi.products.addPrice('prod_abc123...', {
  amount: 50000,
  currency_code: 'XOF',
  billing_interval: 'year',
});

console.log(`New price added: ${price.price_id}`);

// Pay what you want price
const pwywPrice = await lomi.products.addPrice('prod_abc123...', {
  pricing_model: 'pay_what_you_want',
  amount: 1000,
  minimum_amount: 500,
  maximum_amount: 5000,
  currency_code: 'XOF',
});
price = client.products.add_price('prod_abc123...', {
    "amount": 50000,
    "currency_code": "XOF",
    "billing_interval": "year"
})
curl -X POST "https://api.lomi.africa/products/prod_abc123.../prices" \
  -H "X-API-KEY: $LOMI_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 50000,
    "currency_code": "XOF",
    "billing_interval": "year"
  }'

Définir le tarif par défaut

Référence API : Définir le tarif par défaut

const product = await lomi.products.setDefaultPrice('prod_abc123...', 'price_def456...');
product = client.products.set_default_price('prod_abc123...', 'price_def456...')
curl -X POST "https://api.lomi.africa/products/prod_abc123.../prices/price_def456.../set-default" \
  -H "X-API-KEY: $LOMI_SECRET_KEY"

API associée

Sur cette page