Invoicing Quickstart#

Create professional invoices, manage line items, apply tax rates, and automate PDF generation. Invoices integrate with CasaPay Payments for automated collection.

Step 1: Create a Customer#

First, create a customer record for the tenant:

curl https://api.casapay.com/v1/customers \
  -H "Authorization: Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Jane Doe",
    "email": "jane.doe@example.com",
    "metadata": {
      "property_id": "prop_456",
      "unit": "4B"
    }
  }'

Step 2: Create an Invoice#

Create a draft invoice with line items:

curl https://api.casapay.com/v1/invoices \
  -H "Authorization: Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "cus_123456789",
    "due_date": 1708732800,
    "line_items": [
      {
        "description": "Monthly rent — Unit 4B",
        "amount": 120000,
        "currency": "eur"
      },
      {
        "description": "Parking space",
        "amount": 5000,
        "currency": "eur"
      }
    ],
    "metadata": {
      "lease_id": "lease_789",
      "period": "2025-02"
    }
  }'
{
  "id": "inv_abc123",
  "object": "invoice",
  "customer": "cus_123456789",
  "status": "draft",
  "amount_due": 125000,
  "currency": "eur",
  "due_date": 1708732800,
  "line_items": [
    { "description": "Monthly rent — Unit 4B", "amount": 120000 },
    { "description": "Parking space", "amount": 5000 }
  ],
  "created": 1706140800
}

Step 3: Finalize and Send#

Finalize the invoice to lock it, then send it to the tenant:

# Finalize the invoice
curl -X POST https://api.casapay.com/v1/invoices/inv_abc123/finalize \
  -H "Authorization: Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc"

# Send the invoice via email
curl -X POST https://api.casapay.com/v1/invoices/inv_abc123/send \
  -H "Authorization: Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc"
{
  "id": "inv_abc123",
  "status": "open",
  "pdf_url": "https://files.casapay.com/invoices/inv_abc123.pdf",
  "hosted_invoice_url": "https://pay.casapay.com/inv/inv_abc123"
}

Step 4: Track Payment#

Listen for the invoice.paid webhook to know when the tenant pays:

app.post('/webhooks/casapay', async (req, res) => {
  const event = req.body;

  if (event.type === 'invoice.paid') {
    const invoice = event.data.object;
    console.log(`Invoice ${invoice.id} paid: ${invoice.amount_due / 100} EUR`);
    await markRentAsPaid(invoice.metadata.lease_id, invoice.metadata.period);
  }

  res.status(200).send();
});

That's it!

You've created, sent, and tracked an invoice. Explore the API reference for recurring invoices, credit notes, tax rates, and template customization.


Alternative: Alias-Based Invoicing#

Don't want to integrate the full API? Use alias-based invoicing — a low-code approach where CasaPay generates a unique email alias (e.g., jane.doe@casapay.me) for each tenant. Send your PDF invoices to that alias from any PMS, accounting tool, or email, and CasaPay automatically converts them into payment requests.

# Generate an alias for a tenant
curl https://api.casapay.com/v1/email_aliases \
  -H "Authorization: Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc" \
  -H "Content-Type: application/json" \
  -d '{
    "tenant_email": "jane.doe@example.com",
    "entity_id": "ent_456def"
  }'
{
  "id": "alias_abc123",
  "email": "jane.doe@casapay.me",
  "tenant": "cus_new789",
  "status": "active"
}

Now just send your invoice PDFs to jane.doe@casapay.me — CasaPay handles extraction, payment link generation, and tenant notification.

Learn more about alias-based invoicing