Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook Handling Error in Laravel Cashier Mollie #269

Open
WEBronckhorst opened this issue Nov 4, 2024 · 4 comments
Open

Webhook Handling Error in Laravel Cashier Mollie #269

WEBronckhorst opened this issue Nov 4, 2024 · 4 comments

Comments

@WEBronckhorst
Copy link

Issue: Webhook Handling Error in Laravel Cashier Mollie

Description

When handling the webhook for first payments, the webhook fails and results in an internal server error.

Error Details

  • Exception: Laravel\Cashier\Exceptions\InvalidMandateException
  • Message: Invalid customer mandate
  • HTTP Status: 500 Internal Server Error

Request Details

  • Endpoint: POST /webhooks/mollie/first-payment
  • Headers:
    • content-length: 22
    • user-agent: RapidAPI/4.2.6 (Macintosh; OS X/15.1.0) GCDHTTPRequest
    • connection: close
    • host: gaia.staging.nu
    • content-type: application/json; charset=utf-8
  • Body:
    {
        "id": "tr_xxxxxxxx"
    }

Application Details

  • Controller Handling the Request: \Laravel\Cashier\Http\Controllers\FirstPaymentWebhookController@handleWebhook
  • Route Name: webhooks.mollie.first_payment

Database Queries

  1. SELECT * FROM customers WHERE customers.id = 2 LIMIT 1 (2.6 ms)
  2. SELECT * FROM payments WHERE mollie_payment_id = 'tr_xxxxxxxx' LIMIT 1 (0.58 ms)
  3. UPDATE customers SET mollie_mandate_id = NULL, customers.updated_at = '2024-11-04 17:05:00' WHERE id = 2 (0.57 ms)

Steps to Reproduce

  1. Trigger a POST request to the /webhooks/mollie/first-payment endpoint.
  2. Include a valid id in the request body, such as "id": "tr_xxxxxxxx".
  3. Observe the error response and exception thrown.

Expected Behavior

The webhook should be handled without any exceptions or errors, and the payment should be processed correctly.

Actual Behavior

An InvalidMandateException is thrown, resulting in an internal server error.

Possible Related Issues

  • Ensure that the mandate ID for the customer is correctly set before handling the webhook.
  • Verify that the payments and customers tables have consistent data related to the given mollie_payment_id.

Suggested Solution

Investigate why the mollie_mandate_id is set to NULL during the process and ensure that valid mandates are present for the customer.

@sandervanhooft
Copy link
Collaborator

Hi @WEBronckhorst ,

Thanks for the extensive report.

To get started:

  • what specific (2.x.y) package version are you using?
  • do you have any customizations in place such as custom Models, Repositories, routes or preprocessors?
  • have you recently changed Mollie environments, i.e. from test to live, or changed the Mollie profile key for another profile's?
  • for these specific resources, what is the Mollie dashboard telling you about the history?

@WEBronckhorst
Copy link
Author

Here’s an improved and translated response in Markdown format:

Hi @sandervanhooft,

Thank you for your response!

Here's the information you requested:

  • Package Version: Using "mollie/laravel-cashier-mollie": "^2.0".
  • Other Dependencies: I’ve attached my full composer.json list below, which includes dependencies like mollie/laravel-mollie, livewire/livewire, and several others.
  • Custom Modifications: I made a minor adjustment in the Laravel Cashier Mollie package, specifically in FirstPaymentBuilder.ph
public function getMolliePayload()
{
    return array_filter(array_merge([
//       'sequenceType' => SequenceType::SEQUENCETYPE_FIRST,  // <<
        'method' => [], // <<
        'customerId' => $this->owner->asMollieCustomer()->id,
        'locale' => Cashier::getLocale($this->owner),
        'description' => $this->description,
        'amount' => money_to_mollie_array($this->actions->total()),
        'webhookUrl' => $this->webhookUrl,
        'redirectUrl' => $this->redirectUrl,
        'metadata' => [
            'owner' => [
                'type' => $this->owner->getMorphClass(),
                'id' => $this->owner->getKey(),
            ],
        ],
    ], $this->options));
}
  • Mollie Setup: Currently using my own test key and profile until SEPA direct debit is fully activated for the client. This allows me to avoid initiating a payment each time during testing.
  • Webhook Issue: Payments succeed, but the webhook triggers an error afterward.
  • Other Dependencies: My project's composer.json includes the following packages:
  "require": {
      "php": "^8.2",
      "andreiio/blade-iconoir": "^4.3",
      "ariaieboy/filament-currency": "^1.9",
      "artesaos/seotools": "^1.3",
      "calebporzio/sushi": "^2.5",
      "carlos-meneses/laravel-mpdf": "^2.1",
      "codeat3/blade-grommet-icons": "^1.9",
      "codeat3/blade-iconpark": "^1.6",
      "codeat3/blade-phosphor-icons": "^2.2",
      "codeat3/blade-teeny-icons": "^1.10",
      "consoletvs/charts": "^6.7",
      "davidhsianturi/blade-bootstrap-icons": "^1.5",
      "dymantic/laravel-instagram-feed": "^3.3",
      "filament/filament": "^3.2",
      "filament/spatie-laravel-media-library-plugin": "^3.2",
      "intervention/image": "^3.7",
      "intervention/image-laravel": "^1.3",
      "laravel/framework": "^11.9",
      "laravel/horizon": "^5.27",
      "laravel/tinker": "^2.9",
      "league/html-to-markdown": "^5.1",
      "livewire/livewire": "^3.0",
      "m-paap/veloyd-api": "^0.0.2",
      "mailersend/laravel-driver": "^2.6",
      "mollie/laravel-cashier-mollie": "^2.0",
      "mollie/laravel-mollie": "^3.0",
      "mollie/mollie-api-php": "^2.67",
      "mpdf/mpdf": "^8.2",
      "rawilk/laravel-printing": "^3.0",
      "sentry/sentry-laravel": "^4.9",
      "simplesoftwareio/simple-qrcode": "~4",
      "spatie/flysystem-dropbox": "^3.0",
      "spatie/image": "^3.7",
      "spatie/laravel-backup": "^9.0",
      "spatie/laravel-login-link": "^1.2",
      "unisharp/laravel-filemanager": "dev-master",
      "whitecube/laravel-cookie-consent": "^1.2"
  },
  "require-dev": {
      "fakerphp/faker": "^1.23",
      "laravel/breeze": "^2.2",
      "laravel/pint": "^1.13",
      "laravel/sail": "^1.26",
      "mockery/mockery": "^1.6",
      "nunomaduro/collision": "^8.1",
      "pestphp/pest": "^3.3",
      "pestphp/pest-plugin-laravel": "^3.0"
  }

Thank you in advance for your help in resolving this!

Best regards,

Let me know if this version captures everything accurately or if you'd like any adjustments.

@WEBronckhorst
Copy link
Author

something went wrong with my last pee it has not been resolved yet

@WEBronckhorst WEBronckhorst reopened this Nov 6, 2024
@sandervanhooft
Copy link
Collaborator

Thanks @WEBronckhorst ,

That leaves these questions open:

what specific (2.x.y) package version are you using?

You can find the installed package version using composer show mollie/laravel-cashier-molllie

have you recently changed Mollie environments, i.e. from test to live, or changed the Mollie profile key for another profile's?

for these specific resources, what is the Mollie dashboard telling you about the history?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants