def lookup_tax_cloud
unless tax_cloud_transaction.nil?
tax_cloud_transaction.lookup
else
create_tax_cloud_transaction
tax_cloud_transaction.lookup
tax_cloud_adjustment # never called if lookup raises exception
end
end
However, because the transaction was created successfully, we will never again follow the execution path which would cause a tax adjustment to be created. Thus subsequent update_adjustments calls have no effect.
So I think the best strategy for ensuring an adjustment is created along with a transaction is as follows:
def lookup_tax_cloud
unless tax_cloud_transaction.nil?
tax_cloud_transaction.lookup
else
create_tax_cloud_transaction
begin
tax_cloud_transaction.lookup
ensure
tax_cloud_adjustment
end
end
end
Even if the adjustment is created with a zero dollar amount, subsequent lookups will allow update_adjustments to do it's job.
If you like what you see, let me know and I can submit a PR.
Any exception that occurs during a tax cloud transaction lookup prevents the next line of the caller from being executed. In this case:
However, because the transaction was created successfully, we will never again follow the execution path which would cause a tax adjustment to be created. Thus subsequent
update_adjustments
calls have no effect.My initial strategy for dealing with this issue was to simply wrap the vulnerable code in a transaction, however, I was quickly reminded that objects will not have their instance data returned to their pre-transactional state.
So I think the best strategy for ensuring an adjustment is created along with a transaction is as follows:
Even if the adjustment is created with a zero dollar amount, subsequent lookups will allow
update_adjustments
to do it's job.If you like what you see, let me know and I can submit a PR.
Thanks,
Brian