条纹一次性付款+定期付款

时间:2019-05-22 14:45:36

标签: ruby-on-rails ruby stripe-payments

我检查了Stripe api文档,但找不到(product_price + month_fee)模型的解决方案。 我可以看到Stripe :: Charge.create用于一次性付款,订阅用于定期付款。 指南链接或示例代码将非常感谢。 我尝试使用下面的代码,但没有成功。

def save_and_pay(params)
  customer = Stripe::Customer.create(
    :email => subscription.user.email,
    :source  => params[:stripeToken]
  )
  subscription.user.update(gateway_customer_id: customer.id, is_active: true)
  charge = Stripe::Charge.create(
    :customer    => customer.id,
    :amount      => (subscription.plan_price * 100).to_i,
    :currency    => 'usd',
    :description => 'subscription Payment'
  )
  self.payment_status = charge.paid
  self.payment_response = charge.status
  self.save    
end

谢谢

1 个答案:

答案 0 :(得分:0)

我找到了答案。

1)您需要在条纹仪表板中创建计划。 (对于此代码,我使用monthly_fee创建了一个计划)

2)您可以将以下代码添加到文件中

customer = Stripe::Customer.create(
  :email => "user@user.user",
  :source  => params[:stripeToken]
)

invoiceItem = Stripe::InvoiceItem.create({
  :customer    => customer.id,
  :amount      => 100,
  :currency    => 'usd',
  :description => 'subscription Payment'
})

charge = Stripe::Subscription.create(
  :customer => customer,
  :items => [
    {
      :plan => "monthly_fee",
      :quantity => 5
    },
  ]
)

希望这可以帮助面临相同案件的其他人。 谢谢

相关问题