我试图通过条带费用创建订单。目前,我可以通过 billing_address:charge.source.address_line1 来收取帐单地址,但我无法获取送货信息。
ChargesController
class ChargesController < ApplicationController
def create
@product = Product.find(params[:product_id])
#1 Create a charge
customer = Stripe::Customer.create(
email: current_user.email,
card: params[:stripeToken]
)
charge = Stripe::Charge.create(
customer: customer.id, # Note -- this is NOT the user_id in your app
amount: (@product.price * 100).to_i,
description: @product.title,
currency: 'usd',
)
#3 Create an Order
Order.create(
user: current_user,
billing_address: charge.source.address_line1
)
flash[:notice] = "Thank you for your order, #{current_user.email}! "
redirect_to books_path # or wherever
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
表格
<%= form_tag charges_path do %>
<h4>Click the button!</h4>
<script
class='stripe-button'
src="https://checkout.stripe.com/checkout.js"
data-key="<%= @stripe_btn_data[:key] %>"
data-amount=<%= @stripe_btn_data[:amount] %>
data-description="<%= @stripe_btn_data[:description] %>"
data-shipping-address="<%= @stripe_btn_data[:shipping] %>"
data-billing-address="<%= @stripe_btn_data[:billing] %>"
></script>
<%= hidden_field_tag :product_id, @product.id %>
PostsController
def show
@stripe_btn_data = {
key: "#{ Rails.configuration.stripe[:publishable_key] }",
description: @product.title,
amount: (@product.price * 100),
shipping: :true,
billing: :true
}
如何从条纹费用中获取送货信息?
答案 0 :(得分:0)
经过一些试验和错误后,我想出了如何将条纹费用插入我的数据库... shipping_address:params [:stripeShippingAddressLine1]
Order.create(
user: current_user,
billing_address: charge.source.address_line1,
billing_city: charge.source.address_city,
billing_state: charge.source.address_state,
billing_zip: charge.source.address_zip,
shipping_address: params[:stripeShippingAddressLine1]
)