/// <summary>
        /// Refunds the specified transaction.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        /// <param name="refundedOrder">The refunded order.</param>
        /// <param name="userName">Name of the user.</param>
        public static void RefundStandard(Transaction transaction, Order refundedOrder, string userName)
        {
            Order order = new Order(transaction.OrderId);
              Transaction refundTransaction = new Transaction();
              //refundTransaction.OrderId = transaction.OrderId;
              refundTransaction.TransactionTypeDescriptorId = (int)TransactionType.Refund;
              refundTransaction.PaymentMethod = PAYPAL;
              refundTransaction.GatewayName = PAYPAL_STANDARD;
              refundTransaction.GatewayResponse = SUCCESS;
              refundTransaction.GatewayTransactionId = CoreUtility.GenerateRandomString(16);
              refundTransaction.GrossAmount = refundedOrder.Total;
              refundTransaction.NetAmount = 0.00M;
              refundTransaction.FeeAmount = 0.00M;
              refundTransaction.TransactionDate = DateTime.Now;
              //refundTransaction.Save(userName);
              refundedOrder.Save(userName);

              //set the orderid for the refund
              foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) {
            orderItem.OrderId = refundedOrder.OrderId;
              }
              refundedOrder.OrderItemCollection.SaveAll(userName);
              //set the orderId to the refunded orderId
              refundTransaction.OrderId = refundedOrder.OrderId;
              refundTransaction.Save(userName);
              Guid userGuid = new Guid(Membership.GetUser(order.UserName).ProviderUserKey.ToString());
              DownloadCollection downloadCollection;
              foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) {
            //put the stock back
            Sku sku = new Sku(Sku.Columns.SkuX, orderItem.Sku);
            sku.Inventory = sku.Inventory + orderItem.Quantity;
            sku.Save(userName);
            ProductCache.RemoveSKUFromCache(orderItem.Sku);
            //remove the access control
            downloadCollection = new ProductController().FetchAssociatedDownloadsByProductIdAndForPurchase(orderItem.ProductId);
            if (downloadCollection.Count > 0) {
              foreach (Download download in downloadCollection) {
            new DownloadAccessControlController().Delete(userGuid, download.DownloadId);
              }
            }

              }
              if(refundedOrder.Total == order.Total) {
            order.OrderStatusDescriptorId = (int)OrderStatus.OrderFullyRefunded;
              }
              else {
            order.OrderStatusDescriptorId = (int)OrderStatus.OrderPartiallyRefunded;
              }
              order.Save(userName);
              //Add an OrderNote
              OrderNote orderNote = new OrderNote();
              orderNote.OrderId = order.OrderId;
              orderNote.Note = Strings.ResourceManager.GetString(ORDER_REFUNDED);
              orderNote.Save(userName);
              //send off the notifications
              MessageService messageService = new MessageService();
              messageService.SendOrderRefundToCustomer(refundedOrder);
        }
 /// <summary>
 /// Refunds the specified transaction.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 /// <param name="refundedOrder">The order the refund should be applied to.</param>
 /// <param name="userName">Name of the user.</param>
 public static void Refund(Transaction transaction, Order refundedOrder, string userName)
 {
     Order order = new Order(transaction.OrderId);
       PaymentService paymentService = new PaymentService();
       Transaction refundTransaction = paymentService.Refund(transaction, refundedOrder);
       refundedOrder.Save(userName);
       //set the orderid for the refund
       foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) {
     orderItem.OrderId = refundedOrder.OrderId;
       }
       refundedOrder.OrderItemCollection.SaveAll(userName);
       //set the orderId to the refunded orderId
       refundTransaction.OrderId = refundedOrder.OrderId;
       refundTransaction.Save(userName);
       Guid userGuid = new Guid(Membership.GetUser(order.UserName).ProviderUserKey.ToString());
       foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) {
     new Product(orderItem.ProductId);
     //put the stock back
     Sku sku = new Sku(Sku.Columns.SkuX, orderItem.Sku);
     sku.Inventory = sku.Inventory + orderItem.Quantity;
     sku.Save(userName);
     ProductCache.RemoveSKUFromCache(orderItem.Sku);
     //remove the access control
     DownloadCollection downloadCollection = new ProductController().FetchAssociatedDownloadsByProductIdAndForPurchase(orderItem.ProductId);
     if (downloadCollection.Count > 0) {
       foreach (Download download in downloadCollection) {
     new DownloadAccessControlController().Delete(userGuid, download.DownloadId);
       }
     }
       }
       if(refundedOrder.Total == order.Total) {
     order.OrderStatusDescriptorId = (int)OrderStatus.OrderFullyRefunded;
       }
       else {
     order.OrderStatusDescriptorId = (int)OrderStatus.OrderPartiallyRefunded;
       }
       order.Save(userName);
       //Add an OrderNote
       OrderNote orderNote = new OrderNote();
       orderNote.OrderId = order.OrderId;
       orderNote.Note = Strings.ResourceManager.GetString(ORDER_REFUNDED);
       orderNote.Save(userName);
       //send off the notifications
       MessageService messageService = new MessageService();
       messageService.SendOrderRefundToCustomer(refundedOrder);
 }