stripe-payments - Stripe events:如何通过 Stripe events 和 webhook 捕获成功支付的产品?
问题描述
我网站的用户将使用 Stripe 的单次付款工作流程和结帐会话购买积分。他们可以以折扣价购买单个积分或积分套餐,例如 10 积分套餐。成功付款后,我想使用 webhook 捕获事件并根据用户支付的产品和数量更新用户余额。
我目前正在跟踪payment_intent.succeeded
事件,我可以看到付款和收费信息,但是我找不到与所订购产品相关的任何信息。我错过了什么?谢谢你。
这是我正在捕获的付款意图事件的示例:
{
"amount": 5250,
"amount_capturable": 0,
"amount_received": 5250,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"data": [
{
"amount": 5250,
"amount_captured": 5250,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_1HUSonCfZ37XLQD8mLERR2YR",
"billing_details": {
"address": {
"city": null,
"country": "JP",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "xxxx.xxxx.xxxx@gmail.com",
"name": "asd",
"phone": null
},
"calculated_statement_descriptor": "XXX XXXX",
"captured": true,
"created": 1600847712,
"currency": "jpy",
"customer": "cus_I4c27DIUQuvAHQ",
"description": null,
"destination": null,
"dispute": null,
"disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
"id": "ch_1HUSomCfZ37XLQD8d133buOK",
"invoice": null,
"livemode": false,
"metadata": {},
"object": "charge",
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 39,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_1HUSoWCfZ37XLQD82vnE1yQT",
"payment_method": "pm_1HUSolCfZ37XLQD8gSn0oy4x",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 11,
"exp_year": 2050,
"fingerprint": "uaJa23vzDgA7fnSC",
"funding": "credit",
"installments": null,
"last4": "4242",
"network": "visa",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/acct_1HU77uCfZ37XLQD8/ch_1HUSomCfZ37XLQD8d133buOK/rcpt_I4c233eGeSYOaN9cPvncC4AcU2Sm4s7",
"refunded": false,
"refunds": {},
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
],
"has_more": false,
"object": "list",
"total_count": 1,
"url": "/v1/charges?payment_intent=pi_1HUSoWCfZ37XLQD82vnE1yQT"
},
"client_secret": "pi_1HUSoWCfZ37XLQD82vnE1yQT_secret_XXX",
"confirmation_method": "automatic",
"created": 1600847696,
"currency": "jpy",
"customer": "cus_I4c27DIUQuvAHQ",
"description": null,
"id": "pi_1HUSoWCfZ37XLQD82vnE1yQT",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"object": "payment_intent",
"on_behalf_of": null,
"payment_method": "pm_1HUSolCfZ37XLQD8gSn0oy4x",
"payment_method_options": {
"card": {
"installments": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
解决方案
假设您已将产品详细信息放在line_items
您创建的 Checkout 会话中(请参阅指南步骤),那么您正在寻找的是如何“履行订单”(请参阅指南步骤),您可以通过收听checkout.session.completed
事件。
当您收到一个事件时,该事件data
将是一个按 id 的 Checkout 会话,然后您可以检索该会话并指定expand\[\]=line_items
能够检查line_items
该会话。
更新:我修改了上面的内容以反映line_items
默认情况下不包括在内。您必须检索会话并将其包含在展开中。
推荐阅读
- javascript - 使用间隔编辑消息
- python - 如何将 Django Queryset 的 Q 对象转换为 SQL?
- powerbi - 如何根据应用于另一个维度的 RLS 过滤维度?
- spring-boot - 无法使用自定义 Spring 引导库中的类
- azure - Databricks FileInfo:java.lang.ClassCastException:com.databricks.backend.daemon.dbutils.FileInfo 无法转换为 com.databricks.service.FileInfo
- python - 向 Spacy NER 可视化器添加功能
- spring-boot - 对于@sqslistener,从 .yaml 文件以外的环境变量传递值
- sql - 将月份列增加 1 并存储在 scala 变量中
- asp.net - RabbitMq“指定的端点都无法到达”(Windows)
- c# - 如何在波引擎中添加点列表