Stripe PHP 订阅 Webhook

5

如何使用Stripe的Webhook来更新数据库中的用户?我已经让钩子起作用了,只是无法将其用于更新数据库中的用户。

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

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

1个回答

4
这些信息可以在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负载返回的信息中获取客户唯一标识,然后使用该标识进行API调用。负载的响应正文以JSON格式呈现。因此,请确保解码JSON。

那么,我应该把它放在if语句里面吗? - Blood_Wolf89

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接