   else
     Spree.stripePaymentMethod.find('#card_number, #card_expiry, #card_code').prop("disabled" , true)
     Spree.stripePaymentMethod.find(".ccType").prop("disabled", false)
+    Spree.stripePaymentMethod.find(".ccType").val(mapCC(response.card.type))
+
     # token contains id, last4, and card type
     token = response['id'];
     # insert the token into the form so it gets submitted to the server

    Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId  + "][last_digits]' value='" + response.card.last4 + "'/>");
    Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId  + "][month]' value='" + response.card.exp_month + "'/>");
    Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId  + "][year]' value='" + response.card.exp_year + "'/>");
    Spree.stripePaymentMethod.parents("form").get(0).submit();

# Inspired by https://stripe.com/docs/stripe.js

# Map cc types from stripe to spree
mapCC = (ccType) ->
  if (ccType == 'MasterCard') 
    'mastercard'
  else if (ccType == 'Visa') 
    'visa'
  else if (ccType == 'American Express')
    'amex'
  else if (ccType == 'Discover')
    'discover'
  else if (ccType == 'Diners Club')
    'dinnersclub'
  else if (ccType == 'JCB')
    'jcb'


$(document).ready ->
  # For errors that happen later.
