Skip to content

Commit

Permalink
server/payout: improve usefulness of UnmatchingTransfersAmount error
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Oct 30, 2024
1 parent 296606d commit 133ebe7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/polar/transaction/service/payout.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ def __init__(self, account: Account) -> None:


class UnmatchingTransfersAmount(PayoutTransactionError):
def __init__(self) -> None:
def __init__(self, payout_amount: int, transfers_amount: int) -> None:
self.payout_amount = payout_amount
self.transfers_amount = transfers_amount
message = (
"Can't split the balance transactions into transfers "
"equal to the payout amount."
"equal to the payout amount. "
f"Expected {payout_amount} but got {transfers_amount}. "
f"Difference: {payout_amount - transfers_amount}"
)
super().__init__(message)

Expand Down Expand Up @@ -445,7 +449,7 @@ async def _prepare_stripe_payout(

transfers_sum = sum(amount for _, amount, _ in transfers)
if transfers_sum != -transaction.amount:
raise UnmatchingTransfersAmount()
raise UnmatchingTransfersAmount(-transaction.amount, transfers_sum)

# If the account currency is different from the transaction currency,
# Set the account amount to 0 and get the converted amount when making transfers
Expand Down

0 comments on commit 133ebe7

Please sign in to comment.