djangostripe-paymentspayment-gatewaysubscription

Adjust Stripe Subscription Billing Interval


I aim to modify the billing interval of a subscription in Stripe to include a one-time complimentary extension of 3 months when a user subscribes to a product. The regular billing interval for the plan is 1 year, resulting in a 15-month billing period with the extension. However, after this extended period, it should revert back to the original 1-year billing interval. This isn't a trial period; it's a complimentary 3-month extension for which I want to charge the user immediately.

Below is my current implementation for the checkout session view, and I manage all changes using Stripe webhook

class CreateCheckoutSessionView(View):
    def post(self, request, *args, **kwrgs):
        ...
        
        checkout_session = stripe.checkout.Session.create(
                success_url=protocol + domain + reverse('payment_success')+'?session_id={CHECKOUT_SESSION_ID}',
                cancel_url = protocol + domain + reverse('payment_failed'),
                payment_method_types=['card'],
                mode='subscription',
                customer=customer.id,
                line_items=[{
                    'price': price_id,
                    'quantity': 1,
                    'metadata': {
                    }
                }],
                allow_promotion_codes = True,
                subscription_data={
                    'default_tax_rates': [STRIP_TAX_ID],
                },
            )
        return redirect(checkout_session.url, code=303)

Solution

  • You can create a Checkout Session for a yearly Subscription. Then when your receive the checkout.session.completed webhook event, make an extra API call to update the Subscription and add a 3 month free trial.

    This way: