Monday, March 13, 2017

Laravel 5.3 - Mollie API Webhook - Wrong Response code

I'm trying to get the Mollie API for Laravel working. I looked and tried endlessly to get the 200 OK response code for the webhook, but at this point I con only get a 500 or 405. These codes appear in my Mollie Dashboard for testing.

Here are my controllers and route files:

PaymentController.php

  public function payment(Request $request)
{
    $reservation_id = $request->reservation_id;
    $location_id = $request->location_id;
    $amount = DB::table('locations')->where('id', $location_id)->value('price');

    $payment = Mollie::api()->payments()->create([
        "amount"      => $amount,
        "description" => "Week: $reservation_id - Huurbetaling",
        "redirectUrl" => "NGROK URL",
        "webhookUrl" => "NGROK URL",
        'metadata'    => array(
            'reservation_id' => $reservation_id
        )
    ]);
      return redirect($payment->getPaymentUrl());
      exit;
  }

Web.php

Route::post('mollie/reservation_webhook','WebhookController@reservation_paid');

VerifyCsrfToken

I just disabled CSRF only for testing.

WebhookController.php

  public function reservation_paid(Request $request){
  $payment = Mollie::api()->payments()->get($payment->id);
  $reservation_id = $payment->metadata->reservation_id;
  if ($payment->isPaid())
  {
      DB::table('payments')->where('reservation_id', $reservation_id)->update('payment_status', 1);
  }
  elseif (! $payment->isOpen())
  {
      DB::table('payments')->where('reservation_id', $reservation_id)->update('payment_status', 2);
  }}

Further more, when I look at the NGROK console I see 2 HTML '302 Found' redirects at the moment of doing a test payment.

Does anyone maybye know how to get the webhook working? I hope someone can help me!

I jused these two sources: https://github.com/mollie/laravel-mollie https://www.mollie.com/en/docs/webhook



via Patrick Attema

Advertisement