//Need to create an order record without going through any gateway/payment or other recurring steps - the order has already been changed by PayPal. public void ProcessPPECRecurringOrder(int OriginalOrderNumber) { Order originalOrder = new Order(OriginalOrderNumber); Customer recurringCustomer = new Customer(originalOrder.CustomerID); ShoppingCart recurringCart = new ShoppingCart(recurringCustomer.SkinID, recurringCustomer, CartTypeEnum.RecurringCart, OriginalOrderNumber, false); Address billingAddress = new Address(); billingAddress.LoadByCustomer(recurringCustomer.CustomerID, recurringCustomer.PrimaryBillingAddressID, AddressTypes.Billing); billingAddress.PaymentMethodLastUsed = AppLogic.ro_PMPayPalExpress; int newOrderNumber = Gateway.CreateOrderRecord(recurringCart, 0, billingAddress); //Update the new order with some recurring information String orderUpdateSql = "UPDATE Orders SET TransactionState = @TransactionState, IsNew = @IsNew, ParentOrderNumber = @ParentOrderNumber, Notes = @Notes WHERE OrderNumber = @OrderNumber"; SqlParameter[] orderUpdateParams = { new SqlParameter("@OrderNumber", newOrderNumber), new SqlParameter("@TransactionState", AppLogic.ro_TXStateCaptured), new SqlParameter("@IsNew", true), new SqlParameter("@ParentOrderNumber", originalOrder), new SqlParameter("@Notes", "This order was created automatically based on a PayPal Express Checkout notification that the recurring subscription had been charged.") }; DB.ExecuteSQL(orderUpdateSql, orderUpdateParams); //Then update the ShoppingCart record, which is left behind for next time CartItem firstRecurringCartItem = recurringCart.CartItems[0]; //Safe to do as we currently only support one recurring schedule per order DateTime nextRecurringDate = firstRecurringCartItem.NextRecurringShipDate; if (nextRecurringDate.Equals(System.DateTime.MinValue)) { // safety check: nextRecurringDate = System.DateTime.Now; } switch (firstRecurringCartItem.RecurringIntervalType) { case DateIntervalTypeEnum.Day: nextRecurringDate = nextRecurringDate.AddDays(firstRecurringCartItem.RecurringInterval); break; case DateIntervalTypeEnum.Week: nextRecurringDate = nextRecurringDate.AddDays(7 * firstRecurringCartItem.RecurringInterval); break; case DateIntervalTypeEnum.Month: nextRecurringDate = nextRecurringDate.AddMonths(firstRecurringCartItem.RecurringInterval); break; case DateIntervalTypeEnum.Year: nextRecurringDate = nextRecurringDate.AddYears(firstRecurringCartItem.RecurringInterval); break; case DateIntervalTypeEnum.NumberOfDays: nextRecurringDate = nextRecurringDate.AddDays(firstRecurringCartItem.RecurringInterval); break; case DateIntervalTypeEnum.Weekly: nextRecurringDate = nextRecurringDate.AddDays(7); break; case DateIntervalTypeEnum.BiWeekly: nextRecurringDate = nextRecurringDate.AddDays(14); break; case DateIntervalTypeEnum.EveryFourWeeks: nextRecurringDate = nextRecurringDate.AddDays(28); break; case DateIntervalTypeEnum.Monthly: nextRecurringDate = nextRecurringDate.AddMonths(1); break; case DateIntervalTypeEnum.Quarterly: nextRecurringDate = nextRecurringDate.AddMonths(3); break; case DateIntervalTypeEnum.SemiYearly: nextRecurringDate = nextRecurringDate.AddMonths(6); break; case DateIntervalTypeEnum.Yearly: nextRecurringDate = nextRecurringDate.AddYears(1); break; default: //Default to monthly like we do elsewhere nextRecurringDate = nextRecurringDate.AddMonths(1); break; } String cartUpdateSql = "UPDATE ShoppingCart SET NextRecurringShipDate = @NextRecurringShipDate WHERE OriginalRecurringOrderNumber = @OriginalRecurringOrderNumber AND CartType = @CartType"; SqlParameter[] cartUpdateParams = { new SqlParameter("@OriginalRecurringOrderNumber", OriginalOrderNumber), new SqlParameter("@NextRecurringShipDate", nextRecurringDate), new SqlParameter("@CartType", ((int)CartTypeEnum.RecurringCart).ToString()) }; DB.ExecuteSQL(cartUpdateSql, cartUpdateParams); }