title: Django Rest Framework and Stripe, best practice?
body: <p>I'm struggling with philosophical questions in my DRF structure using the payement handler <a href="https://stripe.com">Stripe</a>. I'm selling a product that has a django model <code>Product</code> through my DRF REST API. I'm wondering if I should create the <code>Product</code> and then <strong>handle the payment in my <code>create</code> view</strong> as follow: </p>
  
  <pre><code>class ProductViewSet(viewsets.ModelViewSet):
  
  ...
  
  def create(self, request):
      serializer = ProductSerializer(data=request.data)
      serializer.is_valid(raise_exception=True)
      product = serializer.save()
  
      try:
          response = stripe.Charge.create(
              amount=product.cost,
              currency="usd",
              source=request.data["token"], # Done with Stripe.js
              description="Product"
          )
          product.charge_id = response.charge_id
  
          ...
  </code></pre>
  
  <p>or instead, if I should <strong>handle the payement in the serializer</strong> of <code>Product</code>:</p>
  
  <pre><code>class ProductSerializer(serializers.Serializer):
  
      ...
  
      def create(self, validated_data):
          product = Product.objects.create(**validated_data)
  
          # Will raise an Excetpion and stop the creation:
          response = stripe.Charge.create(
              amount=product.cost,
              currency="usd",
              source=validated_data["token"], # Done with Stripe.js
              description="Product"
          )
  
  
          return product 
  </code></pre>
  
  <p>Which one is the better practice? Or, do I completely miss the point and should do it differently?</p>
  
  <p>Secondly, is there a way to embed Stripe.js and the required form in the Browsable API template for the <code>create</code> route so I can test my REST without the need of any frontend?</p>
  
  <p>Thank you for your help</p>