简体   繁体   English

Stripe PHP订阅Webhook

[英]Stripe PHP Subscription Webhook

How do I use Stripe's Webhook to update a user in the database? 如何使用Stripe's Webhook更新数据库中的用户? I have the hook working just cant get it to update a user in the db. 我有钩子工作只是不能让它更新数据库中的用户。

How do I call in a customer in webhook when customer.subscription.created & customer.subscription.updated & customer.subscription.deleted ? customer.subscription.created & customer.subscription.updated & customer.subscription.deleted时,如何在webhook调用customer.subscription.created & customer.subscription.updated & customer.subscription.deleted

UPDATE: I have this.. 更新:我有这个..

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);

}



?>

But now I get this error: 但是现在我收到了这个错误:

[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

This information can be found in the stripe docs. 此信息可在条带文档中找到。 You must install The Stripe PHP SDK. 您必须安装Stripe PHP SDK。 You can do this using composer or download it directly into your projects vendor folder: 您可以使用composer或直接将其下载到项目供应商文件夹中:

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

https://stripe.com/docs/api/php#update_customer 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();

What you need to do is get the customers unique id out of the information returned in the webhook payload and then use that to make the API call. 您需要做的是从webhook有效负载中返回的信息中获取客户唯一ID,然后使用它来进行API调用。 The response body of the payload is in JSON format. 有效负载的响应主体是JSON格式。 So be sure to decode the JSON. 所以一定要解码JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM