Product
Solutions
Developers & Resources
Developer Guides • 8 min read

The Developer's Guide to Automating Client Billing with Payeny Webhooks and REST API

Payeny
Payeny
Editorial Team • Published August 14, 2026

Building billing workflows manually is one of the most error-prone areas of software engineering. Payeny exposes a clean REST API and a real-time event pipeline designed to bridge client agreements directly to automated provisioning.

1. System Architecture Overview

Payeny follows an event-driven architecture. Whenever a client executes a state-changing action—such as viewing a proposal, drawing a signature, or completing checkout—an event is dispatched to your registered endpoints:

[Client Action: Signed Contract]
    ↓
[Payeny Core Engine verifies signature & generates invoice]
    ↓
[Event Dispatcher fires "contract.executed" & "invoice.created"]
    ↓
[Your App Webhook Endpoint validates HMAC signature]
    ↓
[Automated Provisioning: Creates repo, invites client to Slack, alerts team]

2. Core Billing Lifecycle Events

Event Type Trigger Condition Common Automation Action
proposal.signed Client accepted proposal pricing tier Notify sales lead, prepare contract
contract.executed All parties submitted valid eSignatures Create project repository, generate kickoff ticket
invoice.paid Payment gateway settled funds Unlock deliverable lockbox, provision client space
deliverable.unlocked Client downloaded paid file assets Send satisfaction survey, log milestone

3. Verifying HMAC-SHA256 Signatures

Every outbound Payeny webhook includes a secure signature header: X-Payeny-Signature. You must always verify this cryptographic signature against your endpoint webhook secret before trusting the incoming payload.

4. Complete Webhook Handler (Node.js & PHP)

Node.js / Express Example:
const crypto = require('crypto');
const express = require('express');
const app = express();

app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-payeny-signature'];
  const secret = process.env.PAYENY_WEBHOOK_SECRET;

  const expectedSignature = crypto
    .createHmac('sha256', secret)
    .update(req.body)
    .digest('hex');

  if (signature !== expectedSignature) {
    return res.status(401).send('Invalid signature');
  }

  const event = JSON.parse(req.body.toString());

  switch (event.type) {
    case 'invoice.paid':
      const invoice = event.data;
      console.log(`Payment confirmed for invoice ${invoice.id}: $${invoice.total}`);
      // Trigger your downstream provisioning logic here
      break;
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

  res.json({ received: true });
});
PHP Example:
<?php
$payload = file_get_contents('php://input');
$sigHeader = $_SERVER['HTTP_X_PAYENY_SIGNATURE'] ?? '';
$secret = getenv('PAYENY_WEBHOOK_SECRET');

$computed = hash_hmac('sha256', $payload, $secret);

if (!hash_equals($computed, $sigHeader)) {
    http_response_code(401);
    die('Invalid signature');
}

$event = json_decode($payload, true);

if ($event['type'] === 'invoice.paid') {
    // Process successful invoice payment
}

http_response_code(200);
echo json_encode(['received' => true]);

5. Local Webhook Testing & Best Practices

  • Always return 200 OK immediately: Do not perform long-running background tasks inside the synchronous webhook handler; push jobs to a queue (Redis / RabbitMQ).
  • Implement idempotency: Store processed event.ids to prevent duplicate action if an event is redelivered.
  • Use test mode keys: Develop with test API tokens and simulated events in the Payeny Developer Dashboard before going live.
Filed under: API Webhooks Developers Automation Stripe
RUN YOUR BUSINESS WITH INTENTION

Experience the unified client-to-cash workflow

Put an end to disconnected spreadsheets, PDF invoices, and slow bank transfers. Free to use with zero monthly fees.

Start Free • Pay Only When You Get Paid
CONTINUE READING

Recommended playbooks

Agency Growth

The Complete Guide to the Client-to-Cash Workflow: How to Slash Admin Hours and Get Paid in 48 Hours

Traditional service businesses waste 12+ hours every week juggling disparate tools between proposals, contracts, invoices, and payments. Here is how connecting the entire lifecycle into one unified pipeline accelerates revenue.

Read Guide
Contracts & Legal

Freelance Contracts & eSignatures: What Every Creative and Consultant Must Include in 2026

A handshake or casual email agreement might seem friendly until a project spirals into scope creep or late payments. Here is how legally enforceable digital contracts protect your livelihood.

Read Guide
Client Spaces

Why Branded Client Portals Convert 3x More Referrals and Upsells Than Chaotic Email Threads

Client perception of your work is deeply influenced by the container it arrives in. How dedicated, white-label client spaces turn one-off gigs into long-term retainer partnerships.

Read Guide