You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Stripe技术问题:如何从Charge对象获取Payout对象

Let me break down how to connect your Charge to the right Payout, since you're hitting that "No such payout" error because you're using a Transfer ID (tr_xxx) instead of a Payout ID (po_xxx).

Stripe's flow here is a bit layered—Charges don't directly link to Payouts. Instead, they connect through either Transfers (if you're sending funds directly to a connected account) or Balance Transactions (if funds are first deposited into your platform's balance). Here's how to get the correct Payout ID in both scenarios:

Scenario 1: Charge was sent directly to a connected account (using the destination parameter)

If you created the Charge with a destination pointing to a connected account, the funds go through a Transfer first:

  • Start by retrieving your Charge object. Look for the transfer field—it will hold the Transfer ID (tr_xxx).
  • Retrieve that Transfer object. Inside it, you'll find a destination_payout field—this is the po_xxx Payout ID you need. Use this ID to call the Payout API, and it will work correctly.

Example code snippet (using Stripe's Python SDK):

import stripe
stripe.api_key = "your_api_key"

# Get the Charge
charge = stripe.Charge.retrieve("ch_your_charge_id")
# Extract the Transfer ID
transfer_id = charge.transfer
# Get the Transfer to find the linked Payout
transfer = stripe.Transfer.retrieve(transfer_id)
# Now you have the valid Payout ID
payout_id = transfer.destination_payout
# Retrieve the Payout
payout = stripe.Payout.retrieve(payout_id)

Scenario 2: Charge funds went to your platform's balance first

If the Charge's funds were added to your platform's balance before being included in a Payout:

  • Retrieve the Charge object and grab the balance_transaction field (it will be a txn_xxx ID).
  • Retrieve that Balance Transaction. Look for the payout field—this will be the po_xxx Payout ID once the funds have been included in a payout.

Note: If the funds are still in pending status (not yet paid out), the payout field will be null. It will populate once Stripe processes the payout for those funds.

Example code snippet:

import stripe
stripe.api_key = "your_api_key"

# Get the Charge
charge = stripe.Charge.retrieve("ch_your_charge_id")
# Extract the Balance Transaction ID
balance_txn_id = charge.balance_transaction
# Get the Balance Transaction
balance_txn = stripe.BalanceTransaction.retrieve(balance_txn_id)
# Get the linked Payout ID (if available)
payout_id = balance_txn.payout
if payout_id:
    payout = stripe.Payout.retrieve(payout_id)
else:
    print("Funds are still pending and not yet included in a payout")

To recap: You can't use a Transfer ID (tr_xxx) to look up a Payout directly—you need to go through either the Transfer's destination_payout (for direct connected account transfers) or the Balance Transaction's payout (for platform balance funds) to get the valid po_xxx Payout ID.

内容的提问来源于stack exchange,提问作者Loïc Bellemare-Alford

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:08:03