# 扩展响应用例 展开 API 响应以返回常见的支付详情。 可在您的 API 请求中使用 `expand` 参数,来检索 API 默认响应中未返回的细节。以下使用案例将针对常见的请求信息演示该参数。 ## 查看特定付款的 Stripe 费用 您可以在支付处理完成后查看支付费用,Stripe 会创建[余额交易](https://docs.stripe.com/api/balance_transactions/object.md#balance_transaction_object-fee_details)。[charge.updated](https://docs.stripe.com/api/events/types.md#event_types-charge.updated) 事件引用 `balance_transaction` 属性(例如 `txn_123`),表示它准备就绪,可供使用。 您可以使用 `expand` 在一个单独的调用中检索余额交易,而不必单独检索余额交易。 > *IC+ 用户* (A pricing plan where businesses pay the variable network cost for each transaction plus the Stripe fee rather than a flat rate for all transactions. This pricing model provides more visibility into payments costs)无法从余额交易中检索支付费用信息。请改用支付费用报告。 #### curl ```bash curl https://api.stripe.com/v1/payment_intents/pi_1Gpl8kLHughnNhxyIb1RvRTu \ -u <>: \-d "expand[]"="latest_charge.balance_transaction" \ -G ``` API 版本 [2022-08-01](https://docs.stripe.com/upgrades.md#2022-08-01) 或更早版本的用户: #### curl ```bash curl https://api.stripe.com/v1/payment_intents/pi_1Gpl8kLHughnNhxyIb1RvRTu \ -u <>: \-d "expand[]"="charges.data.balance_transaction" \ -G ``` > 为确保 Stripe 已收取费用,PaymentIntent 必须被 [捕获](https://docs.stripe.com/payments/place-a-hold-on-a-payment-method.md#capture-funds),且其[状态](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-status) 为 `succeeded`。 使用 `automatic_async`(自 `2024-04-10` 版本后默认 `capture_method`)时,支付成功后会创建余额交易,但在后台异步进行。这意味着: - 确认支付后,Charge 对象中的 `balance_transaction` 字段可能会立即为 `null` - 如果您展开 `balance_transaction` 或 `latest_charge.balance_transaction`,其可能无法在响应中使用 - 您可以监听 `charge.updated` 事件,了解何时可使用余额交易 这种异步行为提高了支付效率,但需要确保您的集成能处理余额交易有时无法立即可用的情况。 ## 查看提现中包含的收款 每笔自动*提现* (A payout is the transfer of funds to an external account, usually a bank account, in the form of a deposit)都会与您的 Stripe 账户余额的历史变化有关。API 以[余额交易](https://docs.stripe.com/api/balance_transactions/object.md)来记录这些历史变化,可通过[余额交易列表](https://docs.stripe.com/api/balance_transactions/list.md)来检索。您可以从余额交易列表中扩展 [source](https://docs.stripe.com/api/balance_transactions/object.md#balance_transaction_object-source) 属性来收集触发账户余额变化的因素(收款、退款、转账,等)的信息。例如: #### curl ```bash curl https://api.stripe.com/v1/balance_transactions \ -u <>: \ -d payout=po_1Gl3ZLLHughnNhxyDrOia0vI \ -d type=charge \-d "expand[]"="data.source" \ -G ``` > 只能检索_自动_提现所涉及的余额交易记录。如果启用了手动提现,则必须自己跟踪交易记录。 了解有关[提现对账](https://docs.stripe.com/payouts/reconciliation.md)的更多信息。。 如果您用 *Connect* (Connect is Stripe's solution for multi-party businesses, such as marketplace or software platforms, to route payments between sellers, customers, and other recipients) 进行定向收款,则可以代您的 Connect 子账户检索同一信息。不同之处在于,向 Connect 子账户转移资金时,定向收款涉及转账和关联的付款(以 Charge 对象的形式)。因此,在列示特定于您的 Connect 子账户的提现的余额交易时,每笔余额交易的来源都会关联到转账的 Payment,而非原始 Charge。检索原始 Charge 时,需要通过 [source_transfer](https://docs.stripe.com/api/charges/object.md#charge_object-source_transfer) 属性扩展付款关联的转账;从这里,扩展转账的 [source_transaction](https://docs.stripe.com/api/transfers/object.md#transfer_object-source_transaction) 属性。 #### curl ```bash curl https://api.stripe.com/v1/balance_transactions \ -u <>: \ -d payout=po_1G7bnaD2wdkPsFGzdVOqU44u \ -d type=payment \-d "expand[]"="data.source.source_transfer.source_transaction" \ -H "Stripe-Account: acct_1G7PaoD2wdkPsFGz" \ -G ```