Sha256: 8d85af9f8261f0c9eb8dbfec61becbfc5eb8a4a96f70a9ff1a9c8fe3ac273435

Contents?: true

Size: 1000 Bytes

Versions: 1

Compression:

Stored size: 1000 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

1 entries across 1 versions & 1 rubygems

Version Path
shoppe-stripe-1.3.0 vendor/assets/javascripts/shoppe/stripe/form_handler.coffee