Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_anonymous_pledge(self):
# The form must contain the anonymous field.
back_url = app_reverse('zipfelchappe_backer_create', app_settings.ROOT_URLS,
kwargs={'slug': self.project1.slug})
detail_url = app_reverse('zipfelchappe_project_detail', app_settings.ROOT_URLS,
kwargs={'slug': self.project1.slug})
response = self.client.get(back_url)
self.assertContains(response, '
def test_user_stays_logged_in(self):
self.client.login(username=self.user, password='test')
session_id = self.client.cookies['sessionid'].value
response = self.client.get(self.project1.get_absolute_url())
self.assertEqual(200, response.status_code)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
back_url = app_reverse('zipfelchappe_backer_create', app_settings.ROOT_URLS,
kwargs={"slug": self.project1.slug})
authenticate_url = app_reverse('zipfelchappe_backer_authenticate', app_settings.ROOT_URLS)
payment_url = reverse('zipfelchappe_paypal_payment')
thank_you_url = app_reverse('zipfelchappe_pledge_thankyou', app_settings.ROOT_URLS)
backed_url = app_reverse('zipfelchappe_project_backed', app_settings.ROOT_URLS,
kwargs={'slug': self.project1.slug})
response = self.client.get(back_url)
self.assertEqual(200, response.status_code)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
response = self.client.post(back_url, {
'project': self.project1.id,
'amount': '20',
'reward': self.reward.id,
'provider': 'paypal',
'accept_tac': True
def test_user_stays_logged_in_on_reload_before_payment(self):
""" Here the user backs a project and then returns to the backing page before
the payment process is completed.
"""
self.client.login(username=self.user, password='test')
session_id = self.client.cookies['sessionid'].value
response = self.client.get(self.project1.get_absolute_url())
self.assertEqual(200, response.status_code)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
back_url = app_reverse('zipfelchappe_backer_create', app_settings.ROOT_URLS,
kwargs={"slug": self.project1.slug})
authenticate_url = app_reverse('zipfelchappe_backer_authenticate', app_settings.ROOT_URLS)
payment_url = reverse('zipfelchappe_paypal_payment')
thank_you_url = app_reverse('zipfelchappe_pledge_thankyou', app_settings.ROOT_URLS)
backed_url = app_reverse('zipfelchappe_project_backed', app_settings.ROOT_URLS,
kwargs={'slug': self.project1.slug})
response = self.client.get(back_url)
self.assertEqual(200, response.status_code)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
response = self.client.post(back_url, {
'project': self.project1.id,
'amount': '20',
'reward': self.reward.id,
'provider': 'paypal',
'accept_tac': True
})
self.assertRedirect(response, authenticate_url)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
def test_user_stays_logged_in(self):
self.client.login(username=self.user, password='test')
session_id = self.client.cookies['sessionid'].value
response = self.client.get(self.project1.get_absolute_url())
self.assertEqual(200, response.status_code)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
back_url = app_reverse('zipfelchappe_backer_create', app_settings.ROOT_URLS,
kwargs={"slug": self.project1.slug})
authenticate_url = app_reverse('zipfelchappe_backer_authenticate', app_settings.ROOT_URLS)
payment_url = reverse('zipfelchappe_paypal_payment')
thank_you_url = app_reverse('zipfelchappe_pledge_thankyou', app_settings.ROOT_URLS)
backed_url = app_reverse('zipfelchappe_project_backed', app_settings.ROOT_URLS,
kwargs={'slug': self.project1.slug})
response = self.client.get(back_url)
self.assertEqual(200, response.status_code)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
response = self.client.post(back_url, {
'project': self.project1.id,
'amount': '20',
'reward': self.reward.id,
'provider': 'paypal',
'accept_tac': True
})
self.assertRedirect(response, authenticate_url)
self.assertEqual(self.client.cookies['sessionid'].value, session_id)
response = self.client.get(authenticate_url)
}
# ISO-8859-1
form_params['SHASign'] = sha1(u''.join((
form_params['orderID'],
form_params['amount'],
form_params['currency'],
form_params['PSPID'],
POSTFINANCE['SHA1_IN'],
))).hexdigest()
base_url = 'http://%s' % get_current_site(request)
accept_url = base_url + app_reverse('zipfelchappe_pledge_thankyou', ROOT_URLS)
# global decline and exception URLs are used.
decline_url = base_url + reverse('zipfelchappe_postfinance_declined')
exception_url = base_url + reverse('zipfelchappe_postfinance_exception')
cancel_url = base_url + app_reverse('zipfelchappe_pledge_cancel', ROOT_URLS)
return render(request, 'zipfelchappe/postfinance_form.html', {
'pledge': pledge,
'form_params': form_params,
'locale': to_locale(get_language()),
'accept_url': accept_url,
'decline_url': decline_url,
'exception_url': exception_url,
'cancel_url': cancel_url,
})
def create_preapproval(pledge):
site = Site.objects.get_current()
url = PP_API_URL + '/AdaptivePayments/Preapproval'
data = {
'returnUrl': 'http://%s%s' % (site,
app_reverse('zipfelchappe_pledge_thankyou', ROOT_URLS)),
'cancelUrl': 'http://%s%s' % (site,
app_reverse('zipfelchappe_pledge_cancel', ROOT_URLS)),
'ipnNotificationUrl': 'http://%s%s' % (site,
reverse('zipfelchappe_paypal_ipn')),
'currencyCode': pledge.currency,
'maxNumberOfPayments': 1,
'maxTotalAmountOfAllPayments': unicode(pledge.amount),
'displayMaxTotalAmount': True,
'startingDate': zuluTimeFormat(datetime.utcnow()),
'endingDate': zuluTimeFormat(pledge.project.end),
'memo': pledge.project.title,
'pinType': 'NOT_REQUIRED',
"requestEnvelope": {'errorLanguage': 'en_US'},
}
logger.debug('ipn url %s' % data['ipnNotificationUrl'])
def reverse(view_name, *args, **kwargs):
""" Reverse within our app context """
return app_reverse(view_name, app_settings.ROOT_URLS, args=args, kwargs=kwargs)
'amount': unicode(amount),
'currency': pledge.currency,
'PSPID': POSTFINANCE['PSPID'],
'mode': 'prod' if POSTFINANCE['LIVE'] else 'test',
}
# ISO-8859-1
form_params['SHASign'] = sha1(u''.join((
form_params['orderID'],
form_params['amount'],
form_params['currency'],
form_params['PSPID'],
POSTFINANCE['SHA1_IN'],
))).hexdigest()
base_url = 'http://%s' % get_current_site(request)
accept_url = base_url + app_reverse('zipfelchappe_pledge_thankyou', ROOT_URLS)
# global decline and exception URLs are used.
decline_url = base_url + reverse('zipfelchappe_postfinance_declined')
exception_url = base_url + reverse('zipfelchappe_postfinance_exception')
cancel_url = base_url + app_reverse('zipfelchappe_pledge_cancel', ROOT_URLS)
return render(request, 'zipfelchappe/postfinance_form.html', {
'pledge': pledge,
'form_params': form_params,
'locale': to_locale(get_language()),
'accept_url': accept_url,
'decline_url': decline_url,
'exception_url': exception_url,
'cancel_url': cancel_url,
})
if not settings.PAYPAL['RECEIVERS']:
# TODO: do this on Project save as well.
raise ImproperlyConfigured(_('No paypal receivers defined!'))
receivers = [r.copy() for r in settings.PAYPAL['RECEIVERS']]
for receiver in receivers:
amount = pledge.amount * Decimal(str(receiver['percent']/100.00))
receiver.update({'amount': unicode(amount.quantize(Decimal('.01')))})
del receiver['percent']
data = {
'actionType': 'PAY',
'returnUrl': 'http://%s%s' % (site,
app_reverse('zipfelchappe_pledge_thankyou', ROOT_URLS)),
'cancelUrl': 'http://%s%s' % (site,
app_reverse('zipfelchappe_pledge_cancel', ROOT_URLS)),
'ipnNotificationUrl': 'http://%s%s' % (site,
reverse('zipfelchappe_paypal_ipn')),
'currencyCode': pledge.currency,
'preapprovalKey': preapproval.key,
'receiverList': {
'receiver': receivers
},
'reverseAllParallelPaymentsOnError': True,
'feesPayer': 'EACHRECEIVER',
'memo': pledge.project.title,
"requestEnvelope": {"errorLanguage": "en_US"},
}
return requests.post(url, headers=PP_REQ_HEADERS, data=json.dumps(data))
def create_preapproval(pledge):
site = Site.objects.get_current()
url = PP_API_URL + '/AdaptivePayments/Preapproval'
data = {
'returnUrl': 'http://%s%s' % (site,
app_reverse('zipfelchappe_pledge_thankyou', ROOT_URLS)),
'cancelUrl': 'http://%s%s' % (site,
app_reverse('zipfelchappe_pledge_cancel', ROOT_URLS)),
'ipnNotificationUrl': 'http://%s%s' % (site,
reverse('zipfelchappe_paypal_ipn')),
'currencyCode': pledge.currency,
'maxNumberOfPayments': 1,
'maxTotalAmountOfAllPayments': unicode(pledge.amount),
'displayMaxTotalAmount': True,
'startingDate': zuluTimeFormat(datetime.utcnow()),
'endingDate': zuluTimeFormat(pledge.project.end),
'memo': pledge.project.title,
'pinType': 'NOT_REQUIRED',
"requestEnvelope": {'errorLanguage': 'en_US'},
}
logger.debug('ipn url %s' % data['ipnNotificationUrl'])
response = requests.post(url, headers=PP_REQ_HEADERS, data=json.dumps(data))