1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Cancelling Stripe subscription after a set period of time

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 08:12.

  1. Stack

    Stack Membro Participativo

    I want a subscription to cancel itself after a year. What's the go to way of implementing this?

    checkout_session = stripe.checkout.Session.create(
    payment_method_types=["card"],
    mode="subscription",
    customer=stripe_customer_id, # Use existing customer ID
    line_items=[
    {
    "price": product.stripe_recurring_price_id, # Recurring subscription price
    "quantity": 1,
    },
    {
    # First month extra fees
    "price_data": {
    "currency": "myr",
    "product": "PRODUCT_ID", # One time charge
    "unit_amount": 4000, # RM40 in cents
    "recurring": None, # No recurring charges for this item
    },
    "quantity": 1,
    },
    ],
    metadata=metadata,
    # TODO: Add cancellation for subscription after 12 months
    success_url=YOUR_DOMAIN + "success?success=true",
    cancel_url=YOUR_DOMAIN + "success?canceled=true",
    )
    return JsonResponse(
    {"id": checkout_session.id, "url": checkout_session.url}
    )


    I'm using "stripe.checkout.Session.create" instead of "stripe.Subscription.create" because there's an extra fee for the first month. This was the only solution I had. If there's another solution then do share.

    Basically, I need to be able to set the subscription to last a year and cancels itself after a year. The subscription should not last for more than a year.

    Continue reading...

Compartilhe esta Página