gpt4 book ai didi

ruby-on-rails - 充电失败时检索 Stripe 充电 ID

转载 作者:数据小太阳 更新时间:2023-10-29 07:39:00 26 4
gpt4 key购买 nike

我正在尝试在充电失败时检索 Stripe 充电 ID,因此当 charge.failed Hook 被触发时,我可以通过该 id 检索我的记录。我尝试检查触发的异常,但找不到任何方法来获取它。这是我的代码:

  def charge
token = params[:stripeToken]
type = params[:stripeTokenType]
metadata = {}
record = Record.new(amount: Random.rand(2000), valid: false)
charge = nil
begin
charge = Stripe::Charge.create(
{
amount: 2000,
currency: 'eur',
source: token,
description: 'Test',
metadata: metadata
}, { stripe_account: 'xxxxx' })
record.stripe_charge_id
flash[:notice] = 'Transaction validée'
rescue Exception => e
record.error = e.code
flash[:error] = 'Erreur de paiement'
end
flash[:error] = 'Erreur de paiement' unless record.save || flash[:error]
redirect_to :stripe_test
end

最佳答案

我终于使用元数据来存储我的记录 ID 和费用。所以我能够使用此元数据检索它。

charge = Stripe::Charge.create(
{
amount: 2000,
currency: 'eur',
source: token,
description: 'Test',
metadata: { record_id: 23 }
}, { stripe_account: 'xxxxx' })

关于ruby-on-rails - 充电失败时检索 Stripe 充电 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36239918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com