我正在尝试按照Stripe / Rails教程让客户选择他们想要支付的费用:https://stripe.com/docs/recipes/variable-amount-checkout .

当我尝试这样做时,我不断收到错误说:

You have passed a blank string for 'source'. You should remove the 'source' parameter from your request or supply a non-blank value.

Stripe::Charge.create(
    :amount => @amount,
    :currency => 'usd',
    :source => params[:stripeToken],

我相信这是因为没有设置params [:stripeToken] . 关于如何解决这个问题的任何建议?

目前的new.html.erb

<script src="https://checkout.stripe.com/checkout.js"></script>

    <script>
    var handler = StripeCheckout.configure({
      key: '<%= Rails.configuration.stripe[:publishable_key] %>',
      locale: 'auto',
      name: 'Sand Castles United',
      description: 'One-time donation',
      token: function(token) {
        $('input#stripeToken').val(token.id);
        $('form').submit();
      }
    });

    $('#donateButton').on('click', function(e) {
      e.preventDefault();

      $('#error_explanation').html('');

      var amount = $('input#amount').val();
      amount = amount.replace(/\$/g, '').replace(/\,/g, '')

      amount = parseFloat(amount);

      if (isNaN(amount)) {
        $('#error_explanation').html('<p>Please enter a valid amount in USD ($).</p>');
      }
      else if (amount < 5.00) {
        $('#error_explanation').html('<p>Donation amount must be at least $5.</p>');
      }
      else {
        amount = amount * 100; // Needs to be an integer!
        handler.open({
          amount: Math.round(amount)
        })
      }
    });

    // Close Checkout on page navigation
    $(window).on('popstate', function() {
      handler.close();
    });

    </script>


    <%= form_tag charges_path do %>
      <div id="error_explanation">
        <% if flash[:error].present? %>
          <p><%= flash[:error] %></p>
        <% end %>
      </div>
      <article>
        <%= label_tag(:amount, 'Donation Amount:') %>
        <%= text_field_tag(:amount) %>
      </article>
      <article>
        <%= hidden_field_tag(:stripeToken) %>
      </article>
      <button id='donateButton'>Donate</button>
    <% end %>