Ruby on Rails Stripe,设置默认金额

时间:2015-08-02 19:05:00

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

尝试将Stripe实现到我的应用程序中,但我对Ruby / Rails'的理解语法虽然功能齐全,但仍然非常基础。我该如何表达默认金额?我被提示"创建一个Amount类及其默认的类方法,它应该以便士的形式返回您想要收费的数字。一个这样的价值可能是15_00,十五美元。"在此先感谢您的帮助!

class ChargesController < ApplicationController
  def create

    # Creates a Stripe Customer object, for associating
    # with the charge
    customer = Stripe::Customer.create(
      email: current_user.email,
      card: params[:stripeToken]
    )

    # Where the real magic happens
    charge = Stripe::Charge.create(
      customer: customer.id, # Note -- this is NOT the user_id in your app
      amount: Amount.default,
      description: "BigMoney Membership - #{current_user.email}",
      currency: 'usd'
    )

    flash[:success] = "Thanks for all the money, #{current_user.email}! Feel free to pay me again."
    redirect_to user_path(current_user) # or wherever

  # Stripe will send back CardErrors, with friendly messages
  # when something goes wrong.
  # This `rescue block` catches and displays those errors.
  rescue Stripe::CardError => e
    flash[:error] = e.message
    redirect_to new_charge_path
  end

  def new
    @stripe_btn_data = {
      key: "#{ Rails.configuration.stripe[:publishable_key] }",
      description: "BigMoney Membership - #{current_user.name}",
      amount: Amount.default
    }
  end
end

0 个答案:

没有答案