What is wrong with my coffeescript in Stripe?

I am working on integrating Stripe into my web application and it does not seem to work. To help me, I used Ryan Bates Rails Cast to integrate Stripe. Whenever I try to run a payment form, I get the error message "There was a problem with my credit card." I think the problem is in my coffeescript file, but maybe I'm wrong. I included a token user token as part of my user model instead of putting it in my own subscription model. Here is the coffeescript code I have:

jQuery ->
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
  subscription.setupForm()

user =
  setupForm: ->
    $('#new_user').submit ->
      $('input[type=submit]').attr('disabled', true)
      if $('#card_number').length
        user.processCard()
        false
      else
        true

  processCard: ->
    card =
      number: $('#card_number').val()
      cvc: $('#card_code').val()
      expMonth: $('#card_month').val()
      expYear: $('#card_year').val()
    Stripe.createToken(card, user.handleStripeResponse)

  handleStripeResponse: (status, response) ->
    if status == 500
      $('#user_stripe_card_token').val(response.id)
      $('#new_user')[0].submit()
    else
      $('#stripe_error').text(response.error.message)
      $('input[type=submit]').attr('disabled', false)

I'm starting to do programming, so any help you can give me will be great.

Here is the error I get in my terminal when trying to register:

: { "utf8" = > "✓", "authenticity_token" = > "Xas + iA + a3op7jUi57qTr7XWQSClPscA7fR19rkclkEE =", "user" = > { "stripe_card_token" = > "," name "= > " Jack "," email "= > " email@example.com "," phone_number "= > " 203-xxx-xxxx "," password "= > " [FILTERED] "," password_confirmation "= > " [FILTERED] "}," commit "= > " "}

(0.2ms) SELECT 1 "" WHERE LOWER ( "users". "email" ) = LOWER ('jjets718@yahoo.com ') LIMIT 1 : :

:

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
    <div class="span6 offset3">
        <%= form_for(@user) do |f| %>
            <%= render 'shared/error_messages' %>

            <%= f.hidden_field :stripe_card_token %>

            <%= f.label :name %>
            <%= f.text_field :name %>

            <%= f.label :email %>
            <%= f.text_field :email %>

            <%= f.label :phone_number, "Your cell phone number" %>
            <%= f.text_field :phone_number %>

            <%= f.label :password %>
            <%= f.password_field :password %>

            <%= f.label :password_confirmation, "Password confirmation" %>
            <%= f.password_field :password_confirmation %>

            <%= label_tag :card_number, "Credit Card Number" %>
            <%= text_field_tag :card_number, nil, name: nil %>

            <%= label_tag :card_code, "Security Code on Card (CVV)" %>
            <%= text_field_tag :card_code, nil, name: nil %>

            <%= label_tag :card_month, "Card Expiration" %>
            <%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"}%>
        <%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>

    <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
    <% end %>
</div>
</div>

<div id="stripe_error">
  <noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>

- create:

  def create
    @user = User.new(params[:user])
    if @user.save_with_payment
     sign_in @user
      flash[:success] = "Welcome to the Sample App!"
     redirect_to edit_user_path(current_user)
     UserMailer.welcome_email(@user).deliver
    else
      render 'new'
    end
  end

:

class AddStripeToUsers < ActiveRecord::Migration
  def change
    add_column :users, :stripe_customer_token, :string
  end
end

save_with_payment :

 def save_with_payment
     if valid?
       customer = Stripe::Customer.create(description: email, plan: 1, card: stripe_card_token)
       self.stripe_customer_token = customer.id
       save!
     end

   rescue Stripe::InvalidRequestError => e
     logger.error "Stripe error while creating customer: #{e.message}"
     errors.add :base, "There was a problem with your credit card."
     false
   end
+5
2

2 , :

  • 200, 500
  • coffeescript application.js
    • . // =
0

, :

handleStripeResponse: (status, response) ->
  if status == 500
    $('#user_stripe_card_token').val(response.id)

if status == 500 if status == 200 $('#user_stripe_card_token').val(response.id) $('#new_user_stripe_card_token').val(response.id). .

0

All Articles