lmsqueezy / laravel

A package to easily integrate your Laravel application with Lemon Squeezy.
https://lemonsqueezy.com
MIT License
468 stars 47 forks source link

Webhook skipped due to invalid custom data. #83

Open victor-ponamariov opened 2 months ago

victor-ponamariov commented 2 months ago

Lemon Squeezy for Laravel Version

1.5.2

Laravel Version

11.1.1

PHP Version

8.3.3

Description

In LemonSqueezy I have a product which is a one-time purchase.

When a customer makes a purchase, Laravel receives the webhook. The response of the webhook request is Webhook skipped due to invalid custom data.

That happens because at the time of requesting the webhook there is no billable_id and billable_type.

How to handle the case? When somebody buys a product, I need to

  1. Create a user with the email they specified when purchasing the product
  2. Make sure that the user has bought the product (= there should be a record in the customers taable)

Plus, the user might already exist but might not be a customer (in this case, the first step should be skipped)

Is it possible to realize this scenario? If not, is it possible to override the webhook?

Thanks

Steps To Reproduce

Since it's not a bug but rather a question, there is no specific steps to reproduce. I don't know how to mark the issue as a question.

driesvints commented 2 months ago

Unfortunately there is currently no way to handle this case. All payments need to originate from this library in order to work. This is because at the time of development, using these ID's was the only way to connect a customer in the database to the Lemon Squeezy customer. It might become easier after https://github.com/lmsqueezy/laravel/issues/53 but I don't think it will since an incoming request for a customer that isn't created to a customer in the app database is impossible to map to billable in the app. There's no way to do that afaik.

driesvints commented 2 months ago

That happens because at the time of requesting the webhook there is no billable_id and billable_type.

Just to be clear: how was this purchase performed? What did you do to offer this purchase without involving the app and this library?

victor-ponamariov commented 2 months ago

I've just added their script:

  <a href="https://myshop.lemonsqueezy.com/buy/product-id">
    Buy
  </a>

Which calls webhook after purchasing

driesvints commented 2 months ago

@victor-ponamariov you need to create a user beforehand and generate the link using the library. Otherwise this library cannot know who made the purchase in your app.

driesvints commented 2 months ago

Hmm, actually now that I think deeper on this what we could do maybe is make the billable columns nullable in the database and still save the customer record and the order. That way the data is synced but there's still no user attached to the customer record. But we can leave that up the app to implement depending on incoming event. I'll try to get this in for v2.