       else if vmInfo.type is 'expensed'          then 'expensed'
       else 'group'
 
-    @fetchSubscription getGroup(), type, vmInfo.planCode,\
-      @createDeleteConfirmationModal.bind this, type, callback
+    @fetchSubscription getGroup(), type, vmInfo.planCode, (err, subscription) =>
+      console.error err  if err
+      @createDeleteConfirmationModal type, callback, subscription
 
   # views
+
+  fetchPlanByCode: (planCode, callback) ->
+
+    { JPaymentPlan } = KD.remote.api
+
+    JPaymentPlan.fetchPlanByCode planCode, callback
 
   fetchPaymentInfo: (type, callback) ->
 
     { JPaymentPlan } = KD.remote.api
+
+    debugger
 
     switch type
       when 'group', 'expensed'

        getGroup().checkPayment (err, subs) =>
          findActiveSubscription subs, planCode, callback
      else
        JPaymentSubscription.getUserSubscriptions (err, subs) ->
          findActiveSubscription subs, planCode, callback

  confirmPayment: ({ type, planCode, paymentMethodId }, callback = (->)) ->
    getGroup().canCreateVM { type, planCode, paymentMethodId }, (err, status) =>
      @fetchSubscription type, planCode, (subscription) =>
        cb = (needBilling, balance, amount) =>
          debugger
          # @createPaymentConfirmationModal {
          #   needBilling, balance, amount, type, group, plan, subscription
          # }, callback

        if status
          cb no, 0, 0
        else
          @fetchPaymentInfo type, group, (err, billing) =>
            needBilling = err or not billing?.cardNumber?

            @getBalance type, group, (err, balance) =>
              balance = 0  if err
              cb needBilling, balance, plan.feeMonthly

  makePayment: (type, plan, amount) ->
    vmController = KD.getSingleton('vmController')

    if amount is 0
      vmController.createGroupVM type, plan.code
    else if type in ['group', 'expensed']
      paymentMethod = { plan: plan.code, multiple: yes }
      getGroup().makePayment paymentMethod, (err, result)->
        return KD.showError err  if err
        vmController.createGroupVM type, plan.code
    else
      plan.subscribe multiple: yes, (err, result)->
        return KD.showError err  if err
        vmController.createGroupVM type, plan.code


      @emit 'PaymentDataChanged'

  fetchSubscription: do ->
    findActiveSubscription = (subscriptions, planCode, callback) ->
      for own paymentMethodId, subs of subscriptions
        for sub in subscriptions
          if sub.planCode is planCode and sub.status in ['canceled', 'active']
            return callback null, sub

      callback null

    fetchSubscription = (type, planCode, callback) ->
      { JPaymentSubscription } = KD.remote.api
