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

Inline checkout blade component ignores any false settings parameter #272

Closed fortindustries closed 1 month ago

fortindustries commented 1 month ago

Cashier Paddle Version

2.4.0

Laravel Version

10.48.3

PHP Version

8.1.4

Database Driver & Version

No response

Description

Paddle provides a "allowLogout" setting to prevent the user from changing their email during checkout.

There's no way to pass that parameter to Paddle using Cashier though, because the inline checkout Blade component ignores any settings parameter set to false, as it's using array_filter. So the only way to get this working currently is to overre the Blade component view.

This is a similar issue to #257 but the fix #261 only fixes the button component and not the inline checkout.

Steps To Reproduce

  1. Create checkout

    $checkout = $user->subscribe($priceId)
            ->returnTo(route('dashboard'));
  2. Add inline checkout to view with a false setting parameter

<x-paddle-checkout :settings="['allowLogout'=>false]" :checkout="$checkout" class="w-full" height="500"/>

  1. Inspect the page source code. The object passed to Paddle.Checkout.open does not have "allowLogout"
driesvints commented 1 month ago

You can't logout during an inline checkout? Paddle doesn't allow that.

driesvints commented 1 month ago

Also, there's no ":settings" param on the checkout component so not sure why you're trying that? We also don't document it like this.

fortindustries commented 1 month ago

Also, there's no ":settings" param on the checkout component so not sure why you're trying that? We also don't document it like this.

There is a $settings parameter in the constructor of the component, so if you pass :settings it will actually work - maybe it wasn't intended as I see it is indeed not documented.

Re: ability to log out, the issue is that when allowLogout is true, if you have collected the email previously and created the checkout, the user is then able to change the email inside the Paddle checkout component. And if they do change their email from the one they provided during registration, Paddle creates a new customer, the webhook stops working (the customer_id is different), and they have no active subscription / invoices in their account.

That said, since it's easily fixable by overriding the component view file I understand why you might not be interested in fixing it in the package.

If anyone else is encountering this problem, create this file as resources/views/vendor/cashier/components/checkout.blade.php

<div {{ $attributes->merge(['class' => $id]) }}></div>
@php
    $allOptions = $options();
    $allOptions['settings'] = $allOptions['settings'] ?? [];
    $allOptions['settings']['allowLogout'] = false;
@endphp

<script type="text/javascript">
    Paddle.Checkout.open(@json($allOptions));
</script>
scabudlan commented 1 month ago

Hi @fortindustries,

Hi, we have encountered the same problem. And my temporary solution is updating the value of allowLogout to false in the JS environment.

driesvints commented 1 month ago

I finally managed to confirm this and send in a fix: https://github.com/laravel/cashier-paddle/pull/276

I didn't know you could disable the email field with this! šŸ˜®

Thanks šŸ‘

fortindustries commented 1 month ago

I finally managed to confirm this and send in a fix: #276

I didn't know you could disable the email field with this! šŸ˜®

Thanks šŸ‘

thank you!