           active       : yes
         }
         pay.save (err)->
-          if err then return callback new KodingError 'Unable to save transaction to database.'
+          if err then return callback { message: 'Unable to save transaction to database.' }
           callback null, pay
 
       if data.chargeTo is 'group'

  @chargeGroup = (group, p, data, callback)->
    {multiple, plan, quantity} = data
    p.subscribeGroup group, {multiple, plan, quantity}, (err, subscription)->
      if err then return callback new KodingError "Unable to buy item: #{err}"
      callback null, subscription

  # Charge user account
  @chargeUser = (account, plan, data, callback)->
    return callback new KodingError 'Unable charge, insufficient funds.'
    # TBI

  # List group's payments

  # TODO: Make sure this calculation is enough.
  #       Not tested for expired/canceled subscriptions.
  @getExpenses = (pattern, callback) ->
    error = (err)-> { message: "Unable to query user balance: #{err}" }

    JPaymentPayment.some pattern, {subscription: 1}, (err, items) ->
      return callback error err  if err
