我正在尝试在客户注册计划后发送电子邮件
我已经在条纹中设置了网络钩子,但它没有发送电子邮件
我做错了什么,这是网络钩子文件
<?php
require 'core/lib/Stripe.php';
Stripe::setApiKey("YOUR_SECRET_KEY");
// retrieve the request's body and parse it as JSON
$body = file_get_contents('php://input');
$event_json = json_decode($body);
// for extra security, retrieve from the Stripe API
$event_id = $event_json->id;
$event = Stripe_Event::retrieve($event_id);
// This will send receipts on successful charges
if ($event_json->type == 'charge.succeeded') {
$To = 'myemail@email.com';
$Subject = 'Stripe Message';
$Message = 'Webhook worked';
$Headers = "From: coolio@yahoo.com 'r'n" .
"Reply-To: coolio@yahoo.com 'r'n" .
"Content-type: text/html; charset=UTF-8 'r'n";
mail($To, $Subject, $Message, $Headers);
}
http_response_code(200); // PHP 5.4 or greater
?>
当我查看 Stripe 中的事件时,它没有显示任何响应
您可能
希望从 Stripe 获取事件以测试有效性并处理异常(请注意,这故意在测试 webhook 中失败):
try {
// Check against Stripe to confirm that the ID is valid
$event_id = $event_json->id;
$event = Stripe_Event::retrieve($event_id);
}
catch (Stripe_InvalidRequestError $e) {
// If the event is invalid, log an error
error_log($e->getMessage(),0);
}
然后,您应该能够从中获取事件类型属性,如下所示:
if (isset($event) && $event->type == "charge.succeeded") {
// Send your email
}