gpt4 book ai didi

php - Stripe webhook 测试模式响应 "none"

转载 作者:搜寻专家 更新时间:2023-10-31 21:26:32 27 4
gpt4 key购买 nike

我正在尝试更新数据库。

我已经在测试模式下设置了 stripe 的 webhook 并将“invoice.payment_succeeded”测试 webhook 发送到文件。但它在 stripe 输出中显示响应“none”。

我做错了什么,这是 webhook 文件,请有人帮助我,我对此非常困惑。任何帮助将不胜感激...

 <?php 

include '../admin/include/functions.php';

require_once('Stripe/lib/Stripe.php');
require_once 'stripe_secret.php';

// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);


$event_id = $event_json->id;

if(isset($event_json->id)) {

try {
Stripe::setApiKey($stripe['secretkey']);

$event = Stripe_Event::retrieve($event_id);

var_dump($event);

$invoice = $event->data->object;

if($event->type == 'invoice.payment_succeeded') {

$customer = Stripe_Customer::retrieve($invoice->customer);

$email = $customer->email;

$customerid = $customer->id;

/*$amount = $invoice->amount / 100;*/

$expiry = $invoice->period->end;
$expiredate = date('Y-d-m', $expiry);

$userup = $obj->run_query("UPDATE users SET Expiry_Date = '$expiredate' WHERE user_stripe_id = '$customerid' ");

if ($userup) {
echo "User Date extended";
}
// send a invoice notice email here
}
if($event->type == 'invoice.payment_failed') {

$obj->run_query("UPDATE users SET Status = '0' WHERE user_stripe_id = '$customerid' ");

echo "User membership expired";
}

}


catch(Stripe_CardError $e) {

}
catch (Stripe_InvalidRequestError $e) {
// Invalid parameters were supplied to Stripe's API

} catch (Stripe_AuthenticationError $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)

} catch (Stripe_ApiConnectionError $e) {
// Network communication with Stripe failed
} catch (Stripe_Error $e) {

// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {

// Something else happened, completely unrelated to Stripe
}

}

http_response_code(200);


?>

最佳答案

来自测试 webhook 按钮的测试 webhooks 发送一个具有正确格式的 webhook,但所有值都是 null/零/等等。因此你的行 $obj->run_query("UPDATE users SET Expiry_Date = ' $expiredate' WHERE user_stripe_id = '$customerid' "); 将返回错误结果。这意味着您不会回显任何内容,只会发回一个空的 200 响应。

关于php - Stripe webhook 测试模式响应 "none",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35223139/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com