PrinPoll developer docs

Developers

Webhooks

Receive payment, vote, and ticket events and verify their signatures.

Events

EventData fields
payment.succeededreference, event_id, event_type, kind, amount, currency, channel, paid_at
vote.recordedreference, event_id, event_type, nominee_id, category_id, votes, nominee_total_votes
ticket.issuedreference, event_id, event_type, ticket_types[{ticket_type_id, quantity}], quantity

Each delivery body has id, type, created_at, livemode, and data. Payloads do not include payer phone numbers, ticket codes, or ticket-holder contact details. Payments for API events from any channel can produce events; channel identifies api, widget, website, ussd, or whatsapp as stated by the contract.

Payloads

payment.succeeded payload shape

payment.succeeded payload shape

{
  "id": "evt_example",
  "type": "payment.succeeded",
  "created_at": "2030-01-02T12:00:00Z",
  "livemode": true,
  "data": {
    "reference": "PAYMENT_REFERENCE",
    "event_id": "EVENT_ID",
    "event_type": "vote",
    "kind": "vote",
    "amount": 300,
    "currency": "GHS",
    "channel": "api",
    "paid_at": "2030-01-02T12:00:00Z"
  }
}
vote.recorded payload shape

vote.recorded payload shape

{
  "id": "evt_example",
  "type": "vote.recorded",
  "created_at": "2030-01-02T12:00:00Z",
  "livemode": true,
  "data": {
    "reference": "PAYMENT_REFERENCE",
    "event_id": "EVENT_ID",
    "event_type": "vote",
    "nominee_id": "NOMINEE_ID",
    "category_id": "CATEGORY_ID",
    "votes": 3,
    "nominee_total_votes": 18
  }
}
ticket.issued payload shape

ticket.issued payload shape

{
  "id": "evt_example",
  "type": "ticket.issued",
  "created_at": "2030-01-02T12:00:00Z",
  "livemode": true,
  "data": {
    "reference": "PAYMENT_REFERENCE",
    "event_id": "EVENT_ID",
    "event_type": "ticket",
    "ticket_types": [{ "ticket_type_id": "TICKET_TYPE_ID", "quantity": 2 }],
    "quantity": 2
  }
}

Verify the signature

PrinPoll sends PrinPoll-Signature in the form t=<unix>,v1=<hex HMAC-SHA256>. The signed input is the timestamp, a dot, and the exact raw request body. Compare signatures in constant time and reject timestamps more than five minutes old. Use the raw bytes before parsing JSON.

Python signature verification

Python signature verification

import hashlib
import hmac
import time

secret = "whsec_xxx"
raw_body = request.get_data()
header = request.headers["PrinPoll-Signature"]
timestamp = None
signatures = []
for part in header.split(","):
    key, value = part.split("=", 1)
    if key == "t":
        timestamp = value
    elif key == "v1":
        signatures.append(value)
if timestamp is None:
    raise ValueError("Invalid webhook signature")
expected = hmac.new(
    secret.encode(),
    timestamp.encode() + b"." + raw_body,
    hashlib.sha256,
).hexdigest()
valid = abs(time.time() - int(timestamp)) <= 300 and any(
    hmac.compare_digest(signature, expected) for signature in signatures
)
if not valid:
    raise ValueError("Invalid webhook signature")
JavaScript signature verification

JavaScript signature verification

import crypto from "node:crypto";

const secret = "whsec_xxx";
const rawBody = requestBodyBuffer;
const header = request.headers["prinpoll-signature"];
const parts = header.split(",").map((part) => part.split("=", 2));
const timestamp = parts.find(([key]) => key === "t")?.[1];
const signatures = parts.filter(([key]) => key === "v1").map(([, value]) => value);
if (!timestamp) throw new Error("Invalid webhook signature");
const expected = crypto.createHmac("sha256", secret)
  .update(timestamp + ".")
  .update(rawBody)
  .digest();
const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) <= 300;
const valid = fresh && signatures.some((signature) => {
  const supplied = Buffer.from(signature, "hex");
  return supplied.length === expected.length && crypto.timingSafeEqual(supplied, expected);
});
if (!valid) throw new Error("Invalid webhook signature");
PHP signature verification

PHP signature verification

<?php
$secret = "whsec_xxx";
$rawBody = file_get_contents("php://input");
$header = $_SERVER["HTTP_PRINPOLL_SIGNATURE"];
$timestamp = null;
$signatures = [];
foreach (explode(",", $header) as $part) {
    [$key, $value] = explode("=", $part, 2);
    if ($key === "t") $timestamp = $value;
    if ($key === "v1") $signatures[] = $value;
}
if ($timestamp === null) throw new RuntimeException("Invalid webhook signature");
$expected = hash_hmac("sha256", $timestamp . "." . $rawBody, $secret);
$fresh = abs(time() - (int) $timestamp) <= 300;
$valid = $fresh && array_reduce(
    $signatures,
    fn ($matched, $signature) => $matched || hash_equals($expected, $signature),
    false
);
if (!$valid) throw new RuntimeException("Invalid webhook signature");

Retries and delivery log

A 2xx response within 10 seconds marks a delivery successful. Failed delivery attempts are retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours, and 24 hours; after the final attempt the delivery is dead. An endpoint is disabled after 3 days of failures.

Each attempt is retained in the organizer dashboard delivery log. Failed or dead deliveries can be retried manually. A broken endpoint does not prevent other endpoints from receiving their deliveries.

Test webhooks

The Developers dashboard can send a signed webhook.test delivery immediately. A test delivery is not retried. Use it to validate your receiver and inspect the resulting delivery status in the dashboard.