# Path: billing/views.py
# class AccountView(RetrieveAPIView):
#     """
#     get: Retrieve the full billing account information.
#     """
#     serializer_class = AccountSerializer
#     pagination_class = None
# 
#     def get_object(self):
#         try:
#             return Account.objects.open() \
#                 .prefetch_related('invoices') \
#                 .prefetch_related('credit_cards') \
#                 .prefetch_related('transactions') \
#                 .prefetch_related('charges__product_properties') \
#                 .get(owner=self.request.user)
#         except Account.DoesNotExist:
#             raise Http404('No Account matches the given query.')
# 
# class CreditCardViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericViewSet):
#     """
#     list: Return the list of credit cards registered on the account.
#     retrieve: Return the credit card information
#     partial_update: Change the status of the creditcard.
#     """
#     http_method_names = ['get', 'patch']  # We don't want put (inherited from UpdateModelMixin)
# 
#     def get_queryset(self):
#         return CreditCard.objects.filter(account__owner=self.request.user)
# 
#     def get_serializer_class(self):
#         method = self.request.method
#         if method == 'GET':
#             return CreditCardSerializer
#         elif method == 'PATCH':
#             return CreditCardUpdateSerializer
#         else:
#             raise Exception('Unknown method')
# 
# @permission_classes([permissions.IsAuthenticated])
# @api_view(['POST'])
# def pay_open_invoices_with_registered_credit_cards(request):
#     account = request.user.billing_account
#     assign_funds_to_account_pending_invoices(account_id=account.id)
#     summary = charge_pending_invoices(account_id=account.id)
#     account.refresh_from_db()
#     success = not account.delinquent
#     if success:
#         debt_paid.send(
#             sender=pay_open_invoices_with_registered_credit_cards,
#             account=account
#         )
#     return Response({'success': success, 'summary': summary}, status=HTTP_200_OK)


from django.urls import path
from rest_framework import routers
from .views import (
    AccountView,
    CreditCardViewSet,
    pay_open_invoices_with_registered_credit_cards,
)



router = routers.SimpleRouter(trailing_slash=False)
router.register(
    r'account/credit-cards',
    CreditCardViewSet,
    basename='billing_creditcard'
)

urlpatterns = router.urls + [
    path('account', AccountView.as_view(), name='billing_account'),
    path(

# Path: billing/views.py
# class AccountView(RetrieveAPIView):
#     """
#     get: Retrieve the full billing account information.
#     """
#     serializer_class = AccountSerializer
#     pagination_class = None
# 
#     def get_object(self):
#         try:
#             return Account.objects.open() \
#                 .prefetch_related('invoices') \
#                 .prefetch_related('credit_cards') \
#                 .prefetch_related('transactions') \
#                 .prefetch_related('charges__product_properties') \
#                 .get(owner=self.request.user)
#         except Account.DoesNotExist:
#             raise Http404('No Account matches the given query.')
# 
# class CreditCardViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericViewSet):
#     """
#     list: Return the list of credit cards registered on the account.
#     retrieve: Return the credit card information
#     partial_update: Change the status of the creditcard.
#     """
#     http_method_names = ['get', 'patch']  # We don't want put (inherited from UpdateModelMixin)
# 
#     def get_queryset(self):
#         return CreditCard.objects.filter(account__owner=self.request.user)
# 
#     def get_serializer_class(self):
#         method = self.request.method
#         if method == 'GET':
#             return CreditCardSerializer
#         elif method == 'PATCH':
#             return CreditCardUpdateSerializer
#         else:
#             raise Exception('Unknown method')
# 
# @permission_classes([permissions.IsAuthenticated])
# @api_view(['POST'])
# def pay_open_invoices_with_registered_credit_cards(request):
#     account = request.user.billing_account
#     assign_funds_to_account_pending_invoices(account_id=account.id)
#     summary = charge_pending_invoices(account_id=account.id)
#     account.refresh_from_db()
#     success = not account.delinquent
#     if success:
#         debt_paid.send(
#             sender=pay_open_invoices_with_registered_credit_cards,
#             account=account
#         )
#     return Response({'success': success, 'summary': summary}, status=HTTP_200_OK)


# Path: billing/urls.py
from django.urls import path
from rest_framework import routers
from .views import (
    AccountView,
    CreditCardViewSet,
    pay_open_invoices_with_registered_credit_cards,
)




router = routers.SimpleRouter(trailing_slash=False)
router.register(
    r'account/credit-cards',
    CreditCardViewSet,
    basename='billing_creditcard'
)

urlpatterns = router.urls + [
    path('account', AccountView.as_view(), name='billing_account'),
    path(

        'pay/open/invoices/with/registered/credit/cards',