Django Stripe


1. Creating a Charge:

from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from stripe.api_resources.charge import Charge

@csrf_exempt
def create_charge(request):
    # Get the payment token from the request
    token = request.POST.get('stripeToken')

    # Create a Stripe customer
    customer = stripe.Customer.create(
        email=request.POST.get('email'),
        source=token,
    )

    # Charge the customer for the specified amount
    charge = Charge.create(
        customer=customer.id,
        amount=request.POST.get('amount'),
        currency=request.POST.get('currency'),
        description=request.POST.get('description'),
    )

    return HttpResponse(status=200)

2. Creating a Subscription:

3. Creating a Customer:

4. Updating a Customer:

5. Deleting a Customer:

6. Retrieving a Customer:

7. Listing Customers:

8. Creating a Payment Intent:

9. Retrieving a Payment Intent:

10. Confirming a Payment Intent:

11. Capturing a Payment:

12. Refunding a Payment:

13. Webhook Handling (Stripe Event):

14. Creating a Plan:

15. Updating a Plan:

16. Deleting a Plan:

17. Retrieving a Plan:

18. Listing Plans:

19. Creating a Product:

20. Updating a Product:

21. Deleting a Product:

22. Retrieving a Product:

23. Listing Products:

24. Invoicing:

25. Retrieving an Invoice:

26. Listing Invoices:

27. Sending an Invoice:

28. Marking an Invoice as Paid:

29. Updating an Invoice:

30. Retrieving Upcoming Invoice Items:

31. Creating an Invoice Item:

32. Updating an Invoice Item:

33. Deleting an Invoice Item:

34. Retrieving an Invoice Item:

35. Listing Invoice Items:

36. Setting a Stripe Subscription to Cancel at the End of the Billing Period: