java - 如何使 Stripe 的 WebhookEndpoint.create() 线程安全
问题描述
Stripe 关于如何创建 webhook 的示例并不安全,它使用静态变量来保存 apiKey。有谁知道如何通过 builder() 方法将密钥传递给 Stripe?他们的 RequestOptionsBuilder 类具有 setApiKey() 方法,我找不到与 webhook 类似的东西。
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
WebhookEndpointCreateParams params =
WebhookEndpointCreateParams.builder()
.setUrl("https://example.com/my/webhook/endpoint")
.addAllEnabledEvent(Arrays.asList(
WebhookEndpointCreateParams.EnabledEvent.CHARGE__FAILED,
WebhookEndpointCreateParams.EnabledEvent.CHARGE__SUCCEEDED))
.build();
WebhookEndpoint endpoint = WebhookEndpoint.create(params);
解决方案
有一个重载的方法WebhookEndpoint.create(PaymentIntentCreateParams createParams, RequestOptions requestOptions)
。RequestOptions 构建器允许您为每个请求设置各种值,包括私钥。我将其发布为答案,因为在搜索了 Stripe 网站数周后,在他们提出这个建议之前,他们花了几封电子邮件支持 Stripe;所以即使在 Stripe 也不是常识。
推荐阅读
- r - R:替换循环(使用跳过的索引)并 sapply 以加快性能
- bash - 如何同时运行多个 cURL 命令?
- powerbi - Power BI 中生成的视觉对象的聚合(平均值)
- node.js - 我想从连续加载nodejs的链接中检索数据
- python - 使用 Azure-Storage-Blob Python 读取 Blob 容器目录中每个 Blob 的文件大小
- discord - 为什么以下代码没有向用户添加角色?
- dialogflow-es - 如何使用对话框流在whatsapp bot中添加按钮
- powerbi - 显示具有父子/继任前辈关系的可视化
- graphql - 阿波罗角如何在突变中使用可为空但必需的参数?
- laravel-backpack - 将 Spatie 权限链接到 Backpack UI 显示/隐藏