Ejemplo n.º 1
0
  def post(self):
    try:
      data = json.loads(self.request.body)
    except:
      logging.Warning("Bad JSON request")
      self.error(400)
      self.response.write('Invalid request')
      return

    # ugh, consider using validictory?
    if ('email' not in data or
        'token' not in data or
        'amount' not in data or
        'userinfo' not in data or
        'occupation' not in data['userinfo'] or
        'employer' not in data['userinfo'] or
        'phone' not in data['userinfo'] or
        'target' not in data['userinfo']):
      self.error(400)
      self.response.write('Invalid request')
      return
    email = data['email']
    token = data['token']
    amount = data['amount']
    name = data.get('name', '')

    occupation = data['userinfo']['occupation']
    employer = data['userinfo']['employer']
    phone = data['userinfo']['phone']
    target = data['userinfo']['target']

    try:
      amount = int(amount)
    except ValueError:
      self.error(400)
      self.response.write('Invalid request')
      return

    if not (email and token and amount and occupation and employer and target):
      self.error(400)
      self.response.write('Invalid request: missing field')
      return

    if not mail.is_email_valid(email):
      self.error(400)
      self.response.write('Invalid request: Bad email address')
      return

    customer = stripe.Customer.create(card=token, email=email)

    pledge = model.addPledge(
            email=email, stripe_customer_id=customer.id, amount_cents=amount,
            occupation=occupation, employer=employer, phone=phone,
            target=target, note=self.request.get("note"))

    # Add thank you email to a task queue
    deferred.defer(send_thank_you, name or email, email,
                   pledge.url_nonce, amount, _queue="mail")

    self.response.write('Ok.')
Ejemplo n.º 2
0
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/donor-notify.txt').read().format(**format_kwargs)
    logging.info('Sending ' + lessig_body)
    env.mail_sender.Send(to=donation_notify_email,
                         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
Ejemplo n.º 3
0
    # 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]

    pledge = model.addPledge(email=data['email'],
                             stripe_customer_id=stripe_customer_id,
                             amount_cents=data['amountCents'],
                             first_name=first_name,
                             last_name=last_name,
                             occupation=data['occupation'],
                             employer=data['employer'],
                             phone=data['phone'],
                             target=data['target'],
                             pledge_type=data.get(
                               'pledgeType', model.Pledge.TYPE_CONDITIONAL),
                             team=data['team'],
                             mail_list_optin=data['subscribe'])

    if data['subscribe']:
      env.mailing_list_subscriber.Subscribe(
        email=data['email'],
        first_name=first_name, last_name=last_name,
        amount_cents=data['amountCents'],
        ip_addr=self.request.remote_addr,
        time=datetime.datetime.now(),
        source='pledge')
Ejemplo n.º 4
0
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

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

    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']
                             )
    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)
    # 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
    }

    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' % (id, pledge.url_nonce)

    return id, pledge.url_nonce, receipt_url
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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