我已在Java Spring MVC Web Application
中配置Stripe
付款。我可以添加一個Customer
,創建一個Plan
併爲客戶設置Subscriptions
。由於我有經常性付款,我希望一旦生成發票和付款後發送電子郵件通知給客戶。從條紋文件中,我需要的事件類型是invoice.upcoming.
,invoice.payment_succeeded
和customer.subscription.trial_will_end
,因爲我有少數計劃的試用期。使用Stripe Webhook獲取使用Stripe的定期付款的客戶詳細信息
我已經在我的應用程序增加了一個網絡掛接端點:
@ResponseBody
@RequestMapping(consumes="application/json", produces="application/json", method=RequestMethod.POST, value="/webhook-endpoint")
public Response stripeWebhookEndpoint(@RequestBody String stripeJsonEvent)
{
Event event = Event.GSON.fromJson(stripeJsonEvent, Event.class);
String type = event.getType();
StripeObject stripeObject = event.getData().getObject();
return Response.status(Response.Status.OK).build();
}
我試圖讓event type
,也是customer Id
,這樣我就可以從我的數據庫獲取客戶和發送基於事件的電子郵件通知。由於我在我的localhost
中有我的webhook網址,因此無法從Stripe中觸發實際的數據。此外,我無法從條紋文檔中找到示例數據:https://stripe.com/docs/api#invoice_object。我也試過Retrive stripe data from stripe webhook event,但沒有一些樣本數據就無法測試它。
有沒有一種方法可以從事件中獲取所需的詳細信息,並且還可以在本地主機上測試這些信息。
感謝您的答覆事件
data
對象,但我仍然是如何可以從事件對象的客戶ID。當我嘗試event.getUserId()時,它顯示不推薦使用Event類型的getUserId()方法。我現在需要的是事件類型和客戶ID,以便我可以向該客戶發送電子郵件 –根據我的答案中的以前的JSON樣本,如果事件類型爲「invoice.upcoming」,則可以分析JSON你從webhook獲得的數據並讀取'data.object.customer'屬性來獲取客戶ID。它會對你的用例起作用嗎? –
StripeObject stripeObject = event.getData()。getObject();會給對象。我仍然沒有看到從這個對象中獲取客戶的方法 –