示例#1
0
        private bool VerifyPayment()
        {
            bool isVerified = false;

            GatewayController controller = new GatewayController(Server.MapPath(ModulePath));
            GatewayInfo gateway = controller.GetGateway(storeInfo.GatewayName);
            PayPalSettings _settings = new PayPalSettings(gateway.GetSettings(PortalId));

            _verificationURL = _settings.UseSandbox ? _sandboxVerificationURL : _settings.VerificationURL;
            _paymentURL = _settings.UseSandbox ? _sandboxPaymentURL : _settings.PaymentURL;

            PayPalIPNParameters ipn = new PayPalIPNParameters(Request.Form);
            if (ipn.IsValid)
            {
                HttpWebRequest request = WebRequest.Create(_verificationURL) as HttpWebRequest;
                if (request != null)
                {
                    request.Method = "POST";
                    request.ContentLength = ipn.PostString.Length;
                    request.ContentType = "application/x-www-form-urlencoded";

                    StreamWriter writer = new StreamWriter(request.GetRequestStream());
                    writer.Write(ipn.PostString);
                    writer.Close();

                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    if (response != null)
                    {
                        StreamReader reader = new StreamReader(response.GetResponseStream());
                        string responseString = reader.ReadToEnd();
                        reader.Close();

                        if (string.Compare(responseString, "VERIFIED", true) == 0)
                        {
                            isVerified = true;
                        }
                        else
                        {
                            //Not verified, possible fraud
                        }
                    }
                }
            }

            return isVerified;
        }
示例#2
0
        /// <summary>
        /// Calculate the tax and shipping cost for the order.
        /// </summary>
        /// <param name="orderInfo"></param>
        private void CalculateTaxandShipping(OrderInfo orderInfo)
        {
            if (orderInfo != null)
            {
                ArrayList cartItems = CurrentCart.GetItems(PortalId);

                //Shipping...
                IShippingProvider shippingProvider = StoreController.GetShippingProvider(ModulePath);
                decimal cartWeight = 0;
                foreach (ItemInfo itemInfo in cartItems)
                {
                    cartWeight += (itemInfo.ProductWeight * itemInfo.Quantity);
                }
                IShippingInfo shippingInfo = shippingProvider.CalculateShippingFee(PortalId, cartWeight);
                if (shippingInfo == null)
                {
                    plhAddressCheckout.Visible = false;
                    plhGateway.Visible = false;
                    plhTaxCheckout.Visible = false;
                    plhShippingCheckout.Visible = false;
                    trRow4.Visible = false;
                    trRow5.Visible = false;
                    trRow6.Visible = false;
                    trRow8.Visible = false;
                    //lblError.Text = "<br/>Sorry, but we don't have any shipping rates for the weight of items in your basket.  Please <a href=\"mailto:" + this.PortalSettings.Email + "\">contact us</a> stating the list of products you'd like to order and we'll get a shipping quote for you.";
                    lblError.Text = String.Format(Localization.GetString("ErrorShippingRates", this.LocalResourceFile), this._storeInfo.DefaultEmailAddress);
                    //lblError.Text = String.Format(Localization.GetString("ErrorShippingRates", this.LocalResourceFile), this.PortalSettings.Email);
                    lblError.Visible = true;
                    return;
                }
                else
                {
                    plhAddressCheckout.Visible = true;
                    plhGateway.Visible = true;
                    plhTaxCheckout.Visible = true;
                    plhShippingCheckout.Visible = true;
                    trRow4.Visible = true;
                    trRow5.Visible = true;
                    trRow6.Visible = true;
                    trRow8.Visible = true;
                    lblError.Visible = false;
                }
                orderInfo.ShippingCost = shippingInfo.Cost;

                //Surcharges...
                try
                {
                    PayPalSettings payPalSettings = new PayPalSettings(StoreData.GatewaySettings);
                    decimal m_FixedSurcharge = payPalSettings.SurchargeFixed;
                    decimal m_PercentSurcharge = payPalSettings.SurchargePercent;
                    orderInfo.ShippingCost = orderInfo.ShippingCost + m_FixedSurcharge + ((orderInfo.OrderTotal + orderInfo.ShippingCost + m_FixedSurcharge) * (m_PercentSurcharge / 100));
                    shippingInfo.Cost = orderInfo.ShippingCost;
                }
                catch
                {
                    //Not paypal
                }

                //Tax...
                ITaxProvider taxProvider = StoreController.GetTaxProvider(ModulePath);

                ITaxInfo taxInfo = taxProvider.CalculateSalesTax(PortalId, cartItems, shippingInfo, ShippingAddress);
                //if (taxInfo.ShowTax)
                //Response.Write("<br>CountryCode0: " + BillingAddress.CountryCode);
                try
                {
                    //Response.Write("<br>CountryCode2: " + shippingControl.BillingAddress.CountryCode);
                    //Response.Write("<br>CountryCode3: " + shippingProvider.BillingAddress.CountryCode);
                }
                catch (Exception ex)
                { }

                if (taxInfo.ShowTax && (BillingAddress.CountryCode == "United Kingdom"))  // ns4u changes: only the UK countries pay VAT
                {
                    trTax.Visible = true;
                    orderInfo.Tax = taxInfo.SalesTax;
                }
                else
                {
                    trTax.Visible = false;
                    orderInfo.Tax = 0;
                }
            }
        }
示例#3
0
        private void SetupPayPalFields(OrderInfo orderInfo)
        {
            IAddressInfo shippingAddress = getShipToAddress(orderInfo.ShippingAddressID);
            IAddressInfo billingAddress = getBillToAddress(orderInfo.BillingAddressID);

            GatewayController controller = new GatewayController(Server.MapPath(ModulePath));
            GatewayInfo gateway = controller.GetGateway(storeInfo.GatewayName);

            PayPalSettings _settings = new PayPalSettings(gateway.GetSettings(PortalId));

            // Ajouté pour la localisation
            CultureInfo ci_enUS = new CultureInfo("en-US");

            //_verificationURL = _settings.UseSandbox ? _sandboxVerificationURL : _liveVerificationURL;
            //_paymentURL = _settings.UseSandbox ? _sandboxPaymentURL : _livePaymentURL;
            _verificationURL = _settings.UseSandbox ? _sandboxVerificationURL : _settings.VerificationURL;
            _paymentURL = _settings.UseSandbox ? _sandboxPaymentURL : _settings.PaymentURL;

            //Set the paypal url as form target
            pnlPayPalTransfer.Visible = true;
            pnlOrderDetails.Visible = false;
            btnGoToPayPal.PostBackUrl = _paymentURL;
            paypalimage2.ImageUrl = _settings.ButtonURL;

            string returnURL = Request.Url + "&PayPalExit=return";
            string cancelURL = Request.Url + "&PayPalExit=cancel";
            string notifyURL = Request.Url + "&PayPalExit=notify";

            AddHiddenField("cmd", "_cart");
            AddHiddenField("upload", "1");
            AddHiddenField("business", _settings.PayPalID);
            AddHiddenField("handling_cart", orderInfo.ShippingCost.ToString("0.00", ci_enUS));
            //AddHiddenField("handling_cart", orderInfo.ShippingCost.ToString("0.00"));
            AddHiddenField("charset", _settings.Charset);
            AddHiddenField("currency_code", _settings.Currency);
            AddHiddenField("invoice", orderInfo.OrderID.ToString());
            AddHiddenField("return", returnURL);
            AddHiddenField("cancel_return", cancelURL);
            AddHiddenField("notify_url", notifyURL);
            AddHiddenField("rm", "2");
            AddHiddenField("lc", _settings.Lc);
            //AddHiddenField("lc", "GB");
            _Message = Localization.GetString("PayPalReturnTo", this.LocalResourceFile);
            AddHiddenField("cbt", string.Format(_Message, PortalSettings.PortalName));
            //AddHiddenField("cbt", "Back to " + PortalSettings.PortalName);

            if (orderInfo.Tax > 0)
            {
                AddHiddenField("tax_cart", orderInfo.Tax.ToString("0.00", ci_enUS));
                //AddHiddenField("tax_cart", orderInfo.Tax.ToString("0.00"));
            }

            //Cart Contents...
            OrderController orderController = new OrderController();
            ArrayList cartItems = orderController.GetOrderDetails(orderInfo.OrderID);
            int itemNumber = 1;
            foreach (OrderDetailsInfo itemInfo in cartItems)
            {
                AddHiddenField("item_name_" + itemNumber.ToString(), itemInfo.ModelName);
                AddHiddenField("quantity_" + itemNumber.ToString(), itemInfo.Quantity.ToString());
                AddHiddenField("amount_" + itemNumber.ToString(), itemInfo.UnitCost.ToString("0.00", ci_enUS));
                //AddHiddenField("amount_" + itemNumber.ToString(), itemInfo.UnitCost.ToString("0.00"));
                itemNumber++;
            }

            //Customer Address...
            AddHiddenField("email", UserInfo.Membership.Email);
            AddHiddenField("first_name", GetFirstName(billingAddress.Name));
            AddHiddenField("last_name", GetSurname(billingAddress.Name));
            AddHiddenField("address1", billingAddress.Address1);
            AddHiddenField("address2", billingAddress.Address2);
            AddHiddenField("city", billingAddress.City);
            AddHiddenField("zip", billingAddress.PostalCode);
            AddHiddenField("country", (billingAddress.CountryCode.Equals("United Kingdom") ? "GB" : billingAddress.CountryCode));

            AddHiddenField("business_cs_email", UserInfo.Membership.Email);
            AddHiddenField("business_address1", billingAddress.Address1);
            AddHiddenField("business_address2", billingAddress.Address2);
            AddHiddenField("business_city", billingAddress.City);
            AddHiddenField("business_zip", billingAddress.PostalCode);
            AddHiddenField("business_country", billingAddress.CountryCode);
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _settings = new PayPalSettings(CheckoutControl.StoreData.GatewaySettings);

            _verificationURL = _settings.UseSandbox ? _sandboxVerificationURL : _settings.VerificationURL;
            _paymentURL = _settings.UseSandbox ? _sandboxPaymentURL : _settings.PaymentURL;

            // Do we have any special handling?
            PayPalNavigation nav = new PayPalNavigation(Request.QueryString);
            switch (nav.PayPalExit.ToUpper())
            {
                case "CANCEL":
                {
                    invokePaymentCancelled();
                    CheckoutControl.Hide();
                    pnlProceedToPayPal.Visible = false;
                    return;
                }
                case "RETURN":
                case "NOTIFY":
                {
                    // Collect data, invoke success
                    if (VerifyPayment())
                    {
                        //Set order status to "Paid"...
                        int orderID;
                        if (!Int32.TryParse(Request.Form["invoice"], out orderID))
                        {
                            VerificationFailed();
                            return;
                        }

                        CheckoutControl.OrderInfo = UpdateOrderStatus(orderID, OrderInfo.OrderStatusList.Paid);

                        invokePaymentSucceeded();
                        CheckoutControl.Hide();
                        pnlProceedToPayPal.Visible = false;
                        return;
                    }
                    else
                    {
                        VerificationFailed();
                        return;
                    }
                }
            }

            if (nav.PayPalExit.Length > 0)
            {
                //If the PayPalExit is anything else with length > 0, then don't do any processing
                HttpContext.Current.Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(PortalSettings.ActiveTab.TabID), false);
                return;
            }

            // Continue with display of payment control...
            if ((_settings == null) || (!_settings.IsValid()))
            {
                lblError.Text = Localization.GetString("GatewayNotConfigured", this.LocalResourceFile);
                lblError.Visible = true;
                imageButton1.Visible = false;
                pnlProceedToPayPal.Visible = false;
                pnlContinue.Visible = false;
                return;
            }
            else
            {
                _Message = Localization.GetString("lblConfirmMessage", this.LocalResourceFile);
                lblConfirmMessage.Text = string.Format(_Message, PortalSettings.PortalName);
                _Message = Localization.GetString("paypalimage", this.LocalResourceFile);
                paypalimage.AlternateText = _Message;
                imageButton1.AlternateText = _Message;

                lblError.Text = string.Empty;
                lblError.Visible = false;
                //imageButton1.Visible = true;
                imageButton1.ImageUrl = _settings.ButtonURL;
                paypalimage.ImageUrl = _settings.ButtonURL;
                paypalimage2.ImageUrl = _settings.ButtonURL;
            }
        }