2016-07-28 4 views
0

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 

내가 무엇을 놓치고

답변

0

때까지 이것에 블록을 트리밍 시도 우리는 단순한 달리기를 얻는다 :

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

레일 서버를 중지하고 payola.rb 초기화 변경이 선택됩니다 확인하기 위해 bin/spring stop와 함께 봄을 중지 (봄 각 시간 payola.rb 초기화 변화를 막으려).

위의 오류 메시지가 귀하의 로그 및/또는 rails server 출력에서 ​​발생했는지 확인하십시오. 당신이 찾은 것을 다시보고하십시오. 내가 잘못 어디로 갔는지

+0

빙고 @ 엘리엇. 나는 코드를 뽑아 내고 실패한 곳을 보았다. 내 바보 같은 실수. 나는'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) 

무엇이든지 증회 아무 문제가 없었다 ... 완전히 내 오류입니다.

관련 문제