Ejemplo n.º 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)
Ejemplo n.º 2
0
    def post(self, request):
        form = DeletePayMethodForm(request.user, request.data)
        if not form.is_valid():
            return error_400(response=form.errors)

        pay_method = form.cleaned_data.get('pay_method_uri')
        log.info('deleting payment method for user: {} {}'
                 .format(pay_method, request.user))

        # This is a workaround for accessing the /delete/ path without slumber
        # thinking it's an HTTP DELETE.
        solitude.api().braintree.paymethod('delete').post({
            'paymethod': pay_method,
        })

        payment_methods = get_active_user_pay_methods(request.user)
        return Response({'payment_methods': payment_methods}, status=200)
Ejemplo n.º 3
0
    def post(self, request):
        api = solitude.api()

        data = request.data.copy()
        data['buyer_uuid'] = request.user.uuid
        try:
            result = api.braintree.paymethod.post(data)
        except HttpClientError, exc:
            log.warn('post: solitude returned 400: {}'.format(exc))
            return error_400(exception=exc)
Ejemplo n.º 4
0
 def create_email_only_buyer(self, email):
     api = solitude.api()
     buyer = api.generic.buyer.post({
         'email': email,
         'authenticated': False,
         'uuid': 'service:unauthenticated:{}'.format(uuid.uuid4())
     })
     log.info('Created email-only buyer {} for email {}'
              .format(buyer['uuid'], email))
     auth_utils.set_up_braintree_customer(buyer)
     return self.user_from_api(buyer)
Ejemplo n.º 5
0
    def post(self, request):
        bt_data = solitude.api().braintree.token.generate.post({})

        # Generate a new token for added security.
        csrf.rotate_token(request)

        # This view returns a CSRF token to the client so that it can
        # initialize API usage for anonymous payments (e.g. donations).
        # For added security, we could restrict the scope of that CSRF
        # tokens only to views relating to products that support
        # anonymous payments.

        return Response({
            'token': bt_data['token'],
            'csrf_token': csrf.get_token(request),
        })
Ejemplo n.º 6
0
 def __init__(self, *args, **kw):
     super(SolitudeAPIView, self).__init__(*args, **kw)
     # Get a sys.modules reference so that mocking from tests is easier.
     from payments_service import solitude
     self.api = solitude.api()
Ejemplo n.º 7
0
 def __init__(self, *args, **kw):
     super(Webhook, self).__init__(*args, **kw)
     self.api = solitude.api()
Ejemplo n.º 8
0
def get_active_user_pay_methods(user):
    api = solitude.api()
    return api.braintree.mozilla.paymethod.get(
        braintree_buyer__buyer__uuid=user.uuid,
        active=True,
    )