Skip to content
Advertisement

Stripe API and PHP: Relationship of PAYOUTS to Payment Intent / Charges

I’m new with STRIPE, and I’ve been reading the documentation for STRIPE, and was task to create a list of payouts to a connected account (type is standard). Also, I have to show the details, under those PAYOUT, all the payments included in it.

However I can’t see any relation to PAYOUTS with PAYMENT INTENTS/CHARGES, is it possible to know all those payments included in the PAYOUTS ? We are creating STANDARD connect accounts for our users.

Advertisement

Answer

I had the same challenge, and had to go thru 4 supporters, tell my needs over and over again, before i finally got the right hint and could complete my checks and cron jobs. I provide my solution here to save others the same experience:

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

StripeStripe::setApiKey($stripeSecretKey);
$balanceTransactions = StripeBalanceTransaction::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";
}

Output (cropped to relevant data):

{
  "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"
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement