【问题标题】:Shipping Address with Stripe in RailsRails 中带条纹的收货地址
【发布时间】:2015-07-29 09:27:13
【问题描述】:

我正在使用 Stripe 和 Rails 为一家小型在线企业创建支付系统。我正在使用 Stripe 的 Checkout 功能,这使得设置基本付款变得非常容易。

由于该企业销售实物,我需要收集用户的送货地址信息并将其包含在付款提交中。但是,我注意到 Stripe 关于如何实现这一点的文档非常糟糕。我以前没有使用过 Stripe,所以我对从这里去哪里没有很好的直觉。这是我的代码的样子:

收费/new.html.erb

<%= form_tag charges_path do %>
  <article>
    <label class="amount">
      <span>Amount: <%= @order.subtotal %></span>
    </label>
  </article>

  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
          data-image="http://www.fairmountbagel.com/images/bagels/pavot2.png"
          data-description="Your Bagel Clock"
          data-name="Bagel-O-Clock"
          data-amount="<%= @amount %>"></script>
<% end %>

控制器/chargers_controller.rb

class ChargesController < ApplicationController
    before_filter :load_order

    def new
        if !@order.order_items.empty?
            @amount = (@order.subtotal.to_f * 100).to_i
        else
            redirect_to root_path
        end
    end

    def create
        @amount = (@order.subtotal.to_f * 100).to_i

        customer = Stripe::Customer.create(
            :email => @order.customer_info.email,
            :card  => params[:stripeToken]
            )

        charge = Stripe::Charge.create(
            :customer    => customer.id,
            :amount      => @amount,
            :description => 'Rails Stripe customer',
            :currency    => 'cad'
            )

        @order.order_items.destroy_all

    rescue Stripe::CardError => e
        flash[:error] = e.message
        redirect_to charges_path
    end

    private
    def load_order
        @order = current_order
    end
end

我是否应该将运输信息保存到地址模型中,然后将信息传递给客户或收费对象?或者我可以在 Stripe Checkout 模式中创建字段吗?谢谢

【问题讨论】:

    标签: ruby-on-rails stripe-payments


    【解决方案1】:

    以防万一您不知道您可以创建测试费用并在您的dashboard 中查看。使用test card number,例如 4242424242424242。上面的代码对我来说看起来不错。

    一个选项

    让stripe处理送货地址(check this posts),然后点击pay with card,看看它是什么样子的。

    提交付款后,Stripe 会生成一个 JSON 响应,您可以处理该响应并将其保存到您的数据库中,请查看此帖子 post。

    另一种选择:

    您对您的应用程序进行编码,以便用户在不输入送货地址的情况下无法下订单,并且一旦用户输入送货地址,您就允许他们使用 Stripe 付款

    让我知道这是否有帮助或者您是否遇到了困难。我相信你已经看过 Stripes 文档,但以防万一这里是 link

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 2014-02-04
      • 2015-05-03
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 2015-10-05
      相关资源
      最近更新 更多