【问题标题】:stripe webhook test mode response "none"条纹 webhook 测试模式响应“无”
【发布时间】:2016-05-15 08:53:37
【问题描述】:

我正在尝试更新数据库。

我已在测试模式下以条带设置 webhook,并将“invoice.payment_succeeded”测试 webhook 发送到文件。但它在条带输出中显示响应“无”。

我做错了什么,这是 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);


 ?>

【问题讨论】:

    标签: php stripe-payments webhooks


    【解决方案1】:

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

    【讨论】:

    • 感谢 matthew Arkin 的 rpy,我为客户每月和每年创建了 2 个计划,我只是想确保计划到期时将发票发送到客户电子邮件,如果客户不回复,条纹向我发送 webhook invoice.payment_failed 所以我更新了我的数据库。那么用户将无法访问应用程序。我无法测试这段代码,如果这工作与否。我该怎么办?请帮帮我
    • 创建一个试用期为 1 天的订阅
    猜你喜欢
    • 2016-03-07
    • 2018-04-10
    • 1970-01-01
    • 2018-04-28
    • 2022-01-13
    • 2016-09-12
    • 1970-01-01
    • 2017-10-25
    • 2016-12-25
    相关资源
    最近更新 更多