How to tie/link a payout with the charge that preceded it?

1,316 views
Skip to first unread message

Ron Lum

unread,
Jun 30, 2017, 7:02:06 AM6/30/17
to Stripe API Discussion
Hi everyone,

I am wanting to use the PAYOUT/TRANSFER object as an event to run a function. However, I am running out of ideas to link a PAYOUT (po_xxxx) to the CHARGE (ch_xxxx) that preceded it. 

Quick FYI: 

"charge" is the event of the customer paying with the credit card
"payout" is when the transaction settles and Stripe actually puts the money (minus fee) into your bank account 

WHY? 
I want to do this so that I can access the metadata in the CHARGE object and attribute them to the PAYOUT event as well. For example, if I want to know which customer the payout is related to, I can look up the related CHARGE, which has a customer field and say "this payout is related to customer A and charge ." 

Right now, the only way for me to link the two (like a unique identifier/composite primary key, for those of you who like to think databases) is to look at the dates and the amounts (though CHARGE has gross amounts and PAYOUT has net amounts, but with calculations, you can do this). 

Help, please? 

Remi J.

unread,
Jun 30, 2017, 7:03:53 AM6/30/17
to api-d...@lists.stripe.com
Hey Ron,

What you are looking for is the Balance History API [1]. If you provide the payout identifier in the `payout` parameter you will get a list of transactions that were transferred out on the specified payout [2]. This lets you see each charge or refund for example that were bundled in that payout along with extra information such as the charge's customer id or metadata. You can also use the Expand feature [3] to get to multiple objects in one call and decrease the number of API requests you need to build your report!

Hope this helps!
Remi


--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Michael Bianco

unread,
Jun 30, 2017, 9:08:49 AM6/30/17
to Stripe API Discussion
Here's a script that you can use to find the charge associated with a payout:


Mike

Ron Lum

unread,
Jun 30, 2017, 10:56:38 AM6/30/17
to Stripe API Discussion
Is this something I can access with HTTP GETs?

Here is the item I get when I do a request for an individual Payout (some items edited for anonymity) using https://api.stripe.com/v1/payouts/__________:


{
  "id": "po_1A7hu3DwfKwfo61JzgecM__________",
  "object": "transfer",
  "amount": 203321,
  "arrival_date": 1492041600,
  "balance_transaction": "txn_1A7hu3DwfKwfo_________",
  "created": 1491989803,
  "currency": "usd",
  "description": "STRIPE TRANSFER",
  "destination": "ba_18tQfrDwfKwf_________",
  "failure_balance_transaction": null,
  "failure_code": null,
  "failure_message": null,
  "livemode": true,
  "metadata": {},
  "method": "standard",
  "source_type": "card",
  "statement_descriptor": null,
  "status": "paid",
  "type": "bank_account",
  "date": 1492041600,
  "transfer_group": null,
  "recipient": null,
  "bank_account": {
    "id": "ba_18tQfrDwfKwfo6___________",
    "object": "bank_account",
    "account_holder_name": null,
    "account_holder_type": null,
    "bank_name": "__________ _____ CREDIT UNION",
    "country": "US",
    "currency": "usd",
    "fingerprint": "dI90A5W2Cb______",
    "last4": "_____",
    "routing_number": "__________",
    "status": "new"
  },
  "amount_reversed": 0,
  "reversed": false,
  "reversals": {
    "object": "list",
    "data": [],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/transfers/po_1A7hu3DwfKwfo6______/reversals"
  },
  "application_fee": null,
  "source_transaction": null
}


And then here is the item returned when looking at individual BALANCE HISTORY:

{
  "id": "txn_1A7hu3DwfKwfo61JzgecM___",
  "object": "balance_transaction",
  "amount": -203321,
  "available_on": 1492041600,
  "created": 1491989803,
  "currency": "usd",
  "description": "STRIPE TRANSFER",
  "fee": 0,
  "fee_details": [],
  "net": -203321,
  "source": "po_1A7hu3DwfKwfo61JLm0q9___",
  "sourced_transfers": {
    "object": "list",
    "data": [],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/transfers?source_transaction=po_1A7hu3DwfKwfo61JLm0q9___"
  },
  "status": "available",
  "type": "transfer"
}

As you can see, there is no reference to the charge. Is it not possible via HTTP gets? Or is this advice pertaining to a newer version of the API?
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.

Remi J.

unread,
Jun 30, 2017, 11:03:12 AM6/30/17
to api-d...@lists.stripe.com
Hey Ron,

Unless that Payout was created manually via the API, there should be at least one transaction bundled into it. It's likely that the code you're using is simply getting the first balance transactions instead of the entire list.

Since this is specific to your code and your account, it would be better if you could reach out to our support team directly to discuss this. You can reach them here https://support.stripe.com/email and provide details about that specific payout, without redacted details and the exact code you're using on your end to list those.

Best,
Remi

To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.

Ron Lum

unread,
Jun 30, 2017, 5:49:29 PM6/30/17
to Stripe API Discussion
Thank you Remi. 

I am new to the API, so I definitely don't know the full extent of what is possible. 

However, I did stumble upon another thread.

This lead me to this following request:


Which gave me this:

{
  "object": "list",
  "data": [
    {
      "id": "ch_1AY1sEDwfKwfo6_________",
      "amount": 29319,
      "created": 1498263098,
      "currency": "usd",
      "customer_details": "____________",
      "description": "Invoice ________________",
      "fee": 880,
      "fee_details": [
        {
          "amount": 880,
          "application": null,
          "currency": "usd",
          "description": "Stripe processing fees",
          "type": "stripe_fee"
        }
      ],
      "net": 28439,
      "type": "charge"
    }
  ],
  "has_more": false,
  "url": "/v1/transfers/po_1AZGyWDwfKwfo61________/transactions"
}

Why is it not part of a regular query data? Not sure. Is there a way to lump these all into one query? Not sure. If I get answer back from Stripe support, I will post them. In the meantime, this should be enough to complete my task. Thank you!
Reply all
Reply to author
Forward
0 new messages