示例#1
0
    def post(self, request, format='json'):
        try:
            braintree_user = SubscriptionManager.fetch_braintree_user(
                request.user)
        except BraintreeError:
            return Response(
                {
                    'errors':
                    ["User not initialized properly. Please contact support"]
                },
                status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        try:
            SubscriptionManager.renew(braintree_user)
            LOGGER.info("Renewed subscription for user %s",
                        str(self.request.user))
            return Response({}, status=status.HTTP_202_ACCEPTED)
        except Exception as e:
            LOGGER.exception("Unknown exception in subscription renewal.")
            return Response({'errors': [e.message]},
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)