Skip to content

Re-creating a cancelled subscription throws duplicate key value violates unique constraint "subscriptions_stripe_id_unique" #1758

@ahoiroman

Description

@ahoiroman

Cashier Stripe Version

15.6.4

Laravel Version

12.14.1

PHP Version

8.4

Database Driver & Version

Postgres

Description

Hello,

I am facing the following problem:

I am using stripe checkout to create a subscription. In order to do so, I am generating the link this way:

<?php

$user
    ->collectTaxIds()
    ->newSubscription('default', 'price_1')
    ->checkout([
        'success_url' => $url,
        'cancel_url'  => $url,
    ])->url;

That works and the user can subsribe.

If I then cancel the subscription using the billing portal:

$user->billingPortalUrl($url)

And re-enable it by checking out again using:

<?php

$user
    ->collectTaxIds()
    ->newSubscription('default', 'price_1...')
    ->checkout([
        'success_url' => $url,
        'cancel_url'  => $url,
    ])->url;

This throws the following error:

duplicate key value violates unique constraint "subscriptions_stripe_id_unique"

Steps To Reproduce

  1. Use checkout to create a subscription
  2. Cancel that subscription (now!)
  3. Use checkout to re-create a subscription

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions