有很多不同型別的Stripe 事件。此外,他們指出他們可以隨時添加更多內容。我正在使用 dj-stripe。通過我的事件處理程式,我對我應該監視哪些型別的 webhooks 以進行非常簡單的 Stripe 訂閱設定有了一個很好的想法。在 dj-stripe 框架內,是否有一種簡單的方法可以捕獲我在生產中遇到的未處理的 webhook?在這些方面,我想通過電子郵件告訴自己發生了未處理的 Stripe webhook 事件。
例如,我有以下 webhook 處理程式:
@csrf_exempt
@webhooks.handler("checkout")
def my_handler(event, **kwargs):
print("handling checkout event...")
print(event.type)
@csrf_exempt
@webhooks.handler("customer")
def my_customer_handler(event, **kwargs):
print("handling customer event... in my_customer_handler")
print(event.type)
@csrf_exempt
@webhooks.handler("charge")
def my_charge_handler(event, **kwargs):
print("handling charge event... in my_charge_handler")
print(event.type)
@csrf_exempt
@webhooks.handler("payment_intent")
def my_payment_intent_handler(event, **kwargs):
print("handling payment_intent event... in my_payment_intent_handler")
print(event.type)
@csrf_exempt
@webhooks.handler("price", "product")
def my_price_and_product_handler(event, **kwargs):
print("handling price/product event... in my_price_and_product_handler")
print(event.type)
現在假設某種型別的發票 webhook 進來了。我知道 djstripe 會將此事件保存到djstripe_invoice表中(通過path('stripe/', include("djstripe.urls", namespace="djstripe")),)。但是,如果我想發現它不是當前在內置 dj-stripe URL 之外處理的 webhook 型別怎么辦?是否有任何我可以添加的網路鉤子簽名來通知我發生了網路鉤子事件,而我除了更新資料庫之外沒有做任何事情?
uj5u.com熱心網友回復:
Stripe 建議只訂閱您的業務所必需的事件,因此如果您確實發現訂閱的事件,您沒有處理好選擇是取消訂閱它們。
如果你想對所有事件做一些處理,它看起來dj-stripe有一個handler_all選項(code)。您可能希望維護一些您處理的顯式事件型別的字典,并在記錄未處理的事件之前檢查接收到的事件是否已處理。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/403006.html
標籤:
