在创建动作条件控制器中传递自定义参数

时间:2017-08-04 08:52:28

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

在Stripe的充电控制器的创建动作中,我想获得刚刚支付的命令。但我不知道如何在条形支付表格中传递参数。

这是我的实际代码:

charges_controller

class ChargesController < ApplicationController

  def new
    @command = Command.find(params[:command_id])
    @item = @command.commandable
  end

  def create
    @command = # I would like to have the current command...
    @item = @command.commandable
    # Amount in cents
    amount_in_cents = (@command.total_price * 100).to_i
    customer = StripeTool.create_customer(params[:stripeEmail],
                                          params[:stripeToken])

    charge = StripeTool.create_charge(customer.id,
                                      amount_in_cents,
                                      'Commande Edicouv')

    redirect_to root_path
 end

我在创建动作中的参数:

Processing by ChargesController#create as HTML
Parameters: {"utf8"=>"✓", 
             "authenticity_token"=>"...", 
             "stripeToken"=>"...", 
             "stripeTokenType"=>"card", 
             "stripeEmail"=>"orsay@live.fr"}

视图/充电/新

script.stripe-button[src="https://checkout.stripe.com/checkout.js" 
data-key="#{Rails.configuration.stripe[:publishable_key]}" 
data-description="Règlement de votre achat" 
data-locale="auto" 
data-currency="eur" 
data-panel-label="Payer #{@command.total_price} €" 
data-label="Payer"
data-image="/assets/logo.png" 
data-email="#{current_user.email}" 
data-allow-remember-me="false"]

0 个答案:

没有答案