条带API和PHP:付款与付款意向/费用的关系

hfsqlsce  于 2023-01-01  发布在  PHP
关注(0)|答案(3)|浏览(194)

我是新的STRIPE,我一直在阅读STRIPE的文档,并负责创建一个已连接帐户的支出列表(类型是标准的)。此外,我必须显示详细信息,在这些支出下,所有的付款包括在其中。
但是,我看不出付款意向/费用与付款有任何关系,是否可以知道付款意向/费用中包含的所有付款?我们正在为用户创建标准连接帐户。

6yjfywim

6yjfywim1#

我有同样的挑战,不得不通过4支持者,告诉我的需求一遍又一遍,在我终于得到正确的提示,可以完成我的检查和cron作业.我在这里提供我的解决方案,以保存其他人相同的经验:

$po = 'po_sadfahk.....'; // payout id (i do a loop of payouts)

\Stripe\Stripe::setApiKey($stripeSecretKey);
$balanceTransactions = \Stripe\BalanceTransaction::all([
  'payout' => "$po",
  'type' => 'charge',
  'limit' => 100, // default is 10, but a payout can have more pi's
  'expand' => ['data.source'],
]);

foreach ($balanceTransactions->data as $txn) {
  // my invoice id is added in description when creating the payment intent
  echo "Invoice: {$txn->description}\n"; 
  echo "Created: {$txn->created}\n";
  echo "Available: {$txn->available_on}\n";
  // in source we find the pi_id, amount and currency for each payment intent
  $charge = $txn->source; 
  echo "pi: {$charge->payment_intent}\n";
  $amount = $charge->amount/100;
  echo "$amount {$charge->currency}\n";
}

输出(裁剪为相关数据):

{
  "object": "list",
  "data": [
    {
      "id": "txn_1ISOaSGqFEoKRtad...",
      "object": "balance_transaction",
      "amount": 25000,
      "available_on": 1615680000,
      "created": 1615131127,
      "currency": "dkk",
      "description": "Invoice 44",
      ...
      "fee": 530,
      "fee_details": [
        {
          "amount": 530,
          "application": null,
          "currency": "dkk",
          "description": "Stripe processing fees",
          "type": "stripe_fee"
        }
      ],
      ...
      "source": {
        "id": "ch_1ISOaRGqFEoKR...",
        "object": "charge",
        "amount": 25000,
        ...
        "paid": true,
        "payment_intent": "pi_1ISOa3GqFE...", // here we go!
        "payment_method": "pm_1ISOaRGqFE...",
        "payment_method_details": {
          "card": {
            "brand": "visa",
            ...
          },
          "type": "card"
        },
        ... 
      },
      "status": "available",
      "type": "charge"
    }
  ],
  "has_more": false,
  "url": "/v1/balance_transactions"
}
bjp0bcyl

bjp0bcyl2#

我不确定您是否拥有标准账户的访问权限,但如果您拥有,您将能够列出与该支出相关的所有余额交易,其中将引用source字段中的付款意向,以获取任何付款意向。

bxfogqkk

bxfogqkk3#

感谢金正日的回答。我也在Stripe找了很多支持者,但都无济于事。他的帖子让我明白了。

下面的代码只是Kim上面代码的Python 3.10翻译

po = 'po_<some_payment_id>'

balanceTransactions = stripe.BalanceTransaction.list(
  payout=po,
  type='charge',
  limit=100,
  expand=['data.source']
)

for txn in balanceTransactions.data:
  print("Invoice: {0}".format(txn.description))
  print("Created: {0}".format(txn.created))
  print("Available: {0}".format(txn.available_on))
  charge = txn.source
  print("pi: {0}".format(charge.payment_intent))
  amount = charge.amount/100
  print("{0} {1}".format(amount, charge.currency))

相关问题