laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
238 stars 57 forks source link

[1.x] Fix Livewire support #199

Closed ralphjsmit closed 11 months ago

ralphjsmit commented 11 months ago

I noticed that I was getting 404s by Paddle on a staging environment. The 404s were on the product domain and caused by the fact that certain plan IDs could not be found.

I double checked the HTML to see if the environment was set correctly. Apparently the code for setting the environment to Sandbox environment was present. However, when running Paddle.Environment.get() in the console, it would return production as environment.

I was able to pinpoint the issue to Livewire and the fact that Livewire v3 now introduces __BLOCK__ comments in HTML around Blade @if's:

Script

Since the if-condition was inside a <script> tag, JavaScript doesn't know how to handle this comment well, and therefore the environment would never be set to sandbox. This PR solves the Livewire compatibility by putting the Environment set call in a separate script tag.

Thanks!