Custom checkout process with recurring transactions

Posted by Community Admin on 04-Aug-2018 20:23

Custom checkout process with recurring transactions

All Replies

Posted by Community Admin on 13-Jul-2012 00:00

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;
15. 
16.    foreach (CartDetail myLineItem in order.Details)
17.        // get product object based off of line item id
18.        myProduct = myCatManager.GetProduct(myLineItem.ProductId);
19. 
20.        // find the product type
21.        productType = TypeResolutionService.ResolveType(myProduct.GetType().FullName);
22.        myDynamicProduct = dynamicModuleManager.GetDataItem(productType, myLineItem.ProductId);
23. 
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.        
28. 
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.    
35. 
36.    return bSuccess;
37.

Posted by Community Admin on 19-Jul-2012 00:00

Hello,

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"));
            sc.Start();
        
  
        public void Execute(JobExecutionContext context)
        
            try
            
                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)
            
                Log.Write(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.  

Regards,
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

Posted by Community Admin on 30-May-2013 00:00

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: www.sitefinity.com/.../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.

This thread is closed