A
A
Alexey Verkhovtsev2018-05-04 17:51:40
Stripes
Alexey Verkhovtsev, 2018-05-04 17:51:40

Why doesn't handleWebhook Cashier Laravel work?

Hello everyone, I want to accept hooks from Stripe, I read the doc
Route scored this Route::post('stripe/webhook', '\App\Http\Controllers\[email protected]');
The controller extends the base

use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;

class WebhookController extends CashierController {}

I'm trying to test and create a stupid file
public function handleInvoicePaymentSucceeded($payload)
    {
        //http_response_code(201);
        //$subscription = Subscription::where('stripe_id', $payload);

        $path = 'screenshots/' . time() . '.txt';
        $result = Storage::disk('public')->put($path, 'asdasd');
    }

But nothing is created, but 200 flies in response, for 40 minutes I can’t find a reason, and if you stupidly make the controller separate, not extending CashierController, for example, to the index method, then the file is created perfectly
public function index()
    {
        $input = @file_get_contents('php://input');
        //$event_json = json_decode($input);

// Do something with $event_json
        $path = 'screenshots/' . time() . '.txt';
        $result = Storage::disk('public')->put($path, 'asdasd');

        http_response_code(200); // PHP 5.4 or greater
    }

Of course, I can use the option with my controller and method, but I like the cashier solution, but there is no time to write something like that, has anyone come across it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Verkhovtsev, 2018-05-04
@seftomsk

I kind of figured it out, I had to climb into the WebhookController class,
and there is a check

if (! $this->isInTestingEnvironment() && ! $this->eventExistsOnStripe($payload['id'])) {
            return;
        }

Accordingly, it is not executed, the isInTestingEnvironment method compares CASHIER_ENV with 'testing', registered this in .env and it all worked. It's strange that this was not indicated in the dock ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question