Stripe payment do something when payment is successfull Django

I have an app about posting an advertises and by default i made an expiration date for

every advertise (30 days) now i wanna use stripe to extend the expiration date.

what i have so far is the checkout but i want when the payment i success i update the database.

my checkout view :

class StripeCheckoutView(APIView):
    def post(self, request, *args, **kwargs):
        adv_id = self.kwargs["pk"]
        adv = Advertise.objects.get(id = adv_id)
            adv = Advertise.objects.get(id = adv_id)
            checkout_session = stripe.checkout.Session.create(
                        'price_data': {
                             'unit_amount': 50 * 100,

                        'quantity': 1,
                success_url=settings.SITE_URL + '?success=true',
                cancel_url=settings.SITE_URL + '?canceled=true',
            return redirect(checkout_session.url)
        except Exception as e:
            return Response({'msg':'something went wrong while creating stripe session','error':str(e)}, status=500)


# Create your models here.
class Advertise(models.Model):
    owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name="advertise")
    category = models.CharField(max_length= 200, choices = CATEGORY)
    location = models.CharField(max_length= 200, choices = LOCATIONS)
    description = models.TextField(max_length=600)
    price = models.FloatField(max_length=100)
    expiration_date  = models.DateField(default = Expire_date, blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
    updated_at = models.DateTimeField(auto_now=True, blank=True, null=True)

    class Meta:
        ordering = ['created_at']

    def __str__(self):
        return self.category

So what i want to do is check if the payment is successful nad if so i extend the expiration_date of this adv.

Thanks in advance.

In order to fulfill orders with Stripe Checkout, you need to set up webhooks[1] and listen for the event checkout.session.completed[2], which occurs when a Checkout Session has been successfully completed. More details can be found in this guide[3].

Meanwhile, according to your question it looks like you are building a recurring payment scenario for your customers. I may invite you to take a look at Stripe Billing and Subscriptions APIs[4]. You can keep tracking of active Subscriptions using webhooks also following this guide[5].






Back to Top