Beispiel #1
0
def debug_email(request):
    if not settings.DEBUG:
        return error_403('Only available in debug mode.')

    kind = request.GET.get('kind', 'subscription_charged_successfully')
    premailed = bool(request.GET.get('premailed', 0))
    log.info('Generating email with pre-mailed setting: {}'.format(premailed))
    webhook = Webhook()
    api = solitude.api()

    # Just get the last transaction.
    try:
        bt = api.braintree.mozilla.transaction.get()[0]
    except IndexError:
        raise IndexError(
            'No latest transaction found, ensure you buy a subscription and '
            'complete a webhook from braintree (or use the braintree_webhook '
            'command).'
        )
    moz = api.by_url(bt['transaction']).get()
    method = api.by_url(bt['paymethod']).get()
    product = payments_config.products[
        api.by_url(moz['seller_product']).get()['public_id']
    ]

    # Render the HTML.
    data = webhook.build_context(bt, moz, method, product, kind)
    response = webhook.render_html(data, kind, premailed)

    return HttpResponse(response, status=200)
    def patch(self, request, pk=None):
        """
        Allow patching of payment methods.

        * verify that the user wanting to make a patch is allowed too
        * send through the patch
        """
        # Get the active paymethod filtered by logged in user.
        res = self.get(request, pk=pk)

        if res.status_code != 200:
            # This would be a 404 if the user is trying to patch a
            # paymethod they do not own.
            log.warning(
                '_api_request returned: {} when trying to '
                'access paymethod: {}, user: {}'
                .format(res.status_code, pk, request.user.uuid)
            )
            return error_403('Not allowed')

        return super(PayMethod, self).patch(request, pk=pk)