Skip to content

Call to a member function stripe() on null (soft deletes) #1800

@larskoole

Description

@larskoole

Cashier Stripe Version

16.0.4

Laravel Version

latest

PHP Version

8.4

Database Driver & Version

No response

Description

When receiving a webhook for a soft deleted billable model you get the error:
Call to a member function stripe() on null

What going good is the fact that Cashier::findBillable() applies withTrashed() to find the soft deleted model inside of the WebhookController.

Where it's going wrong is in the asStripeSubscriptionItem() method of SubscriptionItem looking back to the owner like so:

public function asStripeSubscriptionItem(array $expand = [])
{
    return $this->subscription->owner->stripe()->subscriptionItems->retrieve(
        $this->stripe_id, ['expand' => $expand]
    );
}

This method is called from $subscription->currentPeriodEnd(); which does $item->currentPeriodEnd();, which calls $this->asStripeSubscriptionItem().

Here it loads the subscription, but it can't find the owner because it's soft deleted and there is no withTrashed() applied on the subscription->owner relation.

I think a solution would be to chaperone the subscription + owner to the SubscriptionItem, or add withTrashed() logic to the subscription->owner relation.

Steps To Reproduce

  1. Grab a starter kit
  2. Add soft deletes to a user
  3. Start a subscription
  4. Delete the user
  5. Cancel the subscription

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions