【问题标题】:stripe webhook event not working条纹 webhook 事件不起作用
【发布时间】:2015-02-04 13:47:44
【问题描述】:

我正在尝试在客户注册计划后发送电子邮件

我已将 webhook 设置为条带,但它不发送电子邮件

我做错了什么,这里是 webhook 文件

<?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 中的事件时,它没有显示任何响应

【问题讨论】:

    标签: php stripe-payments webhooks


    【解决方案1】:

    您可能希望从 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
        }
    

    【讨论】:

      猜你喜欢
      • 2021-06-05
      • 2015-10-07
      • 2016-03-07
      • 2016-09-12
      • 1970-01-01
      • 2021-01-07
      • 2015-05-25
      • 2016-06-01
      • 1970-01-01
      相关资源
      最近更新 更多