Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need current_period_end and current_period_start column in subscriptions table #515

Closed
tareqtms opened this issue May 10, 2018 · 13 comments
Closed

Comments

@tareqtms
Copy link

After a user cancels the subscription, I need to show the user how many days remaining for the current period. There is no column for those values in the subscriptions table.

How can I achieve this?

@kyranb
Copy link
Contributor

kyranb commented May 10, 2018 via email

@tareqtms
Copy link
Author

tareqtms commented May 10, 2018

Ok, that will solve my initial issue. What if I want to show the next billing date to the user (when the subscription is not canceled)?

@tareqtms
Copy link
Author

tareqtms commented May 10, 2018

Basically, I need to know, is there any way to add any additional fields to the subscriptions table, if I feel the need for any additional data (Which is available in Stripe Subscription model)?

@coryrose1
Copy link

coryrose1 commented Aug 1, 2018

Hi @tareqtms

I'm sure you've moved on from this issue but I found it searching for the same thing.

It's actually simpler than expected. Simply add a field to the subscriptions table using a new migration (or even manually works).

You can then update the field like so:

$user->subscription('main')->new_field_name = 'new_value';
$user->subscription('main')->save();

@driesvints
Copy link
Member

Think this issue can be closed by using the examples provided here. Feel free to provide additional feedback if you want.

@stueynet
Copy link

stueynet commented Oct 13, 2018

Sorry to ressurect this but the above examples don't actually solve much as far as I can tell. current_period_end is a field provided by the stripe API. It is referenced in the Cashier code here: https://github.com/laravel/cashier/blob/master/src/Subscription.php#L309 however it is not accessible via the cashier subscription object which only gives you:

    "id" => 123
    "user_id" => 123
    "name" => "default"
    "stripe_id" => "sub_123"
    "stripe_plan" => "name_of_plan"
    "quantity" => 1
    "trial_ends_at" => null
    "ends_at" => null
    "created_at" => "2018-10-13 16:51:23"
    "updated_at" => "2018-10-13 16:57:09"

If people want to get the actual subscription from Stripe you can do:

return \Stripe\Subscription::retrieve($id);

@driesvints
Copy link
Member

driesvints commented Oct 15, 2018

@stueynet you can do $user->subscription()->asStripeSubscription()->current_period_end.

@stueynet
Copy link

Oh wow thanks @driesvints thats the method I need.

@yoeriboven
Copy link
Contributor

@driesvints This would mean my app has to connect to the Stripe API every time a user wants to see the end of their subscription.

Using @NassimRehali15 solution means the date is incorrect until the command is run.

What's the reason for not putting this in a column on the subscriptions table? It's a value used in almost every app.

I was going to issue a PR until I saw this thread.

@driesvints
Copy link
Member

It's a value used in almost every app.

I've never had to use this in my apps and neither do we use this in Spark afaik. I think this is a bit of an objective opinion. You're free to add the code from your PR to your own app. But I think adding this to the core isn't interesting to everyone out there. It's just not feasible to add every single field of a subscription to the subscriptions table.

Try the following code snippet by @coryrose1 after creating a subscription and then overwrite the webhook in our own controller.

$user->subscription('main')->new_field_name = 'new_value';
$user->subscription('main')->save();

@johnwc
Copy link

johnwc commented Aug 4, 2022

@driesvints We are in need for this to be in the database, so that we are able to do a join query with our other tables to quickly count how many credits a customer has until next billing cycle. What do you suggest would be the best way of getting this value updated when the billing cycle updates in stripe? You mention overwriting the webhook, have a quick example of this? Do you know what webhook we'd need to subscribe to in Stripe to get updated on each new billing cycle?

@bokele3
Copy link

bokele3 commented Mar 1, 2023

$user->asStripeSubscription()->current_period_end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants