#drum

1 messages · Page 1 of 1 (latest)

eternal widgetBOT
remote lark
#

i'm currently solving this problem by fetching the connected account's Balance, and using the full balance as well as its currency to determine the payout amount and currency, but this feels like a hack, because the Balance could have been incremented by something else than the Transfer we created immediately before (in theory)

next tapir
#

That's generally how we recommend doing it. Where is the problem that you're running into?

remote lark
#

oh interesting - you do recommend to fetch the Balance to retrieve the total balance, and you use that amount to determine the amount of the payout?

#

what if, for example, two Transfers for $100 USD each happened from unrelated sources, resulting in a $200 balance on the account, but each process initiating the transfers used this same logic? then one Payout would fail, and one payout would be for $200, which would be unexpected

next tapir
#

I don't follow.

but each process initiating the transfers used this same logic? then one Payout would fail
this shouldn't happen as far as I can tell

remote lark
# next tapir I don't follow. > but each process initiating the transfers used this same logi...
  1. process 0 submits Transfer 0 for $100
  2. process 1 submits Transfer 1 for $100
  3. process 0 submits Payout with an amount equal to the total account balance, so it's for $200
  4. process 1 attempts to submit a payout for $0, which should fail. even if it doesn't, the transfer-payout pairs don't match (i.e. from the perspective of just Transfer 1, it'll look like it wasn't paid out, and from the perspective of Transfer 0, the resultant payout amount won't match what we transferred)
#

perhaps this is how it's supposed to be tho - perhaps you can't ever really guarantee that a payout will be the same amount as a transfer unless you're operating in USD and you use the transfer amount as the payout amount?

next tapir
#

You should be checking the balance for both processes to minimize the likeliness of race conditions, but there's no way to completely mitigate the possibility unless you set up a queuing system to make the API calls consecutively, rather than in parallel.