ruby-on-rails - 最终事务上的 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
解决方案
推荐阅读
- date - Excel计数空日期列
- node.js - 角度的多个服务器请愿
- java - Java - 检测使用 htmlUnit 加载的网页 ajax 组件的更改
- javascript - 检测到移动设备并提醒使用桌面设备
- javascript - 如何在 JavaScript 中获取字符串的总和?(时间格式:00:00:00)
- docker - GCC - VM Machine - 分配更多 /dev/shm 内存
- node.js - 如何使用 node.js 在 mocha 和 chai 中同时使用 should 和 done
- ios - 个人开发团队,包括“*****”,不支持字体功能
- typescript - 是否可以将从模块导出的类型声明为全局类型?
- node.js - 使用 Node.js 进行串口通信 - 打包和发送 8 位二进制数据