Skip to main content

Introducing Webhooks and Callbacks support in PHP and Go SDKs

· 2 min read

This enhancement allows developers to easily manage API notifications and event-driven workflows without extra setup. With type-safe handlers and configured signature verification, integration becomes simpler and more reliable.

Details

Webhooks and callbacks are widely used in APIs to deliver information asynchronously, notifying clients about events or providing results after a request has been initiated. Without SDK support, developers often need to write custom code for parsing payloads, verifying signatures, and mapping data. With this enhancement, PHP and Go SDKs automatically generate type-safe handlers and utilities, giving developers a consistent and reliable way to work with event-driven APIs.

What’s New in SDKs?

APIMatic now supports Webhooks and Callbacks in PHP and Go SDKs.

  • Type Safe Webhook Handlers
  • Type Safe Callback Handlers
  • HMAC Signature Verification

Usage Example

Developers can now verify signatures and handle webhook events with type-safe parsing:

// Create the handler with your shared secret key.
$handler = PaymentHandler::init('hmac-secret-key');

// Verify and parse the request into a typed event.
$result = $handler->verifyAndParse($request);

if ($result instanceof SignatureVerificationFailure) {
// TODO: add signature verification failure handling
return response("Received an event with invalid signature: {$result->getErrorMessage()}", 400);
} elseif ($result instanceof VerifiedPaymentEvent) {
// TODO: add handling logic
return response("Received an event of type FulfillmentCallback: $result");
} elseif ($result instanceof UnknownEvent) {
// TODO: add unknown event handling
return response("Received an unknown event with payload: {$result->getData()}", 400);
}

Learn more about webhooks and callbacks