2017-09-15 68 views
0

我试图在收到来自Stripe API的自定义帐户的account.updated调用时发送(简单测试)电子邮件。我的其他webhook创建收费并告知客户有关成功或失败的收费工作是这样的,但在这里我得到一个错误500(我可以看到在自定义帐户的仪表板中),并且邮件不发送,所以我不确定我在这里做错了什么。我的代码如下所示:stripe webhook account.updated无法正常工作

<?php 

require_once('vendor/autoload.php'); 

// Set your secret key: remember to change this to your live secret key in production 
// See your keys here: https://dashboard.stripe.com/account/apikeys 
\Stripe\Stripe::setApiKey("sk_test_XXXX"); 

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

// Verify the event by fetching it from Stripe 
$event = \Stripe\Event::retrieve($event_json->id); 

// Do something with $event 
if ($event->type == 'account.updated') { 

// The E-Mail message to send to inform about a succeeded charge 
$message = 'test'; 

// Send the E-Mail 
mail('[email protected]', 'We need more info about you!', $message); 

} 

http_response_code(200); // PHP 5.4 or greater 

感谢您的帮助!

回答

0

如果您查看您的网络服务器的error.log(通常可从您的主机控制面板或/var/log/访问),您是否看到有关导致500的更多细节?

难道是$event = \Stripe\Event::retrieve($event_json->id);失败?

如果事件直接发生在连接的帐户上,您可能还需要通过account id来检索它。

在这里看到多一点背景下, https://stripe.com/docs/connect/webhooks

的代码会更喜欢:

$event = \Stripe\Event::retrieve(
array("id" => $event_json->id), 
array("stripe_account" => $event_json->account)); 

https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header

+0

谢谢,鸭,我没有通过该标识关联账户。它现在有效:-) – Dirkozoid