Developer forum

Forum » Ecommerce - Standard features » Reccuring orders using the API

Reccuring orders using the API

Nuno Aguiar
Reply

Hi,

 

Is it possible to create a reccuring order through the API? If so, how?

 

Best Regards,

Nuno Aguiar


Replies

 
Viktor
Reply
This post has been marked as an answer

Hi Nuno,

Actually you can create Recurrong order via Api:


public void CreteRecurringOrder(Order order)
        {
            var recurring = new RecurringOrder();
            recurring.Interval = 1;                                                               //recurring order interval i.e. amount of days or months.
            recurring.IntervalUnit = RecurringOrder.IntervalUnitType.Days;     //recurring order interval type i.e. days, weeks or months
            recurring.StartDate = DateTime.Now;
            recurring.EndDate = DateTime.Now.AddYears(1);
            recurring.Save();
            order.IsRecurringOrderTemplate = true;
            order.RecurringOrderId = recurring.ID;
            order.Save();
        }


Best regards,
Viktor Letavin
DynamicWEB Software A/S, Russian team

Votes for this answer: 1
 
Nuno Aguiar
Reply

Hi Viktor,

 

This is perfect, thank you.

 

Best Regards,

Nuno Aguiar

 
Gonçalo Assunção
Reply

Hi Viktor,

 

I'm using this method to generate a recurring order through the api, but I would like to set it's total price to 0.00. Is it possible?

The idea is that the customer only pays once for a subscription, and it generates a recurring order that would be shipped every month, but it's already paid.

The prices in an order are usually read-only.

edit:
I've tried to add the following line to what you mentioned:
recurring.TotalPrice = new PriceInfo();
recurring.Save();

But it still creates a recurring order with the same price of the 'main' order

 

Thank you

Kind Regards
Gonçalo Assunção

 
Viktor
Reply

Hi Gonçalo,

I think you can try to implement price provider which will change the prices based on whether the order is recurring or not.

Best regards,
Viktor Letavin
DynamicWEB Software A/S, Russian team

 
Gonçalo Assunção
Reply

Hi Viktor,

Thank you for your answer!

I took a different approach to this: I'm creating a copy of the initial order, and in that copy I'm running the following code:

            var recurring = new RecurringOrder();
            order.AllowOverridePrices = true;
            foreach (OrderLine orderline in order.OrderLines)
            {
                if (orderline.Type == "0")
                {
                    orderline.AllowOverridePrices = true;
                    orderline.SetUnitPrice(new PriceInfo(), true);
                }
            }

            RemoveFeesAndTaxes(order);
            order.ForcePriceRecalculation();
            order.ClearCachedPrices();

            recurring.Interval = 1;                                             
            recurring.IntervalUnit = RecurringOrder.IntervalUnitType.Months;    
            recurring.StartDate = DateTime.Now;
            recurring.EndDate = DateTime.Now.AddMonths(subscriptionLength);
            recurring.TotalPrice = new PriceInfo();
            recurring.Save();
            
            order.IsRecurringOrderTemplate = true;
            order.RecurringOrderId = recurring.ID;
            order.Save();

In the 'RemoveFeesAndTaxes' method I'm creating a discount orderline with the total amount of the shipping, payment fees and total taxes.

It's all working without any problem, except the receipt after the order is complete, where it displays the recurring order, where all the prices are set to 0, and not the 'main' order, with all the prices set, and fees and taxes.

 

Thank you

KR,
Gonçalo Assunção

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

For anyone looking at this, I have an updated solution:
https://doc.dynamicweb.com/forum/ecommerce-standard-features/recurring-orders-admin?PID=1605

 

You must be logged in to post in the forum