#some1ataplace

1 messages · Page 1 of 1 (latest)

cunning pilotBOT
muted ravine
fresh rapids
#

I am trying to figure out in python what the best way to compare current UTC time to your UTC times

muted ravine
#

Time at which the object was created. Measured in seconds since the Unix epoch.

fresh rapids
#

ok cool thanks give me a few moments trying to figure out now the best way to do it

muted ravine
fresh rapids
#

the first link doesn't seem to mention Unix time, but is saying that Stripe does everything in terms of UTC. The second link seems to contradict this since it's giving a Unix timestamp (which as mentioned before has no timezone because it's a duration)

#

So maybe what they mean is that they store durations as offsets from the Unix epoch, and store timestamps as UTC (in some format they aren't talking about)

muted ravine
#

Right, sorry. The first link might be a red-herring, since it refers to times in the Stripe Dashboard.

#

I would say store timestamps in whatever format is most helpful for you, with the understanding that conversions will have to happen for both inbound and outbound requests if you store them in something that's not natively used.

tl;dr use time since the Unix epoch for API interactions, unless that's unwieldy for your local storage

fresh rapids
#

Would this work?

datetime.datetime.now(datetime.timezone.utc); dt = now_utc - other_time;

#

where other_time is your API time?

#

Or if I am doing a < or > comparison

muted ravine
#

I'm not sure. What happens when you log the output? Is it giving what is expected?

fresh rapids
#

print(datetime.datetime.now(datetime.timezone.utc).timestamp())
1697231703.540641

muted ravine
#

Is that what you were expecting?

fresh rapids
#

It says there you can get current python epoch time

#

I did this using 2 different methods they are very close but I did one right after the other one and they are probably the same thing

#

So would you say either would work? Or one is better than the other?

#

Under the what is epoch time paragraph on that link, is that what you guys are doing too?

muted ravine
#

It's all a matter of taste. I personally would go with print(time.time())

fresh rapids
#

So if I did this:

for x in stripe.BalanceTransaction.list(stripe_account='acct_1Nu7mfIsMFguiimW', expand=['data.source']):
print(x.available_on)
if x.available_on > time.time()
print('available_on still pending')

#

Would that make sense? time.time() will eventually be the same thing as x.available_on? They are both using epoch on the same UTC timezone?

muted ravine
#

Why do they need to be the same thing?

#

Why not just store the timestamp Stripe gives you?

fresh rapids
#

I want to be able to compare current time to whgat the API says

muted ravine
#

That sounds like it would work to me

fresh rapids
#

ok thanks

fresh rapids
#

Another question

#

I have a stripe connect account

#

Where these stripe connect accounts are affiliate marketers for my site who get a commission for getting a new sale.

#

But on my website, logged in users could delete their accounts. And they wouldn't be able to recover their stripe connect account login with their stripe connect account id

#

So I was told on this support channel the other day to do this:

you can't delete a Connected Account until their balance is 0
Lookup connect account balance in the API, if zero, then allow account deletion
retrieve the balance of your Connected Account. You use https://stripe.com/docs/api/balance/balance_retrieve and pass the Stripe Account Header, see: https://stripe.com/docs/connect/authentication
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.

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

#

What is the difference between available amount, instant_available amount, pending amount?

#

This is my code:

print(stripe.Balance.retrieve(stripe_account='acct_1Nu7mfIsMFguiimW'))
print(stripe.Balance.retrieve(stripe_account='acct_1Nu7mfIsMFguiimW').available[0].amount)
print(stripe.Balance.retrieve(stripe_account='acct_1Nu7mfIsMFguiimW').instant_available[0].amount)
print(stripe.Balance.retrieve(stripe_account='acct_1Nu7mfIsMFguiimW').pending[0].amount)

current_timestamp = int(time.time())

for x in stripe.BalanceTransaction.list(stripe_account='acct_1Nu7mfIsMFguiimW', expand=['data.source']):
#Get all the balance transactions that have not yet reached their available_on date
if x.available_on > current_timestamp:
print(x.id)
print(x.available_on)
print(x.source.source_transfer)
#Reverse the transfers
stripe.Transfer.create_reversal(x.source.source_transfer)

muted ravine
#

Did you already read about those in the API reference?

fresh rapids
#

Not really

#

Am I on the right track with that code? Basically before the user deletes their login from my website, I want to say to them hold on you still have a balance (either available, instant_available, pending) - not sure which one is important here.

Or if they really want to delete their login from my site, I would reverse all the transfers so they could delete their account. But they would lose all their money that has not been paid out yet

muted ravine
fresh rapids
#

thanks. So pending would be it has been paid out but still processing?

muted ravine
#

It means that the funds haven't reconciled in your balance yet

fresh rapids
#

ok cool

#

and what do you think about the code I have for reversing transactions?

#

For example, a stripe connect account still has payouts and all sorts of money that has not processed yet. But for some strange reason they want to delete their website account and in the process delete everything in my database. So they cannot recover their stripe connect express link. So I would have to reverse all those transfer ids that have not reached their available_on

cunning pilotBOT
muted ravine
#

That would stop them from being paid, no?

fresh rapids
#

Yes

#

I would also want to delete their connect account to

#

Once you leave my website, I want to turn everything off

#

If they share an affiliate link with the outside world, if they leave my website, I don't want the affiliate link to work anymore.

#

If you leave, its the same thing as an employee quits kind of, they shouldn't get paid anymore

brisk wagon
#

Hi there, stepping in and catching up

fresh rapids
#

sure

brisk wagon
#

You won't be able to deleted a Connected Account that still has a balance, https://stripe.com/docs/api/accounts/delete? You can attempt to reverse these funds like you mentioned, Once the balance is 0, you can delete the account.

fresh rapids
#

Ok

#

and which balance would need to be 0? available, instant_available, pending?

#

all 3?

brisk wagon
#

All balances shoule be zero

fresh rapids
#

ok

#

if i don't delete the connect account though but the customer deletes my website account, would they still be getting a commission?

#

Let's say they leave their affiliate link out there in the internet but they cannot access my site anymore

#

But they still have a stripe connect account behind the scenes

#

Is there a way I could pause their connect account payments instead or cancel them from receiving funds anymore but keep their stripe account?

#

Wondering also what happens to all the money if the transfers from the connect account are reversed? Do I as the platform get all that money back?

#

Can I do this?

stripe.Account.modify(
"acct_1EKVL0IeTJrsS1re",
payouts_enabled=False,
)

brisk wagon
#

Yes, you can disable the payout like that for a Connected Account.

fresh rapids
#

Okay that might be better then. So I could essentially have them still receive their remaining balances but they can no longer get any commission?

#

Then I would keep the connect account and not delete it, only disable payouts

#

hmm but disabling payouts would prevent any remaining balances from getting paid to them. So I should probably reverse all remaining transfers, then disable their payouts if they leave my website.

#

Does that sound right?

brisk wagon
#

That sounds right, but I recommend that you reach out to our support team. Our support team will be able to assist you better than I can: https://support.stripe.com/contact with balance vaialbalilty and payouts.

fresh rapids
#

But should I delete their account? Could they reactivate it on the express dashboard?

#

reactivate their payouts enabled i mean or is that only something i can do?

brisk wagon
#

Hmm, I'm not 100% sure. Our support team would be able to assist with Dashboard functionalities. They have more expertise on this.

fresh rapids
#

ok sure thing thanks. Are you the last one on here today?

brisk wagon
#

yes

fresh rapids
#

ok and the support team will answer my questions even on the weekend?>

brisk wagon
#

Yes