Example #1
0
def preapproval(request, complete=None, cancel=None):
    if waffle.switch_is_active('currencies'):
        failure = currency(request, do_redirect=False)
        if failure:
            return failure

    today = datetime.today()
    data = {
        'startDate': today,
        'endDate': today + timedelta(days=365),
    }
    store = {
        'expiry': data['endDate'],
        'solitude-key': None,
        'complete': complete,
        'cancel': cancel,
    }

    if waffle.flag_is_active(request, 'solitude-payments'):
        client.create_buyer_if_missing(request.amo_user)
        try:
            result = client.post_preapproval(
                data={
                    'start':
                    data['startDate'].date(),
                    'end':
                    data['endDate'].date(),
                    'uuid':
                    request.amo_user,
                    'return_url':
                    absolutify(reverse('account.payment', args=['complete'])),
                    'cancel_url':
                    absolutify(reverse('account.payment', args=['cancel'])),
                })
        except client.Error:
            paypal_log.error(u'preapproval', exc_info=True)
            raise

        store.update({'key': result['key'], 'solitude-key': result['pk']})
        url = result['paypal_url']

    else:
        # TODO(solitude): remove this.
        data.update({'pattern': 'account.payment'})
        try:
            result = paypal.get_preapproval_key(data)
        except paypal.PaypalError, e:
            paypal_log.error(u'Preapproval key: %s' % e, exc_info=True)
            raise

        store.update({'key': result['preapprovalKey']})
        url = paypal.get_preapproval_url(result['preapprovalKey'])
Example #2
0
def preapproval(request, complete=None, cancel=None):
    if waffle.switch_is_active('currencies'):
        failure = currency(request, do_redirect=False)
        if failure:
            return failure

    today = datetime.today()
    data = {
        'startDate': today,
        'endDate': today + timedelta(days=365),
    }
    store = {
        'expiry': data['endDate'],
        'solitude-key': None,
        'complete': complete,
        'cancel': cancel,
    }

    if waffle.flag_is_active(request, 'solitude-payments'):
        client.create_buyer_if_missing(request.amo_user)
        try:
            result = client.post_preapproval(data={
                'start': data['startDate'].date(),
                'end': data['endDate'].date(),
                'uuid': request.amo_user,
                'return_url': absolutify(reverse('account.payment',
                                                 args=['complete'])),
                'cancel_url': absolutify(reverse('account.payment',
                                                  args=['cancel'])),
            })
        except client.Error:
            paypal_log.error(u'preapproval', exc_info=True)
            raise

        store.update({'key': result['key'], 'solitude-key': result['pk']})
        url = result['paypal_url']

    else:
        # TODO(solitude): remove this.
        data.update({'pattern': 'account.payment'})
        try:
            result = paypal.get_preapproval_key(data)
        except paypal.PaypalError, e:
            paypal_log.error(u'Preapproval key: %s' % e, exc_info=True)
            raise

        store.update({'key': result['preapprovalKey']})
        url = paypal.get_preapproval_url(result['preapprovalKey'])
Example #3
0
def preapproval(request, complete=None, cancel=None):
    if waffle.switch_is_active("currencies"):
        failure = currency(request, do_redirect=False)
        if failure:
            return failure

    today = datetime.today()
    data = {"startDate": today, "endDate": today + timedelta(days=365)}
    store = {"expiry": data["endDate"], "solitude-key": None, "complete": complete, "cancel": cancel}

    if waffle.flag_is_active(request, "solitude-payments"):
        client.create_buyer_if_missing(request.amo_user)
        try:
            result = client.post_preapproval(
                data={
                    "start": data["startDate"].date(),
                    "end": data["endDate"].date(),
                    "uuid": request.amo_user,
                    "return_url": absolutify(reverse("account.payment", args=["complete"])),
                    "cancel_url": absolutify(reverse("account.payment", args=["cancel"])),
                }
            )
        except client.Error:
            paypal_log.error(u"preapproval", exc_info=True)
            raise

        store.update({"key": result["key"], "solitude-key": result["pk"]})
        url = result["paypal_url"]

    else:
        # TODO(solitude): remove this.
        data.update({"pattern": "account.payment"})
        try:
            result = paypal.get_preapproval_key(data)
        except paypal.PaypalError, e:
            paypal_log.error(u"Preapproval key: %s" % e, exc_info=True)
            raise

        store.update({"key": result["preapprovalKey"]})
        url = paypal.get_preapproval_url(result["preapprovalKey"])
Example #4
0
 def test_not_created(self, post_buyer, get_buyer):
     get_buyer.return_value = {'meta': {'total_count': 1}}
     client.create_buyer_if_missing(self.user)
     assert not post_buyer.called
Example #5
0
 def test_not_created(self, post_buyer, get_buyer):
     get_buyer.return_value = {'meta': {'total_count': 1}}
     client.create_buyer_if_missing(self.user)
     assert not post_buyer.called
Example #6
0
 def test_create(self, post_buyer, get_buyer):
     get_buyer.return_value = {"meta": {"total_count": 0}}
     client.create_buyer_if_missing(self.user)
     assert post_buyer.called