I tried doing this but I'm getting some weird results. I implemented the following nvelocity code:
Code: Select all
<table class="Email">
<tr>
<th class="Email">Payments for Order $order.OrderNumber</th>
</tr>
</table>
<table class="Email">
#foreach($payment in $order.Payments)
#beforeall
<tr class="detailHeader">
<td style="text-align: center;">Date</td>
<td style="text-align: center;">Type</td>
<td style="text-align: center;">Amount</td>
<td>Status</td>
<td>Reason</td>
</tr>
#each
<tr class="Email">
<td class="Email" style="text-align: center;">
$payment.PaymentDate.ToString("G")
</td>
<td class="Email" style="text-align: center;">
$payment.PaymentMethodName $payment.ReferenceNumber
</td>
<td class="Email" style="text-align: right;">
$payment.Amount.ToString("ulc")
</td>
<td class="Email">
$payment.PaymentStatus
</td>
<td class="Email">
#set ($Reason = "")
#if ($payment.PaymentStatus == "Void")
#foreach($trans in $payment.Transactions)
#if (($trans.TransactionType == "Authorize") || ($trans.TransactionType == "AuthorizeCapture") || ($trans.TransactionType == "AuthorizeRecurring"))
#set ($Reason = "")
#if ($trans.TransactionStatus == "Failed")
#set ($Reason = $trans.ResponseMessage)
#end
#end
#end
#end
$Reason
</td>
</tr>
#afterall
</table>
#end
- The first time I submit a failed transaction, I get a status of Unprocessed and a blank reason.
- If I resubmit the payment (but still have it fail), I get two transactions. The first one now says Void and Transaction Failed; the second one has a status of AuthorizationFailed with a blank reason.
- If I resubmit the payment (but still have it fail), I get three transactions. The first and second ones say Void and Transaction Failed; the third one has a status of AuthorizationFailed with a blank reason.
What's strange is that all three payments and their transactions are identical. All the payments have PaymentStatusId = 10 (Void) and null for the PaymentStatusReason. Each payment has two transactions: the first is the AuthorizeCapture with a ResponseMessage of TransactionFailed; the second is the Void with a ResponseMessage of Manual Void Successful.
It looks like during the first pass, the email is generated before the database is written to. And somewhere I must have a logic error to cause the last payment line to say AuthorizationFailed with a blank reason.
I would appreciate if someone can tell me my error. Thank you.