2016-07-28 19 views
0

Invoice支払いが成功した場合にPayola gemを使用してデータをテーブルに挿入しようとしています(何らかの理由でこれが動作しません)。 。?請求書が作品を作成されたときが、同様のイベントが電子メールを送信するためにこれは私が私のpayola.rb初期化ファイルを持っているコードです:Rails 4 Payola Stripe webhook請求書をお支払いの際にテーブルに挿入

Payola.configure do |config| 

    Payola.secret_key =Rails.application.secrets.payola_secret_key 
    Payola.publishable_key = Rails.application.secrets.payola_publishable_key 

    config.send_email_for :receipt, :admin_receipt 
    Payola.support_email="[email protected]" 

# this webhook works and I get an email when new invoice is created 
    config.subscribe 'invoice.created' do |event| 
    subscription = Payola::Subscription.find_by(stripe_id: event.data.object.subscription) 
    user=User.find(subscription.owner_id) 
    UserMailer.invoicecreated_email(user).deliver_now 
    end 
# this webhook is supposed to create a new PaymentHistory record and send an email, but none of these actions is performed after invoice is paid. 
    config.subscribe 'invoice.payment_succeeded' do |event| 
     subscription = Payola::Subscription.find_by(stripe_id: event.data.object.subscription) 
     #subscription = Payola::Subscription.find_by(stripe_id: event.data.object.lines.data[0].id) 
     user=User.find(subscription.owner_id) 
     subscription.fail_payment_date1 = nil 
     subscription.fail_payment_date2 = nil 
     subscription.update 
     PayolaPaymentHistory.create(owner_id: user.id, subscription_id: subscription.id, 
      payment_date: Time.at(event.data.object.date).to_date,amount: event.data.object.amount_due,currency: event.data.object.currency, 
      date_start: Time.at(event.data.object.lines.data[0].period.start).to_date, 
      date_end: Time.at(event.data.object.lines.data[0].period.end).to_date, 
      description: 'Monthly payment') 
     UserMailer.successpayment_email(user).deliver_now 
    end 
end 

私は何をしないのです

答えて

0

までダウンこれにブロックをトリミングしてみ我々は何かを簡単に実行する:

config.subscribe 'invoice.payment_succeeded' do |event| 
    raise 'Yes the invoice.payment_succeeded webhook is running!' 
end 

Railsのサーバーを停止し、payola.rb初期化子の変更がピックアップされることを保証するためにbin/spring stopで春を停止(春たびpayola.rb初期化子の変更を停止してみてください)。

テスト支払いを行い、上記のエラーメッセージがログに出力されているか、rails serverの出力であるかどうかを確認してください。あなたが見つけたものを報告してください。

+0

ビンゴ@Eliot。私はコードを引き出し、どこが失敗したかを見ました...私の部分からの愚かなエラー。私は 'subscription.save'の代わりに' subscription.update'を使っていました。上の編集された行がこの問題を修正しました。あなたの助けとポインタをありがとう。 – Alex

0

誰もがこの愚かなエラーので、頭痛を取得している場合、私は間違っていたところだから、ここです:

subscription = Payola::Subscription.find_by(stripe_id: event.data.object.subscription) 
# this is wrong 
subscription.fail_payment_date1 = nil 
subscription.fail_payment_date2 = nil 
subscription.update 

# this is allowed 
subscription.fail_payment_date1 = nil 
subscription.fail_payment_date2 = nil 
subscription.save 

# this is also allowed 
subscription.update(fail_payment_date1: nil, fail_payment_date2: nil) 

一切Payolaと全く問題は私のエラーが完全に...ありませんでした。

関連する問題