Skip to content

Don't modify trial_ends_at in the cancel_now method unless the subscription is actually on trial #1170

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

Conversation

mpvosseller
Copy link
Contributor

Pull Request

Summary:

This updates Pay::Stripe::Subscription#cancel_now! so it will not set (modify) the trial_ends_at property unless the subscription is currently on_trial?

We had been using trial_ends_at to indicate whether a subscription was a trial but found this was not working on subscriptions where cancel_now! was called.

Related Commit
5a719ad

Related Issue:

Description:

Testing:

I'm not quite sure if / how I can add a new VCR cassette? Is that something you would do or can you provide me a reference / pointer to do so?

Screenshots (if applicable):

Checklist:

  • Code follows the project's coding standards
  • Tests have been added or updated to cover the changes
  • Documentation has been updated (if applicable)
  • All existing tests pass
  • Conforms to the contributing guidelines

Additional Notes:

@excid3
Copy link
Collaborator

excid3 commented Jun 2, 2025

Hmm, why are you cancelling the subscription immediately instead of on period end?

@mpvosseller
Copy link
Contributor Author

mpvosseller commented Jun 2, 2025

Hmm, why are you cancelling the subscription immediately instead of on period end?

I guess the most common general use case would be when a customer "forgets to cancel" and customer support graciously decides to "cancel_now" and issue a partial refund.

I assumed setting trial_ends_at in cancel_now! was just an oversight. If you don't think we should be relying on trial_ends_at as an indication of the subscription having been a trial we could probably use the Stripe object's trial_end property instead now that the full Stripe object is in the database.

@excid3
Copy link
Collaborator

excid3 commented Jun 2, 2025

I'm not 100% sure I understand the situation but cancel now's intention is to completely cancel trials or active subscriptions.

@mpvosseller
Copy link
Contributor Author

mpvosseller commented Jun 2, 2025

Sorry if I'm not being clear. Let me rephrase the problem.

Let's say a user creates a regular (non-trial) subscription and at some point we call subscription.cancel (to cancel at end of billing period) the trial_ends_at property stays nil forever.

Now let's say another user creates a regular (non-trial) subscription and at some point we call subscription.cancel_now! (to cancel immediately) the trial_ends_at gets set to the current time.

Why does the pay gem set trial_ends_at when canceling with one method (cancel_now!) but not with the other (cancel)? And when neither subscription was a trial?

@excid3
Copy link
Collaborator

excid3 commented Jun 4, 2025

Ah yep, I get you now. I agree we shouldn't set trial_ends_at if there wasn't one.

@excid3
Copy link
Collaborator

excid3 commented Jun 4, 2025

The current implementation is also incorrect. The values set should match what's returned from the API since the webhooks will update the values anyways. Currently this will set different times for each.

excid3 added a commit that referenced this pull request Jun 4, 2025
This updates Stripe to sync ends_at from the API response consistently.

Also fixes #1170 where trial_ends_at was set regardless of a trial existing or not.
@excid3 excid3 closed this in #1172 Jun 4, 2025
@excid3 excid3 closed this in 35421b4 Jun 4, 2025
@mpvosseller
Copy link
Contributor Author

Thank you @excid3

@excid3
Copy link
Collaborator

excid3 commented Jun 4, 2025

Thanks for catching that @mpvosseller! I meant to give you credit in the commit, sorry! 🙃

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

Successfully merging this pull request may close these issues.

2 participants