首页 > 解决方案 > 最终事务上的 Rails Stripe 集成错误

问题描述

我已经集成了 Stripe,它应该设置为让用户可以成为卖家并销售产品。其他用户可以购买,平台收取费用,其余的由卖家获得。当我尝试进行购买时,我收到 500 内部服务器错误。日志告诉我错误是这样的:

Stripe::InvalidRequestError (You cannot create a destination charge on a connected account without the `card_payments` capability enabled. Use transfer_data[destination] to create a destination charge for a connected account with the `platform_payments` capability.)

我不明白如何解决这个问题。

事务.rb

  def create
    @transaction = Transaction.new(transaction_params)
    @transaction.buyer_id = current_user.id
    @listing = Listing.find(params[:listing_id])
    @seller = @listing.user
    @transaction.listing_id = @listing.id
    @transaction.seller_id = @seller.id

    @total_amount = (@listing.price * 100).to_i
    @charged_fee = (@listing.price * 15 - 30).to_i

    charge_error = nil

    if @transaction.valid?
      begin
        if !current_user.stripe_id.blank?
          customer = Stripe::Customer.retrieve(current_user.stripe_id)
        else
          customer = Stripe::Customer.create(
            :email => params[:stripeEmail],
            :source  => params[:stripeToken]
          )
          current_user.stripe_id = customer.id
          current_user.save
        end

        charge = Stripe::Charge.create(
            {
                :customer => customer.id,
                :amount      => @total_amount,
                :description => @listing.title,
                :currency => 'usd',
                :destination => @seller.uid,
                :application_fee => @charged_fee
            },
        )

      rescue Stripe::CardError => e
        charge_error = e.message
      end
      if charge_error
        flash[:error] = charge_error
        respond_to do |format|
          format.html { render :new }
        end
      else
        @transaction.save

        Activity.create!(item_id: @listing.id, user_id: current_user.id,
                                  activity_type: "purchase")

        Notification.create!(listing_id: @listing.id, 
                                recipient_id: @listing.user_id, notified_by_id: current_user.id, 
                                notification_type: "purchase")
        respond_to do |format|
          format.html { redirect_to purchases_path, notice: 'Transaction successful. You may now download this.' }
        end
      end
    else
      flash[:error] = 'one or more errors in your order'
      render :new
    end
  end

标签: ruby-on-rails

解决方案


条纹设置图片

  1. 你能检查一下你的 Stripe 设置吗?条纹-> 设置-> 连接。
  2. “完成您的平台配置文件” - 如果您还没有 2.1,如果您只是在第一步开始,您必须选择“功能”:平台支付或卡支付。

启动平台图片


推荐阅读