Пример #1
0
 /// <summary>
 /// Handles the Click event of the btnManualTransaction control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void btnManualTransaction_Click(object sender, EventArgs e)
 {
     try {
     Order order = new Order(orderId);
     paymentService = new PaymentService();
     if (order.PaymentMethod == "PayPal" && paymentService.PaymentServiceSettings.ProviderSettingsCollection.Find(provider => provider.GetType().Name.Contains("PayPalStandardPaymentProvider")) != null) {
       OrderController.CommitStandardTransaction(order, txtTransactionId.Text.Trim(), order.Total);
     }
     SetOrderStatus(order.OrderStatusDescriptorId.ToString());
     base.MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblManualTransactionSucceeded"));
       }
       catch (Exception ex) {
     Logger.Error(typeof(actions).Name + ".btnManualTransaction_Click", ex);
     base.MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
       }
 }
Пример #2
0
        /// <summary>
        /// Charges the specified order.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="userName">Name of the user.</param>
        /// <returns></returns>
        public static Transaction Charge(Order order, string userName)
        {
            //update the order with IP
              order.IPAddress = HttpContext.Current.Request.UserHostAddress;
              PaymentService paymentService = new PaymentService();
              Transaction transaction = paymentService.Charge(order);
              order.OrderStatusDescriptorId = (int)OrderStatus.ReceivedPaymentProcessingOrder;
              order.OrderTypeId = (int)OrderType.Purchase;
              order.Save(userName);
              Guid userGuid = new Guid(Membership.GetUser(userName).ProviderUserKey.ToString());
              try {
            //Add an OrderNote
            OrderNote orderNote = new OrderNote();
            orderNote.OrderId = order.OrderId;
            orderNote.Note = Strings.ResourceManager.GetString(ORDER_CHARGED);
            orderNote.Save(userName);
            Sku sku;
            DownloadCollection downloadCollection;
            DownloadAccessControlCollection downloadAccessControlCollection;
            DownloadAccessControl downloadAccessControl;
            foreach (OrderItem orderItem in order.OrderItemCollection) {
              //Adjust the Inventory
              sku = new Sku(SKU, orderItem.Sku);
              sku.Inventory = sku.Inventory - orderItem.Quantity;
              sku.Save(SYSTEM);
              ProductCache.RemoveSKUFromCache(orderItem.Sku);
              //Add access control for orderitems
              downloadCollection = new ProductController().FetchAssociatedDownloadsByProductIdAndForPurchase(orderItem.ProductId);
              if (downloadCollection.Count > 0) {
            foreach (Download download in downloadCollection) {
              Query query = new Query(DownloadAccessControl.Schema).
                AddWhere(DownloadAccessControl.Columns.UserId, Comparison.Equals, userGuid).
                AddWhere(DownloadAccessControl.Columns.DownloadId, Comparison.Equals, download.DownloadId);
              downloadAccessControlCollection = new DownloadAccessControlController().FetchByQuery(query);
              if (downloadAccessControlCollection.Count == 0) {
                downloadAccessControl = new DownloadAccessControl();
                downloadAccessControl.DownloadId = download.DownloadId;
                downloadAccessControl.UserId = userGuid;
                downloadAccessControl.Save(SYSTEM);
              }
            }
              }
            }

            //Send out the messages
            //Send these last in case something happens with the email
            MessageService messageService = new MessageService();
            messageService.SendOrderReceivedNotificationToCustomer(order);
            messageService.SendOrderReceivedNotificationToMerchant(order);
              }
              catch (Exception ex) {
            //swallow the exception here because the transaction is saved
            //and, while this is an inconvenience, it's not critical
            Logger.Error(typeof(OrderController).Name + ".Charge", ex);
              }
              return transaction;
        }
Пример #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"></see> event to initialize the page.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            if (Master.SiteSettings.LoginRequirement == LoginRequirement.Checkout) {
            if (!User.Identity.IsAuthenticated) {
              Response.Redirect("login.aspx?ReturnUrl=/checkout.aspx", true);
            }
              }

              PaymentService paymentService = new PaymentService();
              if (paymentService.PaymentServiceSettings.DefaultProvider == "PayPalStandardPaymentProvider") {
            Response.Redirect("~/paypalcheckout.aspx", true);
              }

              //Keep these here - the Accordion ViewState is funky and requires things to be set early
              Label lblBillingInformation = acCheckout.Panes[0].FindControl("lblBillingInformation") as Label;
              Label lblShippingInformation = acCheckout.Panes[1].FindControl("lblShippingInformation") as Label;
              Label lblShippingMethod = acCheckout.Panes[2].FindControl("lblShippingMethod") as Label;
              Label lblCouponInformation = acCheckout.Panes[3].FindControl("lblCouponInformation") as Label;
              Label lblPaymentInformation = acCheckout.Panes[4].FindControl("lblPaymentInformation") as Label;
              Label lblOrderReview = acCheckout.Panes[5].FindControl("lblOrderReview") as Label;

              //See if there are any coupons in the system
              //If not, then don't display the coupon stuff
              couponCollection = new CouponController().FetchAll();
              if (couponCollection.Count == 0) {
            hasCoupons = false;
            acpCoupon.Visible = false;
            pnlCouponInformationDisplayTitle.Visible = false;
            pnlCouponInformationDisplay.Visible = false;
              }

              shippingService = new ShippingService();
              if (!shippingService.ShippingServiceSettings.UseShipping) {
            acCheckout.Panes[1].Visible = false;
            acCheckout.Panes[2].Visible = false;
            pnlShippingAddressDisplayTitle.Visible = false;
            pnlShippingAddressDisplay.Visible = false;
            pnlShippingMethodDisplayTitle.Visible = false;
            pnlShippingMethodDisplay.Visible = false;
              }

              //Keep these here - the Accordion ViewState is funky and requires things to be set early
              order = new OrderController().FetchOrder(WebUtility.GetUserName());

              #region PayPal Express Checkout Logic

              if (!string.IsNullOrEmpty(order.PaymentMethod)) {
            if (order.PaymentMethod == "PayPal") {
              string token = Utility.GetParameter("token");
              if (!string.IsNullOrEmpty(token)) {
            pnlCreditCardInformation.Visible = false;
            pnlCreditCardInfo.Visible = false;
            lblCreditCardType.Text = order.PaymentMethod;
            ddlCreditCardType.SelectedValue = "4";
            ddlCreditCardType.Enabled = false;
            PayPalPayer payPalPayer = OrderController.GetExpressCheckout(token);
            if (order.BillingAddress == null) {//Then they are coming in from the cart.aspx ExpressCheckout button
              //copy the PayPalPayer ShippingAddress and then flag it as a BillingAddress
              Address billingAddress = new Address(payPalPayer.ShippingAddress);
              billingAddress.AddressType = AddressType.BillingAddress;
              Address duplicateBillingAddress = WebProfile.Current.AddressCollection.Find(
                addressToFind =>
                addressToFind.ToString() == billingAddress.ToString() &&
                addressToFind.AddressType == AddressType.BillingAddress);
              if (duplicateBillingAddress == null) {
                WebProfile.Current.AddressCollection.Add(billingAddress);
                WebProfile.Current.Save();
              }
              order.BillToAddress = payPalPayer.ShippingAddress.ToXml();
            }
            if (!payPalPayer.ShippingAddress.Equals(order.ShippingAddress)) {
              Address shippingAddress = new Address(payPalPayer.ShippingAddress);
              shippingAddress.AddressType = AddressType.ShippingAddress;
              Address duplicateShippingAddress = WebProfile.Current.AddressCollection.Find(
                  addressToFind =>
                  addressToFind.ToString() == shippingAddress.ToString() &&
                  addressToFind.AddressType == AddressType.ShippingAddress);
              if (duplicateShippingAddress == null) {
                WebProfile.Current.AddressCollection.Add(shippingAddress);
                WebProfile.Current.Save();
              }
              order.ShipToAddress = payPalPayer.ShippingAddress.ToXml();
            }
            if (order.ExtendedProperties.ContainsKey(PAYPAL_PAYER_ID)) {
              order.ExtendedProperties.Remove(PAYPAL_PAYER_ID);
            }
            if (order.ExtendedProperties.ContainsKey(PAYPAL_TOKEN)) {
              order.ExtendedProperties.Remove(PAYPAL_TOKEN);
            }
            order.ExtendedProperties.Add(PAYPAL_PAYER_ID, payPalPayer.PayPalPayerId);
            order.ExtendedProperties.Add(PAYPAL_TOKEN, payPalPayer.PayPalToken);
            order.AdditionalProperties = order.ExtendedProperties.ToXml();
            order.Save(WebUtility.GetUserName());
            OrderController.CalculateTax(WebUtility.GetUserName());
            order = new OrderController().FetchOrder(WebUtility.GetUserName());
              }
            }
              }

              #endregion

              if (!Page.IsPostBack) {
            SetBillingAddressDisplay();

            SetShippingAddressDisplay();

            SetShippingMethodDisplay();

            SetCouponDisplay();

            SetPaymentMethodDisplay(-1, order.CreditCardNumber, DateTime.MinValue);
              }
              base.OnInit(e);
        }
Пример #4
0
 /// <summary>
 /// Synchronizes the specified args.
 /// </summary>
 /// <param name="args">The args.</param>
 /// <returns></returns>
 public static string Synchronize(params object[] args)
 {
     PaymentService paymentService = new PaymentService();
       string content = string.Format("&cmd=_notify-synch&tx={0}&at=", args[0]);
       string response = paymentService.Synchronize(content);
       return response;
 }
Пример #5
0
 /// <summary>
 /// Verifies the specified args.
 /// </summary>
 /// <param name="args">The args.</param>
 /// <returns></returns>
 public static string Verify(params object[] args)
 {
     PaymentService paymentService = new PaymentService();
       string content = string.Format("{0}&cmd=_notify-validate", args[0]);
       Logger.Information(string.Format("{0}::{1}", "VERIFY", content));
       string response = paymentService.Synchronize(content);
       return response;
 }
Пример #6
0
 /// <summary>
 /// Sets the express checkout.
 /// </summary>
 /// <param name="order">The order.</param>
 /// <param name="returnUrl">The return URL.</param>
 /// <param name="cancelUrl">The cancel URL.</param>
 /// <param name="authorizeOnly">if set to <c>true</c> [authorize only].</param>
 /// <returns></returns>
 public static string SetExpressCheckout(Order order, string returnUrl, string cancelUrl, bool authorizeOnly)
 {
     PaymentService paymentService = new PaymentService();
       string token = paymentService.SetExpressCheckout(order, returnUrl, cancelUrl, authorizeOnly);
       return token;
 }
Пример #7
0
 /// <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);
 }
Пример #8
0
 /// <summary>
 /// Gets the express checkout.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <returns></returns>
 public static PayPalPayer GetExpressCheckout(string token)
 {
     PaymentService paymentService = new PaymentService();
       PayPalPayer payPalPayer = paymentService.GetExpressCheckoutDetails(token);
       return payPalPayer;
 }
Пример #9
0
        /// <summary>
        /// Does the express checkout.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="authorizeOnly">if set to <c>true</c> [authorize only].</param>
        /// <param name="userName">Name of the user.</param>
        /// <returns></returns>
        public static Transaction DoExpressCheckout(Order order, bool authorizeOnly, string userName)
        {
            PaymentService paymentService = new PaymentService();
              Transaction transaction = paymentService.DoExpressCheckout(order, authorizeOnly);
              order.OrderStatusDescriptorId = (int)OrderStatus.ReceivedPaymentProcessingOrder;
              order.Save(userName);

              try {
            //Adjust the Inventory
            Sku sku;
            foreach (OrderItem orderItem in order.OrderItemCollection) {
              sku = new Sku(SKU, orderItem.Sku);
              sku.Inventory = sku.Inventory - orderItem.Quantity;
              sku.Save(SYSTEM);
              ProductCache.RemoveSKUFromCache(orderItem.Sku);
            }
            //Send out the messages
            MessageService messageService = new MessageService();
            messageService.SendOrderReceivedNotificationToCustomer(order);
            messageService.SendOrderReceivedNotificationToMerchant(order);
              }
              catch (Exception ex) {
            //swallow the exception here because the transaction is saved
            //and, while this is an inconvenience, it's not critical
            Logger.Error(typeof(OrderController).Name + ".DoExpressCheckout", ex);
              }
              return transaction;
        }
Пример #10
0
 /// <summary>
 /// Creates the cart URL.
 /// </summary>
 /// <param name="order">The order.</param>
 /// <param name="returnUrl">The return URL.</param>
 /// <param name="cancelUrl">The cancel URL.</param>
 /// <returns></returns>
 public static string CreateCartUrl(Order order, string returnUrl, string cancelUrl, string notifyUrl)
 {
     PaymentService paymentService = new PaymentService();
       string url = paymentService.CreateCartUrl(order, returnUrl, cancelUrl, notifyUrl);
       return url;
 }