#Mickadelyon

1 messages · Page 1 of 1 (latest)

quasi spireBOT
carmine citrus
#

hello

#

Here is my secret code.php contains my secret key, endpoints key and signature <?php
require_once '../vendor/autoload.php';
//Ma clefs secréte et La clefs secréte de mon webhook
require_once '../secrets.php';

include '../../inc/fonctions.php';
//affichage des erreurs troue = affiche false = n'affiche pas
toggleErrorReporting(true);

// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys

// Configurez votre clé secrète de l'API Stripe
\Stripe\Stripe::setApiKey($stripeSecretKey);
// If you are testing your webhook locally with the Stripe CLI you
// can find the endpoint's secret by running stripe listen
// Otherwise, find your endpoint's secret in your webhook settings in the Developer Dashboard

$payload = @file_get_contents('php://input');
$signature = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;

try {
$event = \Stripe\Webhook::constructEvent(
$payload, $signature, $webhookSecret
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}

// Handle the event
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
handlePaymentIntentSucceeded($paymentIntent);
break;
case 'payment_method.attached':
$paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod
handlePaymentMethodAttached($paymentMethod);
break;
// ... handle other event types
default:
echo 'Received unknown event type ' . $event->type;
}

http_response_code(200);

desert shell
#

Are you calling the webhook endpoint yourself?

carmine citrus
#

Yes on $webhookSecret

desert shell
#

You shouldn't call the webhook endpoint yourself. It exists for Stripe server to communicate to your application.
You can read more here: https://stripe.com/docs/webhooks

carmine citrus
#

this is what i have on screen Warning: Undefined array key "HTTP_STRIPE_SIGNATURE" in /home/cvdumog/www/paiement/public/index.php on line 20

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home/cvdumog/www/paiement/vendor/stripe/stripe-php/lib/WebhookSignature.php on line 87

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /home/cvdumog/www/paiement/vendor/stripe/stripe-php/lib/WebhookSignature.php on line 114

oak hawk
#

Hello 👋
Stepping in and catching up

#

Have you tried debugging your $_SERVER variable to see if it really has the HTTP_STRIPE_SIGNATURE key in there?

carmine citrus
#

yes is null

oak hawk
#

that's the issue then
my PHP skills aren't great but this boils down to how to your PHP server not working as expected.
First thing you'd want to try and do is to get $_SERVER to not be null

Would recommend searching the web and see if folks have run into something similar before

carmine citrus
#

Yes in parallel I search and I find other identical situation

#

when I var_dump($_SERVER); I have the usual returns but not ['HTTP_STRIPE_SIGNATURE']

oak hawk
#

How exactly are you triggering this code?
Are you calling the endpoint yourself OR are you triggering events using Stripe CLI?

carmine citrus
#

I call it directly via the url

oak hawk
#

You shouldn't do that. Stripe calls that endpoint when we have an event to deliver.

#

You calling the endpoint is what's causing the error

#

as your request won't have the same information as payload sent from Stripe would

carmine citrus
#

It's stripe who calls this point?

#

Sorry I overlooked this "detail" point.