Developer forum

Forum » Ecommerce - Standard features » AltaPay subscriptions not capturing

AltaPay subscriptions not capturing

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have a subscription that uses AltaPay as the payment gateway. We've configured the gateway to subscribe and capture:

image

However, it seems that it's only reserving when making the subscription order.

In StartCheckout I see this:

string typeValue = PaymentTypeValue.ToString();
typeValue = char.ToLower(typeValue[0]) + typeValue.Substring(1);
request.SetParameter("type", typeValue);

 

But in Recurring I see no code that sets the type. Could it be that it's missing and should have been set to PaymentTypeValue and that AltaPay defaults to SubscriptionAndReserve when the type is missing?

Thanks!

Imar


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I do not think we have ever supported or tested subscription payments in any gateway. Dynamicweb recurring uses saved card functionality.

In this case I think that you need to alter the post template for Altapay to send the needed information for the subscription. Usually you have to declare that it is digital products if you do charge automatically - if it is physical products, you are not allowed to charge before the product has been sent.

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

It turns out to be a bit more problematic. I don't think I can change any template as this is server to server when executing IRecurring.Recurring, isn't it. Recurring has this code:

var request = CreateRequest();
request.SetParameter("transaction_id", originalOrder.TransactionNumber);
request.SetParameter("amount", order.TotalPrice.ToString(".00", NumberFormatInfo.InvariantInfo));

AltaPayResponse response = request.SendRequest("chargeSubscription");

XmlNodeList transactions = response.ResponseDocument.SelectNodes($"APIResponse/Body/Transactions/Transaction");
XmlNode payment = transactions?.Item(0);
XmlNode recurringPayment = transactions?.Item(1);

...
order.TransactionType = "ChargeSubscription";
order.TransactionStatus = recurringPayment?.SelectSingleNode("TransactionStatus")?.InnerText ?? string.Empty;
...
if (response.Result == RequestResult.Success)
{
    order.CaptureAmount = Converter.ToDouble(recurringPayment?.SelectSingleNode("CapturedAmount")?.InnerText);
    order.CaptureInfo = new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Success, "Recurring payment captured.");
    ...
}
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.
    ...
}

So it seems to always assume that it has been captured (see bold line). This makes the problem bigger as the money is reserved bur not captured, while the UI now believes it is captured (because of the CaptureInfo state) and therefore doesn't allow capturing anymore :-(

Am I seeing this right?

Could I, while we look into this further, update the capture state to NotCaptured for an order and then try capturing it from the UI again?

Imar

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Did you create the payment with subscribe and charge? I cannot see that working as it requires creating an agreement:

https://documentation.altapay.com/Content/Ecom/API/API%20Methods/createPaymentRequest.htm?Highlight=SubscriptionAndCharge

If you are running requrring I think you need the saved credit card feature.

I have asked one with Altapay knowledge to jump in the conversation :-)

 
Stanislav Smetanin Dynamicweb Employee
Stanislav Smetanin
Reply
This post has been marked as an answer

Hi Imar,

Well, I don't think that I am really good in AltaPay, but I will try to help.

Could you please describe the problem step by step to help me reproduce it on my local solution?

So, you use SubscriptionAndCharge, and then create the reccuring order, right?
From which moment do you have a problem? I need to understand the situation to reproduce it somehow and probably find the way to fix it.

These are all existed payment methods in AltaPay: https://documentation.altapay.com/Content/Ecom/Reference/Payment%20request%20type.htm

About the SubscriptionAndCharge payment method.


It looks like that we planned to introduce it somehow, but in fact it probably doesn't work as intended. Nicolai is right that this payment method need to set the agreement, but it is not mandatory. According to documentation, it sets the agreement type to recurring if nothing was passed from the request.

Looks like that the functionality of this command is to automate the subscribtion (we can set the interval and the expire date - much like we do for recurring orders in Dynamicweb. But we already have such functionality in our Dynamicweb implementation, so we don't need it).

-----

The IRecurring.Recurring of our AltaPay provider works differently. It does the charge subscription request (see: https://documentation.altapay.com/Content/Ecom/API/API%20Methods/chargeSubscription.htm)
In the code we set the amount to capture which is equal to the total order price:


And if result is ok, than we mark the order as captured, because we captured the full order price. It's totally ok. It works as intended.

So first we call the createPaymentRequest command with SubscriptionAndCharge type agrument, and then we call chargeSubscription for each of recurring orders.

Maybe the problem in the SubscriptionAndCharge. I recommend to use another payment type:

If we set payment type to be a "subscription", then we need to manually call "chargeSubscription" requests for each recurring orders - as we already do. So I believe that it will work ok with this type of setting.

Please try to use it, maybe it fix your problem.

Maybe I don't understand your situation, so I still need an additional information to reproduce the problem. Sorry if I didn't help you, but I will try again when I have some data to analyze.

 

Kind regards.

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

Sorry for the slow response Stanislav. We had some miscommunication here on who would follow up ;-)

Anyway, setting it to Subscription did do the trick indeed. That doesn't create a transaction in AltaPay (which is good) but sets everything up to capture on the next recurrence of the order.

I do have another, related issue though. When the subscription is created in AltaPay it uses the recurring order ID (like REC123) instead of an actual order ID. Then when the recurring payment is made, it uses that same ID again:

This makes it somewhat difficult to see which order the payment belongs to; especially since the Orders node in the backend doesn't show recurring orders and the recurring node doesn't show normal orders.

I am not sure what the solution is though. At the time of transaction creation all we have is the REC ID. And then when placing the recurring transaction, we don't send the DW order ID anymore, but only the TransactionNumber. The AltaPay docs says this:

Would it make sense to populate transaction_info with the order ID so we have both the recurring template ID as well as the order ID?

And while I was on their doc site, I found this:

They don't quantify "for a while" but it might be necessary to change transaction_id to the agreement ID?

Thanks!

Imar

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Imar

The bugfix for AltaPay and "Subscription" has been fixed in Dynamicweb 9.17.15

Get the application files from download section https://doc.dynamicweb.dk/downloads/dynamicweb-9

Kind Regards
Care Support
Kristian Kirkholt

Votes for this answer: 1

 

You must be logged in to post in the forum