             callback  : =>
               modal.destroy()
               cb()
+          Billing     :
+            title     : "Enter Billing Info"
+            cssClass  : "modal-clean-green"
+            callback  : =>
+              askBillingInfo (success)->
+                if success
+                  modal.buttons.Yes.show()
+                  modal.buttons.Billing.hide()
           Yes         :
             title     : "OK, create the VM"
             cssClass  : "modal-clean-green"
             callback  : =>
               modal.destroy()
-              cb()
-              paymentController.makePaymentModal type, plan, ->
-                console.log "I'm done."
-    
+              paymentController.makePayment type, plan, willCharge, ->
+                cb()
+
+      if needBilling
+        modal.buttons.Billing.show()
+        modal.buttons.Yes.hide()
+      else
+        modal.buttons.Billing.hide()
+
+    getBillingInfo = (cb)->
+      if type is 'group'
+        group.getBillingInfo cb
+      else
+        KD.remote.api.JRecurlyPlan.getUserAccount cb
+
     group.canCreateVM
       type     : type
       planCode : plan.code

              modal.destroy()
              callback?()

  subscribeGroup: (group, type, planCode, callback)->
    paymentController = KD.getSingleton('paymentController')
    vmController      = KD.getSingleton('vmController')

    # Copy account creator's billing information
    KD.remote.api.JRecurlyPlan.getUserAccount (err, data)=>
      warn err
      if err or not data
        data = {}

      # These will go into Recurly module
      delete data.cardNumber
      delete data.cardMonth
      delete data.cardYear
      delete data.cardCV

      @paymentModal = paymentController.createPaymentMethodModal data, (newData, onError, onSuccess)->
        newData.plan = planCode
        newData.type = type
        group.makePayment newData, (err, subscription)->
          if err
            onError err
          else
            vmController.createGroupVM type, planCode
            onSuccess()
            callback()
      @paymentModal.on "KDModalViewDestroyed", -> vmController.emit "PaymentModalDestroyed"

  subscribeUser: (type, planCode, callback)->
    vmController = KD.getSingleton('vmController')

    KD.remote.api.JRecurlyPlan.getPlanWithCode planCode, (err, plan)->
      plan.subscribe {}, (err, subscription)->
        return callback err  if callback and err
        vmController.createGroupVM type, planCode
        callback?()

  confirmPayment: (type, plan, callback=->)->
    paymentController = KD.getSingleton('paymentController')
    group             = KD.getSingleton("groupsController").getCurrentGroup()

      else
        KD.remote.api.JRecurlyPlan.getGroupBalance group, cb

    askBillingInfo = (cb)->
      paymentModal = paymentController.createPaymentMethodModal {}, (newData, onError, onSuccess)->
        if type is 'group'
          group.setBillingInfo newData, (err, result)->
            console.log "Group Billing:", arguments
            if err
              onError err
            else
              onSuccess result
              cb yes
        else
          KD.remote.api.JRecurlyPlan.setUserAccount newData, (err, result)->
            console.log "User Billing:", arguments
            if err
              onError err
            else
              onSuccess result
              cb yes

    buildModal = (content, needBilling, willCharge, cb)->
      modal           = new KDModalView
        title         : "Confirm VM Creation"
        content       : "<div class='modalformline'>#{content}</div>"
