       @emit 'PaymentDataChanged'
 
   fetchSubscription: do ->
-    findActiveSubscription = (subs, planCode, callback) ->
-      subs.reverse().forEach (sub) ->
-        if sub.planCode is planCode and sub.status in ['canceled', 'active']
-          return callback sub
+    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 'none'
+      callback null
 
     fetchSubscription = (type, planCode, callback) ->
       { JPaymentSubscription } = KD.remote.api

      else if vmInfo.type is 'expensed'          then 'expensed'
      else 'group'

    @fetchSubscription getGroup(), type, vmInfo.planCode,\
      @createDeleteConfirmationModal.bind this, type, callback

  # views

  fetchPaymentInfo: (type, callback) ->

    { JPaymentPlan } = KD.remote.api

    switch type
      when 'group', 'expensed'

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

  confirmPayment: ->
    console.error 'confirm payment is removed'

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

    if 'string' is typeof plan
      @fetchPlanByCode plan, (err, planObj) =>
        return console.error err  if err
        @makePayment paymentMethodId, planObj, amount

    else 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 paymentMethodId, multiple: yes, (err, result)->
        return KD.showError err  if err
        vmController.createGroupVM type, plan.code

