 
 module.exports = utils = {
 
-  savePaymentToken, saveCardInfo, getPayment, cleanPayment
+  savePaymentToken, saveCardElement, getPayment, cleanPayment
 
   clearKiteCaches: ->
 

    ).getElement()


  createStripeToken: (Stripe, cardInfo) -> new Promise (resolve, reject) ->
    Stripe.createToken cardInfo, (status, response) ->
      if response.error
      then reject response.error
      else resolve response.id

  authorizeCreditCard: (formData) ->

    { number, cvc, exp_month, exp_year } = formData
    { email } = utils.getTeamData().signup

    cardInfo =
      number    : number
      cvc       : cvc
      exp_month : exp_month
      exp_year  : exp_year

    utils.loadStripe()
      # first create a token for a authorization charge (50cent)
      .then -> utils.createStripeToken global.Stripe, cardInfo
      .then (token) -> utils.makeChargeRequest token, email
      # then create another token for subscription
      .then -> utils.createStripeToken global.Stripe, cardInfo
      .then (token) ->
        utils.savePaymentToken token
        utils.saveCardInfo cardInfo
      .catch (err) ->
        utils.cleanPayment()
        Promise.reject err

  getDummyCard: ->
    return {

  global._payment or= {}
  _payment.token = token

saveCardElement = (cardElement) ->
  global._payment or= {}
  global._payment.card = cardElement

getCardInfo = -> global._payment?.card

