Stripe 的结帐会话是否已存储 "forever"?

Are Stripe's Checkout Sessions stored "forever"?

使用 stripe 的 API 和 Integration Builder,在您进入结帐页面之前,您可以在 create-checkout-session.php 文件中获取 Ceckout Sessionsid。 (https://stripe.com/docs/api/checkout/sessions/object?lang=php)

我的计划是稍后使用该会话 ID 获取客户 ID 和订阅 ID。

但是这些会话会过期吗?意味着一段时间后,我将无法检索该会话? (https://stripe.com/docs/api/checkout/sessions/retrieve?lang=php).

Ps:我认为这不重要,但我使用 PHP 作为我的后端语言。

结帐会话不会永久存储。它们的寿命很短,然后就会过期。但是,如果您需要客户和订阅 ID,您可以按照以下步骤操作(我在我的一个项目中使用的相同)。

  1. 创建结帐会话,一旦用户在结帐成功后重定向回网站,使用会话 ID 检索会话
  2. 在retrieve session响应中,如果支付方式是subscription,则有customer(customerId)和subscriptionId。
  3. 从会话中获取客户 (customerId) 和 subscriptionId 检索 api 响应并将两者存储到数据库中供以后使用。
  4. 进一步获取客户信息,您可以使用客户 api 并传递 customerId 以获取有关该客户的详细信息。
  5. 同样,您可以使用订阅 api 来检索特定的订阅。

要清楚,

  • 您可以检索 Checkout Session any time using the API : https://stripe.com/docs/api/checkout/sessions/retrieve 的完整详细信息。这个没有“过期”。
  • 您只能访问 Event e.g. checkout.session.completed if it was created within the last 13 months from the Dashboard. Events older than 30 days will only provide a summary view. Events within the last 30 days will be fully visible via the API and Dashboard. (source)
  • 的完整数据
  • 结帐会话在创建 24 小时后过期(即客户无法 access/pay 通过结帐 url), but you can shorten the expiration time by setting expires_at (source)。请注意,您仍然可以访问第一点中提到的结帐会话的详细信息。

理想情况下,您应该依赖 webhooks :

checkout.session.completed 事件将包含 customer and subscription