繁体   English   中英

使用Stripe PHP Api通过Webhook原谅发票

[英]Forgive an Invoice through a webhook with Stripe PHP Api

这是我要完成的前提:

Stripe生成每月订阅的发票,并将Webhook发送到服务器上的页面。 我收到了Webhook,并进行了快速测试,以查看用户是否有负余额(财务应用程序),在这种情况下,我想“原谅”发票。 但是,我无法保存发票。 代码在下面,但希望能帮助您解决此问题。

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

// Do something with $event_json
$Stripe_Cust_ID = $event_json->data->object->customer;
$Plan = $event_json->data->object->lines->data[0]->plan->id;
$Invoice_ID = $event_json->data->object->id;

//...
//Small amount of logic and a DB query to figure out user's balance.
//....

if ($Balance < 0) {
    $invoice = \Stripe\Invoice::retrieve($event_json->data->object->id);
    echo "Invoice Forgiven?: ".$invoice->forgiven;
    $invoice->forgiven = true;
    echo "Invoice Forgiven Round 2?: ".$invoice->forgiven;
    $invoice->save();
}

http_response_code(200); // PHP 5.4 or greater

我的代码回显了完整的发票响应,但似乎不会原谅或保存发票。 难道我做错了什么?

在调用Stripe的API之前,是否使用以下类似方法设置Stripe API密钥?

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

除此之外,您的请求应该已经编码了。 我建议您查看Stripe帐户的API日志[0],以确保您的请求进入Stripe,并查看对您的请求的响应。 我还建议您查看自己服务器的日志中是否存在任何错误。

[0] https://dashboard.stripe.com/logs/overview

暂无
暂无

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

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