Invoice Webhook的Stripe Event Gem和Action Mailer

时间:2013-11-19 04:47:02

标签: ruby-on-rails actionmailer webhooks

我设置条纹事件gem来处理我的webhooks。它真的为我简化了一些东西。一切都在初始化器中完成。我想在他们注册订阅时向我的新客户发送发票,但没有正确执行。

这是我的stripe.rb初始化程序

Stripe.api_key = ENV["STRIPE_API_KEY"]
STRIPE_PUBLIC_KEY = ENV["STRIPE_PUBLIC_KEY"]


StripeEvent.setup do
  subscribe 'customer.subscription.deleted' do |event|
    subscription = Subscription.find_by_stripe_customer_token(event.data.object.customer)
    subscription.update_attribute(:subscription_status, "inactive")
  end

  subscribe 'invoice.payment_succeeded' do |event|
    subscription = Subscription.find_by_stripe_customer_token(event.data.object.customer)
    InvoiceMailer.invoice_subscription(subscription).deliver
    end
end

我不允许在初始化程序中使用InvoiceMailer吗?它只适用于控制器吗?

我有一个名为invoice.rb的邮件

class Invoice < ActionMailer::Base

  def invoice_subscription(subscription)
    mail(:to => subscription.email, :subject => "My Subscription Invoice", :from => "invoice@mywebsite.com")
  end

end

1 个答案:

答案 0 :(得分:0)

使用

Invoice.invoice_subscription(subscription).deliver

而不是InvoiceMailer或将invoice.rb中的班级名称更改为InvoiceMailer