我已在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();会给对象。我仍然没有看到从这个对象中获取客户的方法 –