2017-10-07 147 views
0

我正在用rails 5構建一個市場。我可以使用'stripe gem'來設置「自定義託管帳戶」,使用stripe connect條紋託管帳戶webhooks和rails

我還使用'stripe_event gem'來捕捉來自條紋的webhook。我可以使用標準條紋帳戶沒有任何問題。

但是,使用條連接我得再添account attribute某處當基於stripe docs。由於正在掛鉤的事件不存在於主條帶帳戶中,而是存在於已關聯帳戶中。

它使總體感覺我只是不知道如何更新我的班級這樣做。

Stripe.api_key = Rails.configuration.stripe[:secret_key] 


class RecordAccount 
    def call(event) 
     myevent = event.data.object 

     #Look up StripeAccount in our database 
     stripe_account = StripeAccount.where(stripe_id: myevent.account).last 

     #Record Verification details and status in StripeAccount 
     u = stripe_account.update_attributes(
      verification_status: myevent.legal_entity.verification.status, 
      verification_details: myevent.legal_entity.verification.details, 
      ) 
     u.save 

    end 
end 

StripeEvent.configure do |events| 
    events.subscribe 'account.updated', RecordAccount.new 
end 

我從上面得到的迴應是404-事件XXXX未找到。這是有道理的,但我該如何解決它。我知道這是一個簡單的答案,我只是一直在看屏幕太久。

回答

0

我還沒有使用過你提到的寶石,但我對連接的帳戶事件有同樣的問題。就我而言,我剛剛在我的應用程序中設置了一個端點來接收Stripe webhook事件。

重要的是,對於連接的帳戶,您必須在有效負載中使用「帳戶」屬性以及事件ID,而對於涉及您的帳戶的事件,您只需使用事件ID。

這裏是我的意思

begin 
    payload = JSON.parse(request.body.read) 
    # Verify the event by fetching it from Stripe 
    if payload['account'].present? 
     # This is for connected accounts 
     Stripe::Event.retrieve(payload['id'], stripe_account: payload['account']) 
    else 
     # Normal events 
     Stripe::Event.retrieve(payload['id']) 
    end 
    rescue Stripe::StripeError => e 
    # Handle this however you prefer 
    raise ActiveRecord::RecordNotFound.new(e) 
    end 

希望它可以幫助一個代碼示例!

+0

你是死的傳奇! –