-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Description
Consider the following code:
class Invoice::Payer
# ...
def pay
@invoice.lock do
payment = CreditCard::Charger.charge(@invoice.account.credit_card, @invoice.description, @invoice.amount)
if payment.success?
@invoice.update(paid: true)
end
end
end
end
class CreditCard::Charger
# ...
def charge
# ...
from_account = DoubleEntry.account(:credit_card, scope: @credit_card.account)
to_account = DoubleEntry.account(:sales, scope: @credit_card.account)
DoubleEntry.transfer(@amount, from: from_account, to: to_account, code: :purchase)
end
endThis seems like pretty reasonable code to me, but unfortunately doesn't work because in the Invoice class, I'm locking the invoice (which creates a transaction), and then the DoubleEntry#transfer method fails because it's transaction is not the outer-most one.
What's the reasoning behind making it the outer-most transaction? What would the world be like if it "just worked"?
destan
Metadata
Metadata
Assignees
Labels
No labels