Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def render(self):
""" Fetch the subscription details from Recurly and create Salesforce objects.
Then, redirec the user to the thank you page """
# SFAPI: Uses 5 calls to register donation in Salesforce, ~2,000 recurring
# subscription creations per day with the standard nonprofit 10k calls per day
token = self.request.form.get('recurly_token')
if not token:
return 'ERROR: No token provided'
# workaround for http://bugs.python.org/issue5285, map unicode to strings
settings = get_settings()
recurly.API_KEY = str(settings.recurly_api_key)
recurly.js.PRIVATE_KEY = str(settings.recurly_private_key)
# Set a default currency for your API requests
recurly.DEFAULT_CURRENCY = 'USD'
sub = recurly.js.fetch(token)
account = sub.account()
billing_info = account.billing_info
email = account.email.lower()
street_address = billing_info.address1
if billing_info.address2:
street_address = '%s\n%s' % (street_address, billing_info.address2)
# Look for an existing Plone user
mt = getToolByName(self.context, 'portal_membership')
res = get_brains_for_email(self.context, email, self.request)
# SFAPI: Uses 5 calls to register donation in Salesforce, ~2,000 recurring
# subscription creations per day with the standard nonprofit 10k calls per day
token = self.request.form.get('recurly_token')
if not token:
return 'ERROR: No token provided'
# workaround for http://bugs.python.org/issue5285, map unicode to strings
settings = get_settings()
recurly.API_KEY = str(settings.recurly_api_key)
recurly.js.PRIVATE_KEY = str(settings.recurly_private_key)
# Set a default currency for your API requests
recurly.DEFAULT_CURRENCY = 'USD'
sub = recurly.js.fetch(token)
account = sub.account()
billing_info = account.billing_info
email = account.email.lower()
street_address = billing_info.address1
if billing_info.address2:
street_address = '%s\n%s' % (street_address, billing_info.address2)
# Look for an existing Plone user
mt = getToolByName(self.context, 'portal_membership')
res = get_brains_for_email(self.context, email, self.request)
# If no existing user, create one which creates the contact in SF (1 API call)
if not res:
data = {
'first_name': account.first_name,