Hi team,
Is there an example of a Revenuecat webhook endpoint that we can use in our backend php to fetch events data? we d'ont find a kind of information on documentation.
We need a sample like this one (used on stripe) bellow :
<?php
// webhook.php
\Stripe\Stripe::setApiKey('Your_Key');
$endpoint_secret = 'whsec_...';
$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
echo '⚠️ Webhook error while parsing basic request.';
http_response_code(400);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
echo '⚠️ Webhook error while validating signature.';
http_response_code(400);
exit();
}
// Handle the event
switch ($event->type) {
case 'customer.subscription.created':
// What to do
break;
case 'customer.subscription.deleted':
// What to do
break;
case 'customer.subscription.updated':
// What to do
break;
case 'invoice.payment_failed':
// What to do
break;
// ... handle other event types
default:
echo 'Received unknown event type ' . $event->type;
}
http_response_code(200);
?>
Thanks in advance.