php - Stripe PHP 订阅 Webhook

标签 php stripe-payments

如何使用 Stripe 的 Webhook 更新数据库中的用户?我有 Hook 工作只是无法让它更新数据库中的用户。

customer.subscription.created & customer.subscription.updated & customer.subscription.deleted 时,如何在 webhook 中调用客户?

更新:我有这个..

require_once 'mainfile.php';
require_once 'config.php';
require_once 'Stripe/init.php';


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

$customer_id = $event->data->object->customer;
$customer = \Stripe\Customer::retrieve($customer_id);
$email = $customer->email;
$start = $event->data->object->current_period_start;
$end = $event->data->object->current_period_end;
$status = $event->data->object->status;



if ($event->type == "customer.subscription.created") {


    hook($email, $start, $end, $status);

}

if ($event->type == "customer.subscription.deleted") {

    hook($email, $start, $end, $status);

}

if ($event->type == "customer.subscription.updated") {

    hook($email, $start, $end, $status);

}



?>

但是现在我得到这个错误:

[05-Mar-2016 23:52:56 America/New_York] PHP Warning:  mysqli_connect(): Headers and client library minor version mismatch. Headers:100023 Library:100106 in /home/sociagkf/public_html/dashboard/mainfile.php on line 25

最佳答案

此信息可以在 stripe 文档中找到。您必须安装 Stripe PHP SDK。您可以使用 composer 执行此操作或将其直接下载到您的项目 vendor 文件夹中:

https://github.com/stripe/stripe-php

https://stripe.com/docs/api/php#update_customer

\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

$cu = \Stripe\Customer::retrieve("cus_81SwskJbGMS8UI");
$cu->description = "Customer for test@example.com";
$cu->save();

您需要做的是从 webhook 负载中返回的信息中获取客户的唯一 ID,然后使用它进行 API 调用。 payload 的响应体为 JSON 格式。所以一定要解码 JSON。

关于php - Stripe PHP 订阅 Webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35804875/

相关文章:

node.js - 如何从 Firebase 的云功能获取 strip 付款费用 'success'?

payment-gateway - Stripe 身份验证和捕获

php - 多个输入字段上的 Jquery 日期选择器

php - 只能通过 MySQL 来实现这一点

php - MySQL - GROUP BY 减慢页面速度

express - Stripe "Cannot accept the Terms of Service on behalf of Standard and Express connected accounts"

php - 显示通知逻辑

php - Facebook sdk marketing api 使用 date_preset 获取大量见解

javascript - 如何将光标聚焦在 Stripe 输入元素上

javascript - 提交 checkout.js 表单时,this.fn 不是函数