我对滑轨和条纹很陌生。我正在使用条纹付款结帐在Ruby on Rails上构建我的应用程序。用户填写一些数据,然后在接受付款时将其保存到数据库中。在表格中,用户可以选择或购买其他尺寸或鲜花。小号中号大号。小号是30磅,中号是60磅,大号是90磅。我希望当在表格中选择不同的选项时,条纹收费给客户的金额发生变化。
视图
<%= simple_form_for(Subscription.new, :url => { :action => "create" }) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :address %>
<%= f.input :postcode %>
<%= f.input :mobile_number %>
<%= f.input :deliverAddress %>
<%= f.input :deliverName %>
<%= f.input :frequency, collection: Subscription::FREQUENCY, prompt:
"Frequency" %>
<%= f.input :size, collection: Subscription::SIZE, prompt: "select size" %>
<%= f.input :delivery , collection: Subscription::DELIVERY, prompt: "Deliver or Collect" %>
<%= f.input :start %>
</div>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="A month's subscription"
data-amount=???
data-locale="gbp"></script>
<% end %>
subscription_controller
def create
@subscription = Subscription.new subscription_params.merge(card_token: stripe_params["stripeToken"])
raise "Please, check registration errors" unless @subscription.valid?
@subscription.process_payment
@subscription.save
redirect_to @subscription, notice: 'Registration was successfully created.'
rescue e
flash[:error] = e.message
render :new
end
private
def stripe_params
params.permit :stripeEmail, :stripeToken
end
控制器
class Subscription < ApplicationRecord
validates :name, :address, :postcode, :mobile_number, :frequency, :size, :delivery, :start, presence: true
# validates :mobile_number, numericality: {only_integer: true }, length: { minimum: 10, too_short: "is too short "}
FREQUENCY = %w{ Weekly Fortnightly Monthly}
SIZE = ['small', 'medium', "Large", "sublime"]
DELIVERY = ['Thursday Delivery', 'Friday Delivery', 'Friday AM Collection', 'Friday PM collection']
def process_payment
customer = Stripe::Customer.create card: card_token
Stripe::Charge.create customer: customer.id,
amount: ???,
description: "flowers",
currency: 'gbp'
end
end