Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 仅在选择特定选项时使用条纹充电_Ruby On Rails_Ruby_Stripe Payments - Fatal编程技术网

Ruby on rails 仅在选择特定选项时使用条纹充电

Ruby on rails 仅在选择特定选项时使用条纹充电,ruby-on-rails,ruby,stripe-payments,Ruby On Rails,Ruby,Stripe Payments,我有一个带有当前枚举的计划模型: enum delivery_option: { drop_off: 'drop_off', pick_up: 'pick_up' } 以下是计划控制器创建操作:(两个选项收费25美元) 当用户创建日程安排时,他可以选择上下车 我只需要向用户收取25美元的提货选项费用。我该怎么做呢?结果比我想象的要简单:) 若你们想向客户收取特定选项的费用,那个么你们可以设置如下条件 创建一个方法 def create @schedu

我有一个带有当前枚举的
计划
模型:

    enum delivery_option: {
      drop_off: 'drop_off',
      pick_up: 'pick_up'
    }
以下是
计划
控制器
创建
操作:(两个选项收费25美元)

当用户创建日程安排时,他可以选择上下车


我只需要向用户收取25美元的
提货
选项费用。我该怎么做呢?

结果比我想象的要简单:)


若你们想向客户收取特定选项的费用,那个么你们可以设置如下条件

创建一个方法

def create
  @schedule = Schedule.new(schedule_params)

  amount = 25 * 100
  customer = Stripe::Customer.create(
     email: params[:stripeEmail],
     card: params[:stripeToken]
  )

  create_charge(customer, amount, 'Rails Stripe customer', 'usd') if schedule_params[:delivery_option] == "pick_up"
end

private

def create_charge(customer, amt, desc, currency)
  Stripe::Charge.create(
     customer: customer.id,
     amount: amt,
     description: desc,
     currency: currency
   )
end

您是否将交货选项存储在
时间表
表中?
   def create
        @schedule = Schedule.new(schedule_params)


        if schedule_params[:delivery_option] == "pick_up"
           amount = 25 * 100
           customer = Stripe::Customer.create(
               email: params[:stripeEmail],
               card: params[:stripeToken]
             )

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


        if @schedule.save
           render json: @schedule
        else
           render json: @schedule.errors, status: :unprocessable_entity
        end
     end 
def create
  @schedule = Schedule.new(schedule_params)

  amount = 25 * 100
  customer = Stripe::Customer.create(
     email: params[:stripeEmail],
     card: params[:stripeToken]
  )

  create_charge(customer, amount, 'Rails Stripe customer', 'usd') if schedule_params[:delivery_option] == "pick_up"
end

private

def create_charge(customer, amt, desc, currency)
  Stripe::Charge.create(
     customer: customer.id,
     amount: amt,
     description: desc,
     currency: currency
   )
end