Pinelab-studio / pinelab-vendure-plugins

Monorepo for different Vendure plugins developed by Pinelab
111 stars 49 forks source link

Accept Blue can accidently end up in an unwanted auto renew scenario #532

Closed mschipperheyn closed 1 week ago

mschipperheyn commented 3 weeks ago

Which plugin/repository is the issue about? accept-blue stripe-subscriptions (potentially)

Describe the bug Accept Blue treats num_left: 0 on subscriptions as "ongoing". The calculation for getNrOfBillingCyclesLeft at https://github.com/Pinelab-studio/pinelab-vendure-plugins/blob/acca18999ab1acd4224e92595c00f034f7fe4f82/packages/vendure-plugin-accept-blue/src/api/accept-blue-service.ts#L119C17-L119C41 calculates the number of cycles using Math.floor. That could lead to a result of 0 if the endDate is sufficiently close. This in turn would lead to an "endless scenario" when it should likely be "once only" scenario.

To Reproduce Steps to reproduce the behavior:

It's just something I noticed reviewing the code

Expected behavior My guess is that since the recurring key on the schedule is required, you should prob do a num_left: Math.max(1, subscriptionDefinition.billingCyclesLeft), on the recurring key. But it makes sense to examine that approach for new edge cases.

Environment

martijnvdbrug commented 1 week ago

Good catch. I think actually it should always round up with Math.ceil: