示例#1
0
def payment(request, status=None):
    # Note this is not post required, because PayPal does not reply with a
    # POST but a GET, that's a sad face.
    pre, created = PreApprovalUser.objects.safer_get_or_create(user=request.amo_user)

    context = {"preapproval": pre, "currency": CurrencyForm(initial={"currency": pre.currency or "USD"})}

    if status:
        data = request.session.get("setup-preapproval", {})

        context["status"] = status

        if status == "complete":
            # The user has completed the setup at PayPal and bounced back.
            if "setup-preapproval" in request.session:
                if waffle.flag_is_active(request, "solitude-payments"):
                    client.put_preapproval(data={"uuid": request.amo_user}, pk=data["solitude-key"])

                paypal_log.info(u"Preapproval key created: %s" % request.amo_user.pk)
                amo.log(amo.LOG.PREAPPROVAL_ADDED)
                # TODO(solitude): once this is turned off, we will want to
                # keep preapproval table populated with something, perhaps
                # a boolean inplace of pre-approval key.
                pre.update(paypal_key=data.get("key"), paypal_expiry=data.get("expiry"))

                # If there is a target, bounce to it and don't show a message
                # we'll let whatever set this up worry about that.
                if data.get("complete"):
                    return http.HttpResponseRedirect(data["complete"])

                messages.success(request, _("You're all set for instant app purchases with PayPal."))
                del request.session["setup-preapproval"]

        elif status == "cancel":
            # The user has chosen to cancel out of PayPal. Nothing really
            # to do here, PayPal just bounce to the cancel page if defined.
            if data.get("cancel"):
                return http.HttpResponseRedirect(data["cancel"])

            messages.success(request, _("Your payment pre-approval has been cancelled."))

        elif status == "remove":
            # The user has an pre approval key set and chooses to remove it
            if waffle.flag_is_active(request, "solitude-payments"):
                other = client.lookup_buyer_paypal(request.amo_user)
                if other:
                    client.patch_buyer_paypal(pk=other["resource_pk"], data={"key": ""})

            if pre.paypal_key:
                # TODO(solitude): again, we'll want to maintain some local
                # state in zamboni, so this will probably change to a
                # boolean in the future.
                pre.update(paypal_key="")

                amo.log(amo.LOG.PREAPPROVAL_REMOVED)
                messages.success(request, _("Your payment pre-approval has been disabled."))
                paypal_log.info(u"Preapproval key removed for user: %s" % request.amo_user)

    return jingo.render(request, "account/payment.html", context)
示例#2
0
文件: test.py 项目: lmorchard/zamboni
 def test_create_exists(self, get_buyer):
     get_buyer.return_value = {
         'meta': {
             'total_count': 1
         },
         'objects': [{
             'paypal': 'foo'
         }]
     }
     eq_(client.lookup_buyer_paypal(self.user), 'foo')
示例#3
0
def payment(request, status=None):
    # Note this is not post required, because PayPal does not reply with a
    # POST but a GET, that's a sad face.
    pre, created = (PreApprovalUser.objects.safer_get_or_create(
        user=request.amo_user))

    context = {
        'preapproval': pre,
        'currency': CurrencyForm(initial={'currency': pre.currency or 'USD'})
    }

    if status:
        data = request.session.get('setup-preapproval', {})

        context['status'] = status

        if status == 'complete':
            # The user has completed the setup at PayPal and bounced back.
            if 'setup-preapproval' in request.session:
                if waffle.flag_is_active(request, 'solitude-payments'):
                    client.put_preapproval(data={'uuid': request.amo_user},
                                           pk=data['solitude-key'])

                paypal_log.info(u'Preapproval key created: %s' %
                                request.amo_user.pk)
                amo.log(amo.LOG.PREAPPROVAL_ADDED)
                # TODO(solitude): once this is turned off, we will want to
                # keep preapproval table populated with something, perhaps
                # a boolean inplace of pre-approval key.
                pre.update(paypal_key=data.get('key'),
                           paypal_expiry=data.get('expiry'))

                # If there is a target, bounce to it and don't show a message
                # we'll let whatever set this up worry about that.
                if data.get('complete'):
                    return http.HttpResponseRedirect(data['complete'])

                messages.success(
                    request,
                    _("You're all set for instant app purchases with PayPal."))
                del request.session['setup-preapproval']

        elif status == 'cancel':
            # The user has chosen to cancel out of PayPal. Nothing really
            # to do here, PayPal just bounce to the cancel page if defined.
            if data.get('cancel'):
                return http.HttpResponseRedirect(data['cancel'])

            messages.success(
                request, _('Your payment pre-approval has been cancelled.'))

        elif status == 'remove':
            # The user has an pre approval key set and chooses to remove it
            if waffle.flag_is_active(request, 'solitude-payments'):
                other = client.lookup_buyer_paypal(request.amo_user)
                if other:
                    client.patch_buyer_paypal(pk=other['resource_pk'],
                                              data={'key': ''})

            if pre.paypal_key:
                # TODO(solitude): again, we'll want to maintain some local
                # state in zamboni, so this will probably change to a
                # boolean in the future.
                pre.update(paypal_key='')

                amo.log(amo.LOG.PREAPPROVAL_REMOVED)
                messages.success(
                    request, _('Your payment pre-approval has been disabled.'))
                paypal_log.info(u'Preapproval key removed for user: %s' %
                                request.amo_user)

    return jingo.render(request, 'account/payment.html', context)
示例#4
0
文件: views.py 项目: lauraxt/zamboni
def payment(request, status=None):
    # Note this is not post required, because PayPal does not reply with a
    # POST but a GET, that's a sad face.
    pre, created = (PreApprovalUser.objects
                                   .safer_get_or_create(user=request.amo_user))

    context = {'preapproval': pre,
               'currency': CurrencyForm(initial={'currency':
                                                 pre.currency or 'USD'})}

    if status:
        data = request.session.get('setup-preapproval', {})

        context['status'] = status

        if status == 'complete':
            # The user has completed the setup at PayPal and bounced back.
            if 'setup-preapproval' in request.session:
                if waffle.flag_is_active(request, 'solitude-payments'):
                    client.put_preapproval(data={'uuid': request.amo_user},
                                           pk=data['solitude-key'])

                paypal_log.info(u'Preapproval key created: %s' %
                                request.amo_user.pk)
                amo.log(amo.LOG.PREAPPROVAL_ADDED)
                # TODO(solitude): once this is turned off, we will want to
                # keep preapproval table populated with something, perhaps
                # a boolean inplace of pre-approval key.
                pre.update(paypal_key=data.get('key'),
                           paypal_expiry=data.get('expiry'))

                # If there is a target, bounce to it and don't show a message
                # we'll let whatever set this up worry about that.
                if data.get('complete'):
                    return redirect(data['complete'])

                messages.success(request,
                    _("You're all set for instant app purchases with PayPal."))
                del request.session['setup-preapproval']

        elif status == 'cancel':
            # The user has chosen to cancel out of PayPal. Nothing really
            # to do here, PayPal just bounce to the cancel page if defined.
            if data.get('cancel'):
                return redirect(data['cancel'])

            messages.success(request,
                _('Your payment pre-approval has been cancelled.'))

        elif status == 'remove':
            # The user has an pre approval key set and chooses to remove it
            if waffle.flag_is_active(request, 'solitude-payments'):
                other = client.lookup_buyer_paypal(request.amo_user)
                if other:
                    client.patch_buyer_paypal(pk=other['resource_pk'],
                                              data={'key': ''})

            if pre.paypal_key:
                # TODO(solitude): again, we'll want to maintain some local
                # state in zamboni, so this will probably change to a
                # boolean in the future.
                pre.update(paypal_key='')

                amo.log(amo.LOG.PREAPPROVAL_REMOVED)
                messages.success(request,
                    _('Your payment pre-approval has been disabled.'))
                paypal_log.info(u'Preapproval key removed for user: %s'
                                % request.amo_user)

    return jingo.render(request, 'account/payment.html', context)
示例#5
0
文件: test.py 项目: lmorchard/zamboni
 def test_create_err(self, get_buyer):
     get_buyer.return_value = {'meta': {'total_count': 2}}
     with self.assertRaises(ValueError):
         client.lookup_buyer_paypal(self.user)
示例#6
0
 def test_create_err(self, get_buyer):
     get_buyer.return_value = {'meta': {'total_count': 2}}
     with self.assertRaises(ValueError):
         client.lookup_buyer_paypal(self.user)
示例#7
0
 def test_create_exists(self, get_buyer):
     get_buyer.return_value = {'meta': {'total_count': 1},
                               'objects': [{'paypal': 'foo'}]}
     eq_(client.lookup_buyer_paypal(self.user), 'foo')
示例#8
0
 def test_create_exists(self, get_buyer):
     get_buyer.return_value = {"meta": {"total_count": 1}, "objects": [{"paypal": "foo"}]}
     eq_(client.lookup_buyer_paypal(self.user), "foo")