Sha256: 97658f9ef4218f8477ec82506ef1426e18fdb45bdc7d3db259a23244502a5e6b

Contents?: true

Size: 999 Bytes

Versions: 5

Compression:

Stored size: 999 Bytes

Contents

$ -> 
  $('form.stripeForm').on 'submit', ->
    # The form
    form = $(this)
    
    # Build a hash of params which will be sent to Stripe
    stripeCardParams = {}
    $.each ['number', 'exp_month', 'exp_year', 'cvc', 'name', 'address_line1', 'address_line2', 'address_city', 'address_state', 'address_zip', 'address_country'], (i,f)->
      stripeCardParams[f] = $("[data-stripe='#{f}']").val()
    
    # Send the data to Stripe and define a method to be executed when the response
    # comes back from Stripe.
    Stripe.card.createToken stripeCardParams, (status, response)->
      if response.error
        $('p.stripeError', form).remove()
        $("<p class='stripeError'>#{response.error.message}</p>").prependTo(form)
        $('input[type=submit]', form).removeClass('disabled').prop('disabled', false)
      else
        $('[data-stripe=token]').val(response['id'])
        form.get(0).submit()
    
    # Return false to ensure that the form doesn't submit on first click
    false

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
kkt_shoppe-stripe-2.0.0 vendor/assets/javascripts/kkt_shoppe/stripe/form_handler.coffee
shoppe-stripe-1.2.2 vendor/assets/javascripts/shoppe/stripe/form_handler.coffee
shoppe-stripe-1.2.1 vendor/assets/javascripts/shoppe/stripe/form_handler.coffee
shoppe-stripe-1.1.0 vendor/assets/javascripts/shoppe/stripe/form_handler.coffee
shoppe-stripe-1.0.2 vendor/assets/javascripts/shoppe/stripe/form_handler.coffee