Stripe Webhooks错误503无效编码:ISO-8859-1 [英] Stripe Webhooks Error 503 Invalid encoding: ISO-8859-1

查看:85
本文介绍了Stripe Webhooks错误503无效编码:ISO-8859-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照Stripe的建议设置了带有签名验证的Stripe Webhook:

I setup a stripe webhook with signature verification just as recommended by stripe:

<?php

logme("Secure connection: ".isSecure());
logme("I was called at:".time());

require 'vendor/autoload.php';

\Stripe\Stripe::setApiKey('sk_test_ff...');
$endpoint_secret = 'whsec_Ky...';

$payload = @file_get_contents('php://input');

if($payload) {
//request body is set
} else {
//request body is not set
    exit();
}

$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];

$event = null;


try {
    $event = \Stripe\Webhook::constructEvent(
        $payload, $sig_header, $endpoint_secret
    );

} catch(\UnexpectedValueException $e) {
    // Invalid payload
    http_response_code(400);
    exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
    // Invalid signature
    http_response_code(400);
    exit();
}

http_response_code(200);

// Handle the event
switch ($event->type) {
    case 'event1':
    // do something 
    break;
    
    // ... handle other event types
    default:
        echo 'Received unknown event type ' . $event->type;
        logme('Received unknown event type ' . $event->type);
}


function logme($msg){

    $log_file = "error.txt";
// logging error message to given log file
    error_log($msg."\n-\n", 3, $log_file);
}
function isSecure() {
    return
        (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
        || $_SERVER['SERVER_PORT'] == 443;
}


在条纹仪表板上,我使用 https://example.org/path/to创建了一个Webhook./webhook.php ,但是如果我在测试模式下启动invoice.paid webhook,则会收到以下错误消息:

At stripe dashboard I created a webhook with https://example.org/path/to/webhook.php but if I fire invoice.paid webhook in test mode I receive the following error:

Test-Webhook-Error: 503 
Invalid encoding: ISO-8859-1 

有人知道这种错误吗?

更新
它似乎取决于触发的事件的类型.例如.plan.deleted工程不成功,payment_intent.succeeded

Update
It seems to depend on the type of event that is triggered. E.g. plan.deleted works and payment_intent.succeeded does not

推荐答案

此错误似乎不是来自签名验证,而是来自请求/网络堆栈中的其他位置.请注意,您在 try {} 中引发的错误是 withStatus(403)(不是503).您能否从服务器中提供更详细的日志记录,以识别失败的地方?

This error does not appear to be coming from the signature verification, but rather somewhere else in your request/network stack. Note that the error you throw in the try {} is withStatus(403) (not 503). Can you provide more detailed logging from your server to identify where this fails?

请参见此相关问题并将解决方案连接到HTTP->HTTPS重定向.确保您配置的端点直接进入HTTPS,并且您的SSL证书正确响应.

See this related question and the solution being connected to a HTTP -> HTTPS redirect. Ensure your configured endpoint is going directly to HTTPS and that your SSL certificates are responding correctly.

我还看到您在处理程序开始时甚至在签名检查之前都在调用 $ event = $ request-> getParsedBody(); ,这可能会导致被操纵的主体数据出现问题(签名验证需要请求的原始内容.)

I also see you are calling $event = $request->getParsedBody(); at the start of your handler even before signature checking, which can something cause problems with the body data being manipulated (the signature verification requires the raw body of the request).

这篇关于Stripe Webhooks错误503无效编码:ISO-8859-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆