   global._payment or= {}
   _payment.token = token
 
-saveCardInfo = ({ number, exp_month, exp_year }) ->
+saveCardElement = (cardElement) ->
   global._payment or= {}
-
-  _payment.card =
-    exp_month: exp_month
-    exp_year: exp_year
-    last4: do ->
-      parts = number.split(' ').filter(Boolean)
-      lastPart = parts[parts.length - 1]
-      return lastPart.substring lastPart.length - 4
-
+  global._payment.card = cardElement
 
 getCardInfo = -> global._payment?.card
 

    ).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 {


module.exports = utils = {

  savePaymentToken, saveCardElement, getPayment, cleanPayment

  clearKiteCaches: ->

