stripe 支付报错:No signatures found matching the expected signature for payload

技术分享 · Fecmall · 于 2年前 发布 · 2316 次阅读

stripe支付,接收异步支付消息,log日志打印

public function receiveIpn()
    {
        
        // 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($this->private_key);

        // You can find your endpoint's secret in your webhook settings
        //$endpoint_secret = 'whsec_...';

        $payload = @file_get_contents('php://input');
        $sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
        $event = null;
        \Yii::info('constructEvent', 'fecshop_debug');
        try {
            \Yii::info($payload, 'fecshop_debug');
            \Yii::info($sig_header, 'fecshop_debug');
            \Yii::info($this->endpoint_secret, 'fecshop_debug');
            
            $event = \Stripe\Webhook::constructEvent(
                $payload, $sig_header, $this->endpoint_secret
            );
        } catch(\UnexpectedValueException $e) {
            // Invalid payload
            \Yii::info('UnexpectedValueException', 'fecshop_debug');
            \Yii::info($e->getMessage(), 'fecshop_debug');
            
            http_response_code(400);
            exit();
        } catch(\Stripe\Exception\SignatureVerificationException $e) {
            // Invalid signature
            \Yii::info('SignatureVerificationException', 'fecshop_debug');
            \Yii::info($e->getMessage(), 'fecshop_debug');
            http_response_code(400);
            exit();
        }

        // Handle the checkout.session.completed event
        if ($event->type == 'checkout.session.completed') {
            $session = $event->data->object;

            // Fulfill the purchase...
            $this->paymentSuccess($session);
        }

        http_response_code(200);
    }

\Yii::info('SignatureVerificationException', 'fecshop_debug'); , \Yii::info($e->getMessage(), 'fecshop_debug');报错:

No signatures found matching the expected signature for payload

经过仔细研究,发现,是因为密钥签名(Endpoint Secret)写错了

对于stripe的 public key和private key,都是公用的,但是密钥签名,每一个端点是单独的,

添加webhooks网址:https://dashboard.stripe.com/test/webhooks

因为我的这个网址,填写的是其他端点的密钥签名,进而导致的报错

共收到 0 条回复
没有找到数据。
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics