Rails 4应用程序无法连接到Stripe

时间:2014-05-26 19:23:48

标签: javascript ruby-on-rails ruby stripe-payments

尝试向我的应用添加条带付款,但它没有连接。 安装了条纹宝石,重新启动了服务器&添加了我的条带API密钥(测试) 添加了javascript信息,以便连接我的条带帐户

所以当我买东西时输入CC细节它应该连接到条纹。

也关闭了turbolinks但仍然做同样的事情。我需要的是从条纹弹出,我知道它的工作。

orders.js.coffee

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

payment =
  setupForm: ->
    $('#new_order').submit ->
        $('input[type=submit]').attr('disabled', true)
        Stripe.card.createToken($('#new_order'), payment.handleStripeResponse)
        false
  handleStripeResponse: (status, response) ->
    if status == 200
      alert(response.id)
    else
      alert(response.error.message)

show.html.erb

<div class="row">
  <div class="col-md-6">
    <div class="thumbnail">
      <%= image_tag @listing.image.url %>
    </div>
  </div>
  <div class="col-md-6">
    <h3><%= @listing.name %></h3>
    <p><%= number_to_currency(@listing.price) %></p>
    <p><%= @listing.description %></p>
    <br>
    <div class="center">
      <%= link_to "Buy it Now", new_listing_order_path(@listing), class: "btn btn-primary", data: { no_turbolink: true } %>
  </div>
</div>

<% if current_user == @listing.user %>
  <%= link_to 'Edit', edit_listing_path(@listing), class: "btn btn-link" %> |
<% end %>
<%= link_to 'Back', listings_path, class: "btn btn-link" %>

orders._form.html

<div class="row">
    <div class="col-md-4">
      <div class="thumbnail">
        <%= image_tag @listing.image.url %>
      </div>
      <h3><%= @listing.name %></h3>
      <h4><%= number_to_currency(@listing.price) %></h4>
    </div>

      <div class="col-md-8">

        <%= form_for([@listing, @order]) do |f| %>
          <% if @order.errors.any? %>
            <div id="error_explanation" class="alert alert-danger alert-dismissable">
              <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
              <h4><%= pluralize(@order.errors.count, "error") %> prohibited this order from being saved:</h4>

              <ul>
              <% @order.errors.full_messages.each do |msg| %>
                <li><%= msg %></li>
              <% end %>
              </ul>
            </div>
          <% end %>

          <div class="form-group">
            <%= f.label :address %>
            <%= f.text_field :address, class: "form-control" %>
          </div>
          <div class="form-group">
            <%= f.label :city %>
            <%= f.text_field :city, class: "form-control" %>
          </div>
          <div class="form-group">
            <%= f.label :state %>
            <%= f.text_field :state, class: "form-control" %>
          </div>



          <div class="form-group">
            <div class="row">
              <div class="col-md-8">
                <%= label_tag :card_number, "Credit Card Number" %>
                <%= text_field_tag :card_number, nil, { :name => nil, :'data-stripe' => "number", class: "form-control" } %>
              </div>
              <div class="col-md-4">
                <%= label_tag :card_code, "CVC" %>
                <%= text_field_tag :card_code, nil, { :name => nil, :'data-stripe' => "cvc", class: "form-control" } %>
              </div>
            </div>
          </div>

  <div class="form-group">
    <%= label_tag nil, "Expiration Date" %>
      <div class="row">
       <div class="col-md-3">
        <%= select_month nil, { use_two_digit_numbers: true }, { :name => nil, :'data-stripe' => "exp-month", class: "form-control" } %>
      </div>
      <div class="col-md-3">
        <%= select_year nil, { start_year: Date.today.year, end_year: Date.today.year+10 }, { :name => nil, :'data-stripe' => "exp-year", class: "form-control" } %>
      </div>
    </div>
  </div>

       <div class="form-group">
        <%= f.submit "Complete Order", class: "btn btn-success" %>
      </div>
    <% end %>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

看起来您正试图从不存在的表单触发Stripe函数。您有几个引用:

$('#new_order')

看起来您的表单ID实际上是新的列表顺序:

$('#new_listing_order')

但请检查生成的HTML或inspect元素,以确定。