laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 671 forks source link

On cancel subscription immediately from customer portal, ends_at column in the subscription table stays NULL #1567

Closed micos7 closed 1 year ago

micos7 commented 1 year ago

Cashier Stripe Version

14.12

Laravel Version

10.10

PHP Version

8.2.10

Database Driver & Version

Mysql 8 smth Ubuntu

Description

I create a subscription from the checkout image Then I cancel it from the customer portal image In my webhook all customer events are listened to customer.bank_account.created customer.bank_account.deleted customer.bank_account.updated customer.card.created customer.card.deleted customer.card.updated customer.created customer.deleted customer.discount.created customer.discount.deleted customer.discount.updated customer.source.created customer.source.deleted customer.source.expiring customer.source.updated customer.subscription.created customer.subscription.deleted customer.subscription.paused customer.subscription.pending_update_applied customer.subscription.pending_update_expired customer.subscription.resumed customer.subscription.trial_will_end customer.subscription.updated customer.tax_id.created customer.tax_id.deleted customer.tax_id.updated customer.updated

"api_version": "2023-08-16",

In customer portal subscription cancel is set to immediately

image

After I click cancel i get 2 events in logs image

In subscription updated event I get the Json image

cancel_at is null but not canceled_at

So I changed in this snippet of code cancel_at in canceled_at in the function handleCustomerSubscriptionUpdated

if (isset($data['cancel_at_period_end'])) {
                if ($data['cancel_at_period_end']) {
                    $subscription->ends_at = $subscription->onTrial()
                        ? $subscription->trial_ends_at
                        : Carbon::createFromTimestamp($data['current_period_end']);
                } elseif (isset($data['canceled_at'])) {
                    $subscription->ends_at = Carbon::createFromTimestamp($data['canceled_at']);
                } else {
                    $subscription->ends_at = null;
                }
            }

I am in test mode. Am I missing something ,is this an issue in the latest version or what? Thanks

Steps To Reproduce

Just create a subscription from checkout and cancel from customer portal.It should be enough.

driesvints commented 1 year ago

Thank you. This has been fixed already for the upcoming Cashier v15 release. Right now we don't have an ETA for it, sorry.

micos7 commented 1 year ago

Extending the webhook with those modification should be enough?

driesvints commented 1 year ago

@micos7 yeah that's a good one in the meantime 👍

micos7 commented 1 year ago

Thanks.