def payment_methods(self, request, pk, org): billcon = request.GET.get("billcon") if not billcon: return Response({"billcon": ["Required field"]}, status=400) queryset = models.PaymentMethod.get_for_org(org).filter( billcon_id=billcon) serializer = Serializers.pay(queryset, many=True) return Response(serializer.data)
def payment_method(self, request, pk, org, auditlog=None): pay = models.PaymentMethod.objects.get(billcon__org=org, id=request.data.get("id")) if pay.billcon.pay_set.filter(status="ok").count() <= 1: return Response( { "non_field_errors": [ "Need at least one payment method set on a billing contact. Delete the billing contact itself if it is no longer needed" ] }, status=400, ) old_id = pay.id models.Subscription.set_payment_method(org, replace=pay) pay.delete() pay.id = old_id serializer = Serializers.pay(pay, many=False) return Response(serializer.data)