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

Scheduled Subscriptions #110

Open
hannahwoodward opened this issue May 6, 2020 · 1 comment
Open

Scheduled Subscriptions #110

hannahwoodward opened this issue May 6, 2020 · 1 comment

Comments

@hannahwoodward
Copy link

When creating subscriptions via the Stripe dashboard, you can schedule them to start at a later date. Would it be possible to implement something similar via Commerce / the Commerce Stripe gateway?

@benrnorman
Copy link

I have found a half a solution that might be useful to some people, though it has a catch.

You could create a module and hook into the "EVENT_BEFORE_SUBSCRIBE" event to add the "billing_cycle_anchor" param. In the example below, I want all my subscribers to be billed at the same time on Mondays.

Event::on(
    StripeGateway::class,
    StripeGateway::EVENT_BEFORE_SUBSCRIBE,
    function(SubscriptionRequestEvent $e) {
        // Set the scheduled billing period for the following Monday
        $nextMonday = strtotime('next Monday');
        $e->parameters['billing_cycle_anchor'] = $nextMonday;
        // $e->parameters['proration_behavior'] = 'none';
    }
);

The Catch: at the moment, this will bill the user a prorated amount up until the scheduled billing anchor of next Monday. E.G. if it's a $7 subscription and they sign-up on Sunday, they will be immediately billed $1 (the prorated amount), and then the $7 the next day when the billing cycle begins.

You can set the "proration_behaviour" to "none", which prevents this behaviour in Stripe. However, then commerce-stripe throws errrors whenever you try to reference the subscription, as it expects a subscription to always have a latest invoice. For example, PaymentIntents.php expects it in getBillingIssueDescription: $intentData = $subscriptionData['latest_invoice']['payment_intent'];

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

No branches or pull requests

3 participants