LetsPay
Skip to content

Webhooks and testing

Verify signatures, handle repeat deliveries and test an integration without a transfer.

Payment event

LetsPay sends an HTTPS POST with an invoice.paid event to the webhook URL configured for the project. id is the LetsPay invoice ID, and order_id is your store reference. amount_minor and currency refer to the order price.

JSON
{
  "type": "invoice.paid",
  "id": "DEMO_0123456789abcdefghijklmnopq",
  "order_id": "order-1042",
  "currency": "EUR",
  "amount_minor": 2450,
  "status": "paid"
}

Verify the signature

Read the raw request bytes before decoding JSON. Compute HMAC-SHA256 using the signing key and the exact bytes of X-Pay-Timestamp, a literal dot and the raw body. Compare the lowercase hex digest to X-Pay-Signature in constant time. Keep the server clock synchronized and reject timestamps more than five minutes from now.

In PHP, read php://input for the body and HTTP_X_PAY_TIMESTAMP and HTTP_X_PAY_SIGNATURE from the request environment. Choose the project’s signing key from your server configuration.

PHP
function validLetsPaySignature(
    string $rawBody, string $timestamp, string $signature, string $key
): bool {
    if ($key === '' || !preg_match('/^[0-9]{1,12}$/D', $timestamp)
        || abs(time() - (int) $timestamp) > 300) {
        return false;
    }
    $expected = hash_hmac('sha256', $timestamp . '.' . $rawBody, $key);
    return hash_equals($expected, $signature);
}

Acknowledge and fulfil once

  1. For a sale require a valid live signature, type invoice.paid and status paid. Match the invoice ID, order ID, amount_minor and currency against the order stored on your server.
  2. Commit the paid transition and a unique fulfilment record together, keyed by project and invoice ID. If delivery happens in another service, commit an outbox job in the same transaction. A duplicate event should find the original result.
  3. After a successful commit, return HTTP 200 with the plain text body OK. A repeat of an already committed event gets the same acknowledgement. LetsPay retries unacknowledged live deliveries with increasing delays of up to one hour.

Send a test event

In the project, open Test integration and create test credentials. POST /v1/test/webhooks with the test bearer key returns HTTP 202, an id and queued. The receiver gets invoice.test with livemode set to false. Check it with the test signing key and acknowledge it without creating a paid order.

GET /v1/test/webhooks/{id} uses the same test API key and returns queued, sending, delivered or failed. Wait at least one minute between test events. The demo invoice also lets you explore the buyer experience without moving funds.

cURL
curl --request POST https://api.letspay.today/v1/test/webhooks \
  --header "Authorization: Bearer $LETSPAY_TEST_KEY"

curl "https://api.letspay.today/v1/test/webhooks/$TEST_EVENT_ID" \
  --header "Authorization: Bearer $LETSPAY_TEST_KEY"
Open the demo invoice