The problem with this is the whole version designed system. Even if
you were to follow the best practices of updating an order, somehow
you will still see orders fail sporadically in the commerce pipeline
because of the InvalidVersion exception. Also, this problem
dramatically increases in the fulfillment pipeline. I have seen this
on every project I have worked on.
Yes you could call update version on the order but a lot of the times
I have seen exceptions that specify the payment groups are out of
version (using OOTB cybersource processor) and there is no way to
explicitly call update version on a payment group. Without ranting on
about the version designed system, which I could all day, I have a
solution I have found that works pretty well if you would like to try
it.
- First you create a new table that is essentially a replica of the
credit card status table. It will contain a column for the payment
group id and columns for every property on your credit card status
object. This table represents an audit table for your credit card
status.
- Then you will need to override the authorize method of your
CreditCardProcessor class.
- Immediately after the authorization is received from the 3rd party
processor or gateway, you save the values in the authorization status
to your new audit table. You need to do this in a new transaction
with mode RequiresNew. This suspends the current transaction and
guarantees that the new entry is saved in your audit table.
- Now that you have audit records of your authorization statuses, you
will need to put a check in right before the call is made to the
gateway to see if the audit record exists.
- If it does exist and because the CreditCardStatus is an object, you
can now create the CreditCardStatus object using the values in your
audit table.
Here is the process flow when an order is submitted
Transaction 1 begins
1. Order state updated to SUBMITTED
2. Order is validated and runs through the processOrder pipeline
3. Order reaches authorize payment pipeline
4. Check to see if Cybersource response already exists
a. if true
i. Create Cybersource status from existing response.
ii. continue to 7
b. if false continue to 5
5. Order is sent to Cybersource for authorization
6. Authorization received from Cybersource
a. Transaction 1 suspended
i.
Transaction 2 begin
ii.
Save Cybersource authorization to audit table
iii.
Transaction 2 commit
b. Transaction 1 resume
7. Pay state updated to Authorized
8. Finish processOrder pipeline.
9. Update order.
10. Commit transaction 1.
Using this solution allows you to maintain the natural flow of the
pipelines and default behavior of submitting an order. Please note
that the same concept will apply to debiting the credit card in the
fulfillment pipeline which is actually more important then the
authorization. This is because a lot of credit card processors,
paymentech for instance, allow multiple debits per authorization and
they do not decline debits over the authorized amount.
Michael