def pledge_helper(handler, data, stripe_customer_id, stripe_charge_id, paypal_payer_id, paypal_txn_id): env = handler.app.config['env'] if 'last_name' in data: last_name = data['last_name'] if 'first_name' in data: first_name = data['first_name'] else: first_name = '' else: # Split apart the name into first and last. Yes, this sucks, but adding the # name fields makes the form look way more daunting. We may reconsider # this. name_parts = data['name'].split(None, 1) first_name = name_parts[0] if len(name_parts) == 1: last_name = '' logging.warning('Could not determine last name: %s', data['name']) else: last_name = name_parts[1] if not 'surveyResult' in data: data['surveyResult'] = '' if not 'city' in data: data['city'] = None if not 'address' in data: data['address'] = None else: logging.info('Address was: ' + str(data['address'])) if not 'state' in data: data['state'] = None if not 'zipCode' in data: data['zipCode'] = None if not 'bitpay_invoice_id' in data: data['bitpay_invoice_id'] = None if not 'recurring' in data: data['recurring'] = False if not 'enddate' in data: data['enddate'] = '' if not 'recurrence_period' in data: data['recurrence_period'] = '' if not 'nationBuilderVars' in data: data['nationBuilderVars'] = None if not 'keep_donation' in data: data['keep_donation'] = False if not 'pledge_fulfillment' in data: data['pledge_fulfillment'] = False if not 'upsell' in data: data['upsell'] = False if not 'source' in data: data['source'] = None amountCents = data['amountCents'] pledge_type = data.get('pledgeType', model.Pledge.TYPE_CONDITIONAL) user, pledge = model.addPledge( email=data['email'], stripe_customer_id=stripe_customer_id, stripe_charge_id=stripe_charge_id, paypal_payer_id=paypal_payer_id, paypal_txn_id=paypal_txn_id, amount_cents=amountCents, first_name=first_name, last_name=last_name, occupation=data['occupation'], employer=data['employer'], phone=data['phone'], target=data['target'], surveyResult=data['surveyResult'], pledge_type=pledge_type, team=data['team'], source=data['source'], mail_list_optin=data['subscribe'], anonymous=data.get('anonymous', False), address=str(data['address']), city=data['city'], state=data['state'], zipCode=data['zipCode'], bitpay_invoice_id=data['bitpay_invoice_id'], recurring=data['recurring'], recurrence_period=data['recurrence_period'], enddate=data['enddate'], keep_donation=data['keep_donation'], upsell=data['upsell'], addressCheckPass=data.get('addressCheckPass', True), ) logging.info('Added pledge to database') if data['subscribe']: env.mailing_list_subscriber.Subscribe( email=data['email'], first_name=first_name, last_name=last_name, amount_cents=amountCents, ip_addr=handler.request.remote_addr, time=datetime.datetime.now(), source='pledge', phone=data['phone'], nonce=user.url_nonce, recurring=data['recurring'], zipcode=data['zipCode']) if False: model.addNationBuilderDonation( email=data['email'], stripe_customer_id=stripe_customer_id, stripe_charge_id=stripe_charge_id, paypal_payer_id=paypal_payer_id, paypal_txn_id=paypal_txn_id, amount_cents=amountCents, first_name=first_name, last_name=last_name, occupation=data['occupation'], employer=data['employer'], phone=data['phone'], target=data['target'], surveyResult=data['surveyResult'], pledge_type=pledge_type, team=data['team'], source=data['source'], mail_list_optin=data['subscribe'], anonymous=data.get('anonymous', False), address=str(data['address']), city=data['city'], state=data['state'], zipCode=data['zipCode'], bitpay_invoice_id=data['bitpay_invoice_id'], recurring=data['recurring'], enddate=data['enddate'], recurrence_period=data['recurrence_period'], nationBuilderVars=data['nationBuilderVars']) if data['pledge_fulfillment']: # Remove from stretch total. logging.info('Removing from stretch total: $%d' % int(amountCents / 100)) stretchTotal = StretchCheckTotal.get() StretchCheckTotal.update(stretchTotal - amountCents) # Weird code structure below left intact in case we want to go back and # start counting amountRecurring = amountCents if data['recurring'] == True: if data['upsell'] == True: amountRecurring = 0 else: amountRecurring = amountCents model.ShardedCounter.increment('TOTAL-5', amountRecurring) if data['team']: cache.IncrementTeamPledgeCount(data['team'], 1) cache.IncrementTeamTotal(data['team'], amountRecurring) totalStr = '$%d' % int(amountCents / 100) format_kwargs = { 'name': data['name'].encode('utf-8'), 'url_nonce': pledge.url_nonce, 'total': totalStr, 'user_url_nonce': user.url_nonce } if data['recurring'] == True: text_body = open('email/thank-you-recurring.txt').read().format( **format_kwargs) html_body = open('email/thank-you-recurring.html').read().format( **format_kwargs) else: text_body = open('email/thank-you.txt').read().format(**format_kwargs) html_body = open('email/thank-you.html').read().format(**format_kwargs) env.mail_sender.Send(to=data['email'].encode('utf-8'), subject='Thank you for your pledge', text_body=text_body, html_body=html_body) if amountCents >= 100000: format_kwargs = { 'name': data['name'].encode('utf-8'), 'total': totalStr, 'phone': data['phone'], 'email': data['email'], } lessig_body = open('email/lessig-notify.txt').read().format( **format_kwargs) logging.info('Sending ' + lessig_body) env.mail_sender.Send( to='*****@*****.**', subject='A donation for %s has come in from %s %s' % (totalStr, first_name, last_name), text_body=lessig_body, html_body='<html><body>' + lessig_body + '</html></body>') id = str(pledge.key()) receipt_url = '?receipt=%s&auth_token=%s&uut=%s' % ( id, str(pledge.url_nonce), str(user.url_nonce)) return id, pledge.url_nonce, user.url_nonce, receipt_url
def pledge_helper(handler, data, stripe_customer_id, stripe_charge_id, paypal_payer_id, paypal_txn_id): env = handler.app.config['env'] if 'last_name' in data: last_name = data['last_name'] if 'first_name' in data: first_name = data['first_name'] else: first_name = '' else: # Split apart the name into first and last. Yes, this sucks, but adding the # name fields makes the form look way more daunting. We may reconsider this. name_parts = data['name'].split(None, 1) first_name = name_parts[0] if len(name_parts) == 1: last_name = '' logging.warning('Could not determine last name: %s', data['name']) else: last_name = name_parts[1] if not 'surveyResult' in data: data['surveyResult'] = '' if not 'city' in data: data['city'] = None if not 'address' in data: data['address'] = None else: logging.info('Address was: ' + str(data['address'])) if not 'state' in data: data['state'] = None if not 'zipCode' in data: data['zipCode'] = None if not 'bitpay_invoice_id' in data: data['bitpay_invoice_id'] = None print data if not 'recurring' in data: data['recurring'] = False if not 'enddate' in data: data['enddate'] = '' if not 'recurrence_period' in data: data['recurrence_period'] = '' if not 'nationBuilderVars' in data: data['nationBuilderVars'] = None if not 'keep_donation' in data: data['keep_donation'] = False amountCents = data['amountCents'] user, pledge = model.addPledge(email=data['email'], stripe_customer_id=stripe_customer_id, stripe_charge_id=stripe_charge_id, paypal_payer_id=paypal_payer_id, paypal_txn_id=paypal_txn_id, amount_cents=amountCents, first_name=first_name, last_name=last_name, occupation=data['occupation'], employer=data['employer'], phone=data['phone'], target=data['target'], surveyResult=data['surveyResult'], pledge_type=data.get( 'pledgeType', model.Pledge.TYPE_CONDITIONAL), team=data['team'], mail_list_optin=data['subscribe'], anonymous=data.get('anonymous', False), address=str(data['address']), city=data['city'], state=data['state'], zipCode=data['zipCode'], bitpay_invoice_id=data['bitpay_invoice_id'], recurring=data['recurring'], recurrence_period=data['recurrence_period'], enddate=data['enddate'], keep_donation=data['keep_donation']) logging.info('Added pledge to database') if data['subscribe']: env.mailing_list_subscriber.Subscribe( email=data['email'], first_name=first_name, last_name=last_name, amount_cents=amountCents, ip_addr=handler.request.remote_addr, time=datetime.datetime.now(), source='pledge', phone=data['phone'], nonce=user.url_nonce, recurring=data['recurring']) if False: model.addNationBuilderDonation( email=data['email'], stripe_customer_id=stripe_customer_id, stripe_charge_id=stripe_charge_id, paypal_payer_id=paypal_payer_id, paypal_txn_id=paypal_txn_id, amount_cents=amountCents, first_name=first_name, last_name=last_name, occupation=data['occupation'], employer=data['employer'], phone=data['phone'], target=data['target'], surveyResult=data['surveyResult'], pledge_type=data.get('pledgeType', model.Pledge.TYPE_CONDITIONAL), team=data['team'], mail_list_optin=data['subscribe'], anonymous=data.get('anonymous', False), address=str(data['address']), city=data['city'], state=data['state'], zipCode=data['zipCode'], bitpay_invoice_id=data['bitpay_invoice_id'], recurring=data['recurring'], enddate=data['enddate'], recurrence_period=data['recurrence_period'], nationBuilderVars=data['nationBuilderVars']) # Add to the total. model.ShardedCounter.increment('TOTAL-5', amountCents) if data['team']: cache.IncrementTeamPledgeCount(data['team'], 1) cache.IncrementTeamTotal(data['team'], amountCents) totalStr = '$%d' % int(amountCents / 100) format_kwargs = { 'name': data['name'].encode('utf-8'), 'url_nonce': pledge.url_nonce, 'total': totalStr, 'user_url_nonce': user.url_nonce } if data['recurring'] == True: text_body = open('email/thank-you-recurring.txt').read().format( **format_kwargs) html_body = open('email/thank-you-recurring.html').read().format( **format_kwargs) else: text_body = open('email/thank-you.txt').read().format(**format_kwargs) html_body = open('email/thank-you.html').read().format(**format_kwargs) env.mail_sender.Send(to=data['email'].encode('utf-8'), subject='Thank you for your pledge', text_body=text_body, html_body=html_body) id = str(pledge.key()) receipt_url = '?receipt=%s&auth_token=%s' % (id, pledge.url_nonce) return id, pledge.url_nonce, receipt_url