Automate Your E-commerce Invoicing with PineBill

Published: (December 7, 2025 at 06:51 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

What PineBill Offers

PineBill is an invoicing SaaS with 23 API endpoints covering:

  • Invoices – Create, read, update invoices
  • Customers – Full CRUD operations
  • Products – Inventory management (7 endpoints)
  • Categories – Product organization
  • Payment Methods – Transaction processing options
  • Exchange Rates – Multi‑currency support

The API follows the OpenAPI 3.1 specification, uses Bearer token authentication, and runs on a global CDN with 99.99 % uptime.

Getting Started

1. Get Your API Key

Sign up on PineBill and navigate to the dashboard. Generate an API key from the API Keys section.

Plans

PlanPriceAPI Calls
Pro$29 /month10,000 calls/month
Enterprise$90 /monthUnlimited calls

2. Base URL and Authentication

All API requests go to:

https://api.pinebill.app

Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Core Integrations for E-commerce

Creating an Invoice Programmatically

When a customer completes a purchase, trigger an invoice creation:

const createInvoice = async (orderData) => {
  const response = await fetch('https://api.pinebill.app/invoices', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      products: orderData.productIds,
      customerID: orderData.customerId,
      paymentMethods: ['pm_card', 'pm_bank_transfer'],
      invoiceMode: 'PRODUCT',
      taxRate: 10,
      taxType: 'PERCENT',
      issueDate: new Date().toISOString().split('T')[0],
      currency: 'USD'
    })
  });

  return response.json();
};

Syncing Customers from Your Platform

Create corresponding customer records in PineBill when users register:

const syncCustomer = async (user) => {
  const response = await fetch('https://api.pinebill.app/customers', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: user.fullName,
      email: user.email,
      phone: user.phone,
      address: user.billingAddress
    })
  });

  const customer = await response.json();
  // Store customer.id in your database for future invoices
  return customer;
};

Managing Products

Keep your product catalog in sync:

// Create a product
const createProduct = async (product) => {
  const response = await fetch('https://api.pinebill.app/products', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: product.name,
      price: product.price,
      description: product.description,
      categoryId: product.categoryId
    })
  });

  return response.json();
};

// Toggle product status (active/inactive)
const toggleProductStatus = async (productId) => {
  await fetch(`https://api.pinebill.app/products/${productId}/toggle-status`, {
    method: 'PATCH',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });
};

// Duplicate a product
const duplicateProduct = async (productId) => {
  const response = await fetch(`https://api.pinebill.app/products/${productId}/duplicate`, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });

  return response.json();
};

Multi‑Currency Support

Retrieve real‑time exchange rates for international invoices:

const getExchangeRates = async () => {
  const response = await fetch('https://api.pinebill.app/exchange-rates/latest', {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });

  return response.json();
};

Use the rates when creating invoices for customers in different currencies.

Real‑World Integration Patterns

E‑commerce Order Webhook Handler

// Express.js webhook handler example
app.post('/webhooks/order-completed', async (req, res) => {
  const order = req.body;

  try {
    // 1. Ensure customer exists
    let customer = await findCustomerByEmail(order.customer.email);
    if (!customer) {
      customer = await syncCustomer(order.customer);
    }

    // 2. Map order items to PineBill product IDs
    const productIds = await mapOrderItemsToProducts(order.items);

    // 3. Create invoice
    const invoice = await createInvoice({
      productIds,
      customerId: customer.id
    });

    // 4. Store invoice reference
    await saveInvoiceReference(order.id, invoice.invoiceNumber);

    res.status(200).json({ success: true, invoiceNumber: invoice.invoiceNumber });
  } catch (error) {
    console.error('Invoice creation failed:', error);
    res.status(500).json({ error: 'Failed to create invoice' });
  }
});

Subscription Platform Integration

Automate recurring invoices for SaaS or subscription businesses:

// Cron job for monthly billing
const processMonthlySubscriptions = async () => {
  const activeSubscriptions = await getActiveSubscriptions();

  for (const subscription of activeSubscriptions) {
    const response = await fetch('https://api.pinebill.app/invoices', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        // payload details would go here
      })
    });
    // handle response...
  }
};
Back to Blog

Related posts

Read more »