Developer forum

Forum » Ecommerce - Standard features » Recurring order failing even though payment seems succesful

Recurring order failing even though payment seems succesful

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

Our recurring orders our failing even though the payment seems fine. On the order log I see this:

Dynamicweb.Ecommerce.CheckoutHandlers.AltaPay.AltaPayCheckoutHandler Recurring order failed for ORDER10133 (based on REC86). The payment failed with the message: (OrderID:ORDER10133 (IsCart:False, Complete:False) Total:5, orderline total:5 kr; Orderlines:2 - Products:1, Discounts:1, Taxes:0, BOM:0, (IP:10.21.142.1, Url:/Admin/Public/TaskExecute.aspx), Thread:68, HashCode:22965211.)

There's no error message as far as I can see.

The XML from AltaPay stored on ther order seems alright:

<?xml version="1.0"?>
<APIResponse version="20170228">
  <Header>
    <Date>2022-09-30T11:02:54+02:00</Date>
    <Path>API/validatePaymentAuthentication</Path>
    <ErrorCode>0</ErrorCode>
    <ErrorMessage/>
  </Header>
  <Body>
    <Result>Success</Result>
    <Transactions>
      <Transaction>
        <TransactionId>101</TransactionId>
        <PaymentId>e7caf116-1e46-4468-....</PaymentId>
        <AuthType>subscription</AuthType>
        <CardStatus>Valid</CardStatus>
        <CreditCardExpiry>
          <Year>2023</Year>
          <Month>04</Month>

Is there anything I can debug or should I open a support case?

Imar

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

It could be some response parsing that goes wrong.

This is the code that causes the log entry:

And what could be wrong:

Could it be encoding issue? See no UTF8 header in the response XML document...

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Yeah, found the same code. It all seems to look OK. However, I just noticed this:

versus this:

The recurrence is from today while the Payment XML is from last week when the order got created. So it seems that this isn't the response from the payment, but from the original order? Are orders cloned when recurrence happens? 

I guess now we get a response back from AltaPay but we can't see it as it's not logged or stored anyway, right?

Imar

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

It could seem like the Recurring method in altapay does not save the respsonse when it is not a success - and the OrderManager also does not. So that could be why you cannot see it stored.

#9903

Does not explain what goes wrong though...

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> Does not explain what goes wrong though...

Yeah, exactly. Over the weekend I created a roque version of the provider that logs the response and saves it back on the order. That hopefully gives us some insights as to what's happening.

Imar

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

With that custom DLL we're getting better info. Here's what I see now which implies it's a configuration issue that we'll explore further:

  <Body>
    <Result>Failed</Result>
    <MerchantErrorMessage>Transaction not permitted at Terminal</MerchantErrorMessage>
    <CardHolderErrorMessage>Declined</CardHolderErrorMessage>

I used this to set the AltaPay XML but that didn't work:

order.SetXmlResponse(response.ResponseDocument.OuterXml);

I guess I also need to call Save on the OrderService, right? I assume that's called by SetOrderComplete on a success state so that's why there is no explicit call to Save in the AltaPay Recurring method?

Imar

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Yes, you need to call save. ANd yes, setordercomplete also saves.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

It turned out to be a configuration issue indeed. In order to make tracking down problems like this easier in the future, can the response XML be stored on the order? Something like this at the end of the Recurring method of AltaPayCheckoutHandler.cs:

if (response.Result == RequestResult.Success)
{
 ...
}
else
{
  order.CaptureInfo = new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed, "Recurring payment failed.");
  order.SetXmlResponse(response.ResponseDocument.OuterXml);
  Services.Orders.Save(order, false); // Save changes to the custom AltaPayXml field.

  LogEvent(order, "Recurring order failed for {0} (based on {1}). The payment failed with the message: {2}", DebuggingInfoType.RecurringError, order.Id, originalOrder.Id, response.ErrorMessage);
}

Thanks!

Imar

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Added - out with next version of Altapay.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

It was actually released yesterday.

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I checked the code and I don't think this will solve the issue. Commit acc77e7b has this:

else
{
  order.CaptureInfo = new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed, "Recurring payment failed.");
  LogEvent(order, "Recurring order failed for {0} (based on {1}). The payment failed with the message: {2}", DebuggingInfoType.RecurringError, order.Id, originalOrder.Id, response.ErrorMessage);
  Services.Orders.Save(order, saveOldVersion: false);
}

where the highlighted line is new. However, this just saves the order, but doesn't assign the AltaPay response to it. What is missing is this (from my previous post):

  order.SetXmlResponse(response.ResponseDocument.OuterXml);

before the call to Save.

And it's probably a good idea to do this before the if check for Success, so the XML is stored. regardless of success or failure.

Agreed?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Yikes, yes.

I have too many pulls going on at the same time. I have comitted the response saving now also - so at next bump it will be included.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Released now.

 

You must be logged in to post in the forum