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

标签 php stripe-payments webhooks

我正在尝试更新数据库。

我已经在测试模式下设置了 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/

相关文章:

php - 函数中的mysql查询和结果语句

ruby-on-rails - 我可以在添加新卡之前检查 Stripe 客户是否已经拥有特定卡吗?

java - 使用 Stripe Webhook 发送获取客户详细信息以使用 Stripe 进行定期付款

php - 如何将 Gitlab Web Hook 设置为部署

c# - Facebook Webhook签名计算(C#)

php - 使用 file_put_contents 下载图像

php - Symfony/Propel - 从数据库中检索旧日期

php - MySQL 可在本地主机上运行,​​但不能在线运行

javascript - 是否通过浏览器发送没有名称 =“” 的输入字段

php - Stripe,用户无法下载他们的发票