I'm setting my webhook
STRIPE and i want to send message on Telegram
when happen event in STRIPE (checkout.session.completed
so after payment).
To set webhook is very easy so i'm sure the problem is really easy (just not for me).
\Stripe\Stripe::setApiKey('sk_test_xxx');
// You can find your endpoint's secret in your webhook settings
$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
http_response_code(400);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}
// Handle the checkout.session.completed event
if ($event->type == 'checkout.session.completed') {
$session = $event->data->object;
// Fulfill the purchase...
handle_checkout_session($session);
}
http_response_code(200);
If payment is successfull (so if $event->type == 'checkout.session.completed'
) i want to write a message on telegram.
To write message is very easy:
$url= 'https://api.telegram.org/botxxx/sendMessage?chat_id=xxx&parse_mode=HTML&text=ok-webhook';
file_get_contents($url);
Why doesn't work ?
I tried to put it (code to write message) inside last if
but nothing.
I know payment works because i can read the request to my endpoint and status code 200 (OK).
I hope you can help me...