Invoice 결제가 성공적 일 때 테이블에 데이터를 삽입하기 위해 Payola gem을 사용하여 웹 훅을 설정하려고합니다 (예 : invoice.payment_succeeded
). 왠지 이유로 작동하지 않습니다 .? 송장이 작품을 만들 때, 그러나 유사한 이벤트가 이메일을 보내이 내가 내 payola.rb
초기화 파일에있는 코드 :레일 4 Payola 스트라이프 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
내가 무엇을 놓치고
빙고 @ 엘리엇. 나는 코드를 뽑아 내고 실패한 곳을 보았다. 내 바보 같은 실수. 나는'subscription.save' 대신'subscription.update'를 사용하고있었습니다. 위의 수정 된 행이이 문제를 해결했습니다. 도움과 포인터를 가져 주셔서 감사합니다. – Alex