       subscription.plan = plansByCode[subscription.planCode]
     
     { plans, subscriptions }
-

class PaymentController extends KDController

  getGroup = ->
    KD.getSingleton('groupsController').getCurrentGroup()

  getBalance: (type, callback)->

    { JPaymentPlan } = KD.remote.api

    if type is 'user'
      JPaymentPlan.getUserBalance callback
    else
      JPaymentPlan.getGroupBalance callback

  fetchPaymentMethods: (callback) ->

    { dash } = Bongo

    methods       = null
    preferredPaymentMethod = null
    appStorage    = new AppStorage 'Account', '1.0'
    queue = [

      -> appStorage.fetchStorage (err) ->


    return form

  debitSubscription: ->
    subscription.debit pack, (err, nonce) =>
      return  if KD.showError err

      @emit 'SubscriptionDebited', subscription

      callback null, nonce

  fetchSubscriptionsWithPlans: (tags, callback) ->
    [callback, tags] = [tags, callback]  unless callback

    KD.whoami().fetchPlansAndSubscriptions tags, (err, plansAndSubs) =>
      return callback err  if err
      
      { subscriptions } = @groupPlansBySubscription plansAndSubs

      callback null, subscriptions

  groupPlansBySubscription: (plansAndSubscriptions = {}) ->
    
    { plans, subscriptions } = plansAndSubscriptions
