2017-09-15 71 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