#some1ataplace
1 messages · Page 1 of 1 (latest)
Hey there, you use https://stripe.com/docs/api/balance/balance_retrieve and the Stripe Account header, see: https://stripe.com/docs/connect/authentication
For example, in python it would be this? print(stripe.Balance.retrieve(stripe_account='acct_1Nu7mfIsMFguiimW'))
I see this:
{
"available": [
{
"amount": 0,
"currency": "usd",
"source_types": {
"card": 0
}
}
],
"instant_available": [
{
"amount": 7500,
"currency": "usd",
"source_types": {
"card": 7500
}
}
],
"livemode": false,
"object": "balance",
"pending": [
{
"amount": 12500,
"currency": "usd",
"source_types": {
"card": 12500
}
}
]
}
That looks right to me
So all 3 - available, instant_available, pending need to be all 0?
Need to be 0 for what?
If a user is to delete their account from my website. How do I stop them from deleting their account unless they have a 0 balance?
Ah we discussed this yesterday, I forgot
Yea sorry, I just got to it now since I have some free time
Yeah so you will need to either reverse the transfers that were sent to that account equal to the amount of their current balance, or you need to wait until that balance is paid out.
Then you can delete the account within Stripe.
oh wow how could I determine either of those in the API?
Either of those being a payout or reversing transfers?
yes
Well you can list Transfers: https://stripe.com/docs/api/transfers/list#list_transfers-destination
-
reverse the transfers that were sent to that account equal to the amount of their current balance
-
wait until that balance is paid out - how can you check this
And if the account is on automatic payouts then that will just happen... automatically
In terms of checking on when that occurs, you either listen to Webhooks for payout.paid or you just check once a day using a cron job or something like that
hmm all right this is going to require more effort than I thought. Give me some time I will try to write some code.
So print(stripe.Transfer.list(destination='acct_1Nu7mfIsMFguiimW')) will list all historic transfers? Or just the ones that are pending?
All
Oh boy so I would have to reverse all the transfers even if they successfully completed?
Wouldn't I just need to reverse the pending ones that have not completed yet, how would i do that?
No you wouldn't reverse all
ok cool so just the ones that have not completed yet, how can i see that in the api
You can list balance transactions on the Connected Account using https://stripe.com/docs/api/balance_transactions/list and see which balance transactions haven't yet reached their available_on (https://stripe.com/docs/api/balance_transactions/object#balance_transaction_object-available_on)
When you do that you also want to expand the source: https://stripe.com/docs/api/balance_transactions/object#balance_transaction_object-source
This will give you the Charge on the Connected Account and that Charge will contain the source_transfer (https://stripe.com/docs/api/charges/object#charge_object-source_transfer) which is what you want to reverse
thanks will review this after my work meeting
👍
I am unable to do this?
print(stripe.BalanceTransaction.list(id='txn_3NzuhiIeTJrsS1re27hFhwHe'))
Received unknown parameter: id
Hi there
hi
Yeah that's not a valid param: https://stripe.com/docs/api/balance_transactions/list?lang=python
The suggestion above wasn't to pass an id either
If you want to list balance transactions on a connect account, don't pass that id param and make sure to pass the stripe account header of the connect account whose balance transactions you're trying to get: https://stripe.com/docs/connect/authentication
ah
That worked
print(stripe.BalanceTransaction.list(stripe_account='acct_1Nu7mfIsMFguiimW'))
But then you also want to expand source as suggested above
Recommend taking a look at https://stripe.com/docs/expand
yes trying that now
print(stripe.BalanceTransaction.list(stripe_account='acct_1Nu7mfIsMFguiimW', expand=['data.source']))
Then I would do this?
https://stripe.com/docs/api/transfer_reversals/create
"source_transfer": "tr_3NzKn4IeTJrsS1re2XLouM29"
stripe.Transfer.create_reversal(
"tr_3NzKn4IeTJrsS1re2XLouM29",
amount=100,
)
How would I say the full amount even if it is not 100? I would have to extract that from stripe.BalanceTransaction.list?
or can i exclude amount=100 and it will do the entire amount?
If you exclude amount it will reverse the entire amount