Я не уверен, почему я получаю следующие ошибки в моем файле webhook php. Я почти точно следую примеру того, что есть в Stripe в их документах (https://stripe.com/docs/payments/handling-payment-events). Однако я получаю предупреждения / ошибки ниже.
Предупреждения, которые я получаю, когда я go прямо на странице веб-крючка. Я также вижу эти ошибки в теле ответа на информационной панели Stripe. Я использую инструмент Stripe Webhook CLI и запускаю событие charge.succeeded
, однако кажется, что case
для этого никогда не перехватывает его и HELLO3
всегда отражается в ответе.
( ! ) Warning: array_keys() expects parameter 1 to be array, string given in /stripe/stripe-php/lib/StripeObject.php on line 272
Warning: array_diff(): Argument #2 is not an array in /stripe/stripe-php/lib/StripeObject.php on line 272
Warning: Invalid argument supplied for foreach() in /stripe/stripe-php/lib/Util/Set.php on line 15
Warning: Invalid argument supplied for foreach() in /stripe/stripe-php/lib/StripeObject.php on line 295
Warning: Invalid argument supplied for foreach() in /stripe/stripe-php/lib/StripeObject.php on line 280
<?php
//load Stripe API
require_once($_SERVER['DOCUMENT_ROOT'].'/stripe/stripe-php/init.php');
// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_XXXXXXXXXXXXXXXXXXXXX');
$payload = @file_get_contents('php://input');
$event = null;
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
}
// Handle the event
switch ($event->type) {
case 'charge.succeeded':
$paymentIntent = $event->data->object; // contains a StripePaymentIntent
handlePaymentIntentSucceeded($paymentIntent);
wp_publish_post( 36 );
echo "HELLO";
break;
case 'payment_method.attached':
$paymentMethod = $event->data->object; // contains a StripePaymentMethod
handlePaymentMethodAttached($paymentMethod);
echo "HELLO2";
break;
// ... handle other event types
default:
// Unexpected event type
http_response_code(400);
echo "HELLO3";
exit();
}
http_response_code(200);
?>