<commit_before>const AssignMail = require('../mail/assign')
const PaymentMail = require('../mail/payment')
const Promise = require('bluebird')
const models = require('../../models')
const Stripe = require('stripe')
const stripe = new Stripe(process.env.STRIPE_KEY)
const TransferMail = require('../mail/transfer')
const DeadlineMail = require('../mail/deadline')
const assignExist = require('../assigns').assignExists
const offerExists = require('../offers').offerExists
const memberExists = require('../members').memberExists
const i18n = require('i18n')
const constants = require('../mail/constants')
const TaskMail = require('../mail/task')

const createSourceAndCharge = Promise.method((customer, orderParameters, order, task, user) => {
  return stripe.customers.createSource(customer.id, { source: orderParameters.source_id }).then(card => {
    const centavosAmount = orderParameters.amount * 100
    return stripe.charges.create({
      amount: centavosAmount * 0.92, // 8% base fee
      currency: orderParameters.currency,
      customer: customer.id,
      source: card.id,
      transfer_group: `task_${task.dataValues.id}`,
      metadata: { order_id: order.dataValues.id }
    }).then(charge => {
      if (charge) {
        return order.updateAttributes({
          source: charge.id,
          source_id: card.id,
          paid: charge.paid,
          status: charge.status
        }).then(updatedUser => {
          PaymentMail.success(user, task, order.amount)
          TaskMail.notifyPayment(task.dataValues.User, {
            task: {
              title: task.dataValues.title,
              value: order.dataValues.amount,
              issue_url: task.dataValues.url,
              url: constants.taskUrl(task.dataValues.id)
            }
          })
          if (task.dataValues.assigned) {
            const assignedId = task.dataValues.assigned
            return models.Assign.findById(assignedId, {
              include: [models.User]
            }).then(assign => {
              PaymentMail.assigned(assign.dataValues.User.dataValues.email, task, order.amount)
              return task
            })
          }
          return task
        })
      }
      throw new Error('no charge')
    }).catch(e => {
      // eslint-disable-next-line no-console
      console.log('could not create charge', e)
      throw new Error(e)
    })<commit_msg>commenting the new bounty added notification for now (#393)<commit_after>const AssignMail = require('../mail/assign')
const PaymentMail = require('../mail/payment')
const Promise = require('bluebird')
const models = require('../../models')
const Stripe = require('stripe')
const stripe = new Stripe(process.env.STRIPE_KEY)
const TransferMail = require('../mail/transfer')
const DeadlineMail = require('../mail/deadline')
const assignExist = require('../assigns').assignExists
const offerExists = require('../offers').offerExists
const memberExists = require('../members').memberExists
const i18n = require('i18n')
// const constants = require('../mail/constants')
// const TaskMail = require('../mail/task')

const createSourceAndCharge = Promise.method((customer, orderParameters, order, task, user) => {
  return stripe.customers.createSource(customer.id, { source: orderParameters.source_id }).then(card => {
    const centavosAmount = orderParameters.amount * 100
    return stripe.charges.create({
      amount: centavosAmount * 0.92, // 8% base fee
      currency: orderParameters.currency,
      customer: customer.id,
      source: card.id,
      transfer_group: `task_${task.dataValues.id}`,
      metadata: { order_id: order.dataValues.id }
    }).then(charge => {
      if (charge) {
        return order.updateAttributes({
          source: charge.id,
          source_id: card.id,
          paid: charge.paid,
          status: charge.status
        }).then(updatedUser => {
          PaymentMail.success(user, task, order.amount)
          /*
          TaskMail.notifyPayment(task.dataValues.User, {
            task: {
              title: task.dataValues.title,
              value: order.dataValues.amount,
              issue_url: task.dataValues.url,
              url: constants.taskUrl(task.dataValues.id)
            }
          })
          */
          if (task.dataValues.assigned) {
            const assignedId = task.dataValues.assigned
            return models.Assign.findById(assignedId, {
              include: [models.User]
            }).then(assign => {
              PaymentMail.assigned(assign.dataValues.User.dataValues.email, task, order.amount)
              return task
            })
          }
          return task
        })
      }
      throw new Error('no charge')
    }).catch(e => {
      // eslint-disable-next-line no-console
      console.log('could not create charge', e)
      throw new Error(e)
    })
{'fraction_non_alphanumeric': 0.13161157024793388, 'fraction_numerical': 0.005165289256198347, 'mean_word_length': 2.4652827487473155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5973170', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1322, 'n_words': 282}