Try Now
More in this section

Forums / Developing with Sitefinity / Custom checkout process with recurring transactions

Custom checkout process with recurring transactions

3 posts, 0 answered
  1. AlphaZeta
    AlphaZeta avatar
    14 posts
    06 Jun 2006
    13 Jul 2012
    Link to this post
    I'm building a custom checkout process and have a few questions.

    1) One of the features of this checkout process is to allow for donations that can include recurring billing. So the user has to specify how many times to perform the recurring transaction, duration, and start date. In the custom payment gateway, I've added fields to a PaymentRequest object that implements interface IPaymentRequest to handle these fields. How do I populate these fields when using the checkout API demonstarted in this example: http://www.sitefinity.com/blogs/stevemiller/posts/12-04-13/sitefinity_ecommerce_custom_checkout_ndash_part_1.aspx 

    2) When selling items items on the site, we would like to do an inventory check. I've added a custom field to my product type Tickets. I've tried dynamicModuleManager to get the product and update the quantity but I get object reference is null error when I execute GetDataItem method. How can I go about checking a custom field and updating it? Here is what I have tried:

    01./// <summary>
    02./// Performs a check on the order to determine if what is in the cart is available
    03./// by checking against custom "Quantity" field.
    04./// </summary>
    05./// <param name="order">The order object with details (line items) to check</param>
    06./// <returns>Returns true if all quantities requested can be provided.</returns>
    07.private static bool CheckInventory(CartOrder order) {
    08.    Type productType = null;
    09.    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
    10.    DynamicContent myDynamicProduct = null;
    11.    Catalog.Model.Product myProduct = null;
    12.    CatalogManager myCatManager = CatalogManager.GetManager();
    13.    int iQuantityAvailable = 0;
    14.    bool bSuccess = true;
    16.    foreach (CartDetail myLineItem in order.Details) {
    17.        // get product object based off of line item id
    18.        myProduct = myCatManager.GetProduct(myLineItem.ProductId);
    20.        // find the product type
    21.        productType = TypeResolutionService.ResolveType(myProduct.GetType().FullName);
    22.        myDynamicProduct = dynamicModuleManager.GetDataItem(productType, myLineItem.ProductId);
    24.        // determine if product type has a quantity field, if it doesn't continue to next line item
    25.        if (!myDynamicProduct.DoesFieldExist("Quantity")) {
    26.            continue;
    27.        }
    29.        // if quantity field exists, check if amount available exceeds quantity requested
    30.        iQuantityAvailable = Convert.ToInt32(myDynamicProduct.GetValue("Quantity"));
    31.        if (iQuantityAvailable < myLineItem.Quantity) {
    32.            bSuccess = false;
    33.        }
    34.    }
    36.    return bSuccess;

  2. Grace Hallwachs
    Grace Hallwachs avatar
    144 posts
    03 Nov 2014
    19 Jul 2012
    Link to this post

    1) I would recommend using OnePage Checkout and saving the recurring transaction, duration, and start date along with the order. Also you may use a Scheduler to actually charge the customer. You can use any .NET based job scheduler for doing this task. For this example you can use Quartz.net . You can add it to your project by using Nuget. I have included some code snippets for your reference. Please feel free to change the code below according to your needs.

    using System;
    using System.Linq;
    using Quartz;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Abstractions;
    namespace SitefinityWebApp
        public class HourlyJob : IJob
            public HourlyJob()
            public static void ScheduleJob(IScheduler sc)
                JobDetail job = new JobDetail("HourlyJob", "ExecuteTask", typeof(HourlyJob));
                sc.ScheduleJob(job, TriggerUtils.MakeHourlyTrigger("HourlyTrigger"));
            public void Execute(JobExecutionContext context)
                    Guid roleId = Guid.NewGuid(); //Id of the role you want to remove the user from.
                    RoleManager roleManager = RoleManager.GetManager();
                    UserManager userManager = UserManager.GetManager();
                    var role = roleManager.GetRole(roleId);
                    var users = userManager.GetUsers();
                    foreach (var user in users)
                        if (roleManager.IsUserInRole(user.Id, role.Id) && MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(user.Id,role.Id))
                            roleManager.RemoveUserFromRole(user.Id, role);
                catch (Exception ex)
            private bool MyCustomRuleForDeterminingIfUserHasToBeRemovedFromRole(Guid userId, Guid roleId)
                //Add your custom logic here
                return true;

    and in Global.asax in your Application_Start method, register the Job using the snippet below.

    protected void Application_Start(object sender, EventArgs e)
        HourlyJob.ScheduleJob(new StdSchedulerFactory().GetScheduler());

    2) Inventory tracking is not built into ECommerce module yet. But you can take advantage of a feature we introduced in 5.0 to achieve inventory tracking. Let me explain how this will work - You will
     add a custom field called "InventoryLeft" to the product type and enter the inventory amount there. You will then make use of "Post Purchase hook" which is already present in Ecommerce module to decrease
     the inventory amount when someone purchases a product. When the number is ZERO. You will make the product InActive which will take the product out of listing. As soon as you make a product inactive,
     our new feature in 5.0 called "Out of Stock" will automatically take care of all the existing carts and will warn the users that the product is out of stock and cannot be purchased.  

    Grace Hallwachs
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Boyan
    Boyan avatar
    6 posts
    21 May 2013
    30 May 2013
    Link to this post
    Hi everyone,

    Please note that Sitefinity also offers its own Scheduling API, which you can benefit from. Here's an example from our online documentation on how you can create and run a scheduled task with Sitefinity: http://www.sitefinity.com/documentation/documentationarticles/developers-guide/how-to/how-to-schedule-a-task-to-import-pop3-content

    One importation piece of information that's worth pointing out when working with classes inheriting from ScheduledTask is that you should add a default constructor for the class, and also a
    parametrized one, if needed.

     In addition, please note that the value of the TaskName property should match the name of your class.
3 posts, 0 answered