In my opinion, the right approach is a combination of the two approaches provided, because you have to send the Stripe request to the ModelViewSet class, but save the Product object only after a successful service response.
Otherwise, if the service response fails, I will refuse every database operation (with Django 1.6+ you can do this using transaction.atomic() documented here ).
I donβt like your second approach, because, according to the DRF documentation about the create serializers.Serializer method, this method should only return a new Entity instance, taking into account the verified data, so I would not add another business logic.
As for the second question, I would structure the create method to use the injected layout object for the Stripe request, so you can check your code for any interaction with the external interface (obviously, this way you do not do this integration test, but unit test) .
source share