Späw Documentation
Démarrage

Premier abonnement en 4 appels

Du client au premier débit : le parcours minimal pour encaisser un abonnement.

1. Créer le client

Seul le nom est obligatoire. L'e-mail sert à envoyer les avis de prélèvement et à ouvrir son espace payeur.

curl -X POST https://xn--spw-rla.com/v1/customers \
  -H "Authorization: Bearer spaw_sk_VOTRE_CLE" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Camille Martin",
    "email": "camille@example.org"
  }'
const res = await fetch('https://xn--spw-rla.com/v1/customers', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SPAW_SECRET_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "name": "Camille Martin",
    "email": "camille@example.org"
  }),
});
const data = await res.json();
Réponse
{
  "id": "cus_42",
  "object": "customer",
  "name": "Camille Martin",
  "email": "camille@example.org",
  "address": {
    "line1": "12 rue des Lilas",
    "postal_code": "75011",
    "city": "Paris",
    "country": "FR"
  },
  "created": "2026-11-16T09:12:44.000Z"
}

2. Enregistrer son mandat

Transmettez l'IBAN et la preuve d'acceptation. Si votre client a validé le mandat sur votre page, envoyez son adresse IP et son navigateur (online). Si vous détenez un mandat signé, envoyez sa date de signature (offline).

L'IBAN complet n'est jamais conservé ni renvoyé : seuls le pays et les 4 derniers caractères le sont.

curl -X POST https://xn--spw-rla.com/v1/mandates \
  -H "Authorization: Bearer spaw_sk_VOTRE_CLE" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "cus_42",
    "iban": "FR1420041010050500013M02606",
    "acceptance": {
      "type": "online",
      "ip": "203.0.113.7",
      "user_agent": "Mozilla/5.0"
    }
  }'
const res = await fetch('https://xn--spw-rla.com/v1/mandates', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SPAW_SECRET_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "customer": "cus_42",
    "iban": "FR1420041010050500013M02606",
    "acceptance": {
      "type": "online",
      "ip": "203.0.113.7",
      "user_agent": "Mozilla/5.0"
    }
  }),
});
const data = await res.json();
Réponse
{
  "id": "mdt_17",
  "object": "mandate",
  "customer": "cus_42",
  "status": "active",
  "scheme": "sepa_core",
  "reference": "PF0003-9C41D2E07A5B6F18",
  "bank_account": {
    "country": "FR",
    "last4": "2606"
  },
  "acceptance": {
    "type": "online",
    "accepted_at": "2026-11-16T09:13:02.000Z"
  },
  "provider": "gocardless",
  "created": "2026-11-16T09:13:02.000Z",
  "cancelled_at": null
}

3. Lancer l'abonnement

Indiquez un produit, ou bien un montant, une fréquence et un libellé. Si la première échéance est aujourd'hui, le prélèvement est émis immédiatement.

curl -X POST https://xn--spw-rla.com/v1/subscriptions \
  -H "Authorization: Bearer spaw_sk_VOTRE_CLE" \
  -H "Content-Type: application/json" \
  -d '{
    "mandate": "mdt_17",
    "product": "prod_5"
  }'
const res = await fetch('https://xn--spw-rla.com/v1/subscriptions', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SPAW_SECRET_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "mandate": "mdt_17",
    "product": "prod_5"
  }),
});
const data = await res.json();
Réponse
{
  "id": "sub_31",
  "object": "subscription",
  "customer": "cus_42",
  "mandate": "mdt_17",
  "product": "prod_5",
  "description": "Abonnement Pro",
  "amount": 4900,
  "currency": "eur",
  "interval": "monthly",
  "status": "active",
  "start_date": "2026-11-16",
  "next_charge_date": "2026-12-16",
  "max_occurrences": null,
  "occurrences_done": 1,
  "created": "2026-11-16T09:13:05.000Z",
  "cancelled_at": null
}

4. Suivre les prélèvements

Un prélèvement SEPA reste pending quelques jours avant d'être confirmé par les banques. Plutôt que d'interroger l'API en boucle, abonnez-vous aux webhooks payment.paid et payment.failed.

curl https://xn--spw-rla.com/v1/payments?subscription=sub_31 \
  -H "Authorization: Bearer spaw_sk_VOTRE_CLE"
const res = await fetch('https://xn--spw-rla.com/v1/payments?subscription=sub_31', {
  method: 'GET',
  headers: {
    Authorization: `Bearer ${process.env.SPAW_SECRET_KEY}`,
  },
});
const data = await res.json();
Réponse
{
  "object": "list",
  "data": [
    {
      "id": "pay_208",
      "object": "payment",
      "customer": "cus_42",
      "mandate": "mdt_17",
      "subscription": "sub_31",
      "amount": 4900,
      "fee": 74,
      "net": 4826,
      "currency": "eur",
      "status": "pending",
      "description": "Abonnement Pro — échéance du 16 nov. 2026",
      "failure_reason": null,
      "period_date": "2026-11-16",
      "provider": "gocardless",
      "created": "2026-11-16T09:13:05.000Z",
      "updated": "2026-11-16T09:13:05.000Z"
    }
  ],
  "has_more": false
}