【问题标题】:Stripe PHP Subscription Webhook条纹 PHP 订阅 Webhook
【发布时间】:2016-03-04 19:50:02
【问题描述】:

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

当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

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    可以在条带文档中找到此信息。您必须安装 Stripe PHP SDK。您可以使用 Composer 执行此操作,也可以将其直接下载到您的项目供应商文件夹中:

    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,然后使用该 ID 进行 API 调用。有效负载的响应正文为 JSON 格式。所以一定要解码 JSON。

    【讨论】:

    • 那么,我会把它放在 if(statement) 中吗?
    猜你喜欢
    • 2018-11-29
    • 2015-11-12
    • 1970-01-01
    • 2019-03-31
    • 2020-05-04
    • 2016-11-26
    • 1970-01-01
    • 2019-05-28
    相关资源
    最近更新 更多