serializers.py 948 B

123456789101112131415161718192021222324252627282930313233
  1. """
  2. .. module:: dj-stripe.contrib.rest_framework.serializers.
  3. :synopsis: dj-stripe - Serializers to be used with the dj-stripe REST API.
  4. """
  5. from djstripe.models import Subscription
  6. from rest_framework import serializers
  7. from rest_framework.serializers import ModelSerializer
  8. class SubscriptionSerializer(ModelSerializer):
  9. """A serializer used for the Subscription model."""
  10. class Meta:
  11. """Model class options."""
  12. model = Subscription
  13. exclude = ["default_tax_rates"]
  14. class CreateSubscriptionSerializer(serializers.Serializer):
  15. """A serializer used to create a Subscription."""
  16. stripe_token = serializers.CharField(max_length=200)
  17. plan = serializers.CharField(max_length=50)
  18. charge_immediately = serializers.BooleanField(
  19. required=False, allow_null=True, default=None
  20. )
  21. tax_percent = serializers.DecimalField(
  22. required=False, max_digits=5, decimal_places=2
  23. )