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'])
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'])
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"])
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
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