<commit_before>{Base}  = require 'bongo'
recurly = require 'koding-payment'

module.exports = class JRecurly extends Base

  {secure, dash} = require 'bongo'
  {difference, extend} = require 'underscore'

  JUser = require '../user'

  prefixedId = (prefix) -> (ob) ->
    toString  : -> "#{prefix}#{ob.getId()}"
    prefix    : prefix
    target    : ob

  @userCodeOf  = prefixedId 'user_'
  @groupCodeOf = prefixedId 'group_'

  { userCodeOf } = this

  @share()

  @set
    sharedMethods  :
      static       : [
        'getBalance', 'setBillingInfo', 'getAccount', 'getTransactions', 'fetchCountryDataByIp'
      ]

  @setBillingInfo = secure (client, data, callback) ->

    {delegate} = client.connection
    JSession   = require '../session'

    JSession.one {clientId: client.sessionToken}, (err, session) =>
      {username, firstName, lastName} = delegate.profile
      extend data, {username, firstName, lastName}
      data.ipAddress = session?.clientIPAddress or '0.0.0.0'

      JUser.fetchUser client, (err, user) ->
        userId = userCodeOf delegate
        data.email = user.email
        recurly.setAccount userId, data, (err, res) ->
          return callback err  if err?

          recurly.setBilling userId, data, (err, res) ->
            console.log { err, res, callback }

  @getAccount = secure ({connection:{delegate}}, callback)->
    recurly.getAccount (userCodeOf delegate), callback
<commit_msg>recurly: pass callback through<commit_after>{Base}  = require 'bongo'
recurly = require 'koding-payment'

module.exports = class JRecurly extends Base

  {secure, dash} = require 'bongo'
  {difference, extend} = require 'underscore'

  JUser = require '../user'

  prefixedId = (prefix) -> (ob) ->
    toString  : -> "#{prefix}#{ob.getId()}"
    prefix    : prefix
    target    : ob

  @userCodeOf  = prefixedId 'user_'
  @groupCodeOf = prefixedId 'group_'

  { userCodeOf } = this

  @share()

  @set
    sharedMethods  :
      static       : [
        'getBalance', 'setBillingInfo', 'getAccount', 'getTransactions', 'fetchCountryDataByIp'
      ]

  @setBillingInfo = secure (client, data, callback) ->

    {delegate} = client.connection
    JSession   = require '../session'

    JSession.one {clientId: client.sessionToken}, (err, session) =>
      {username, firstName, lastName} = delegate.profile
      extend data, {username, firstName, lastName}
      data.ipAddress = session?.clientIPAddress or '0.0.0.0'

      JUser.fetchUser client, (err, user) ->
        userId = userCodeOf delegate
        data.email = user.email
        recurly.setAccount userId, data, (err, res) ->
          return callback err  if err?

          recurly.setBilling userId, data, callback

  @getAccount = secure ({connection:{delegate}}, callback)->
    recurly.getAccount (userCodeOf delegate), callback

{'fraction_non_alphanumeric': 0.12963617096432356, 'fraction_numerical': 0.00282585658777817, 'mean_word_length': 2.933333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1366887', 'n_tokens_mistral': 888, 'n_tokens_neox': 875, 'n_words': 222}