创建对象并使用条带进行付款

时间:2016-11-07 15:15:46

标签: ruby-on-rails stripe-payments

所以我试图在jobs_controller中创建一个job对象,并且我设法让checkout stripe gem按照here所述的方式工作。所以我可以在mywebsite / charge / new中付款,所以api密钥是 正确和工作,因为我可以在条带仪表板中看到我的测试付款。

但我现在想要在用户尝试创建作业对象时创建付款,您可以在jobs_controller中的create action中看到。

def create
    puts "HELLLOOOOOOOOOOOOOOOOOOOOOOOOOOO"
    @job = Job.new(job_params)
    @job.highlight = true

    raise "Please, check job errors" unless @job.valid?
    @amount = 200 *100


    customer = Stripe::Customer.create(
        :email => params[:stripeEmail],
        :source  => params[:stripeToken]
    )

    charge = Stripe::Charge.create(
        :customer    => customer.id,
        :amount      => @amount,
        :description => 'Rails Stripe customer',
        :currency    => 'usd'
    )

    @job.save
    redirect_to @job, notice: 'Job was successfully created.'

  rescue Stripe::CardError => e
    logger.debug e.message
    flash[:error] = e.message
    render :new
end

我的_form.html.erb在/ jobs

<form>
  <%= form_for(job) do |f| %>
      <% if job.errors.any? %>
          <div id="error_explanation">
            <h2><%= pluralize(job.errors.count, "error") %> prohibited this job from being saved:</h2>

            <ul>
              <% job.errors.full_messages.each do |message| %>
                  <li><%= message %></li>
              <% end %>
            </ul>
          </div>
      <% end %>

      <div class="form-group">
        <%= f.label :title %><br>
        <%= f.text_field :title, :class => "form-control" %>
      </div>

      <div class="form-group">
        <%= f.label :description %><br>
        <%= f.bootsy_area :description, size: "100x30", :class => "form-control", editor_options: { font_styles: false, image: false, color: false } %>
      </div>

      <div class="form-group">
        <%= f.label :url %><br>
        <%= f.text_field :url, :class => "form-control" %>
      </div>

      <div class="form-group">
        <%= f.label :company %><br>
        <%= f.text_field :company, :class => "form-control" %>
      </div>

      <div class="form-group">
        <label>By posting a job, you agree to our <%= link_to "terms of service policy.", terms_path %></label>
      </div>

      <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
              data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
              data-description="A job posting"
              data-amount="20000"
              data-locale="auto">

      </script>
  <% end %>
</form>

但是当我尝试创建一个工作时,付款不会变成低谷,也没有创建任何对象,我看不出任何错误,我在heroku日志中看不到任何东西,所以我迷路了。我的问题出在哪里?

谢谢。

0 个答案:

没有答案