Почему Stripe webhook работает с использованием терминала и не работает без терминала? - PullRequest
1 голос
/ 06 февраля 2020

Я сделал php конечную точку http://site/stripe-webhooks с кодом из следующего примера "http://stripe.com/docs/webhooks/build".

<?php
/**
 * Template Name: Stripe Webhooks
 */


$endpoint_secret = 'whsec_****************************************';

$payload = @file_get_contents('php://input');
$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();
}

// Handle the event
switch ($event->type) {
    case 'payment_intent.succeeded':
        $paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
        // Then define and call a method to handle the successful payment intent.
        // handlePaymentIntentSucceeded($paymentIntent);
        break;
    case 'payment_intent.created':
        $paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
        // Then define and call a method to handle the successful payment intent.
        // handlePaymentIntentSucceeded($paymentIntent);
        break;
    case 'payment_method.attached':
        $paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod
        // Then define and call a method to handle the successful attachment of a PaymentMethod.
        // handlePaymentMethodAttached($paymentMethod);
        break;
    case 'checkout.session.completed':
        $session = $event->data->object;

        // Fulfill the purchase...
        handle_checkout_session($session);
        break;
    // ... handle other event types
    default:
        // Unexpected event type
        http_response_code(400);
        exit();
}

http_response_code(200);

Когда я пишу stripe listen --forward-to http://site/stripe-webhooks в терминале и проверяю процесс оплаты, он работает.

Но если я закрываю терминал, он не работает. Когда я отправляю тестовое событие в конечную точку webhook через панель мониторинга, я получаю следующий ответ:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>503 Service Unavailable</title>
</head><body>
<h1>Service Unavailable</h1>
<p>The server is temporarily unable to service your
request due to maintenance downtime or capacity
problems. Please try again later.</p>
</body></html>

Страница существует и ее можно открыть в браузере. Где ошибка?

...