Esempio n. 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;
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void loadGatewayAdmin(string gatewayName)
        {
            // TODO: We may want to use caching here

            plhGateway.Controls.Clear();

            GatewayController controller = new GatewayController(Server.MapPath(ModulePath));
            GatewayInfo gateway = controller.GetGateway(gatewayName);
            if (gateway != null)
            {
                string controlPath = gateway.GatewayPath + "\\" + gateway.AdminControl;
                if (File.Exists(controlPath))
                {
                    controlPath = controlPath.Replace(Server.MapPath(ModulePath), ModulePath);

                    gatewayControl = (StoreControlBase)LoadControl(controlPath);
                    gatewayControl.EnableViewState = true;
                    gatewayControl.ParentControl = this as PortalModuleBase;
                    gatewayControl.DataSource = gateway.GetSettings(PortalId);

                    plhGateway.Controls.Add(gatewayControl);
                }
                else
                {
                    LiteralControl error = new LiteralControl("<span class=\"NormalRed\">" + Localization.GetString("CouldNotFind", this.LocalResourceFile) + " " + controlPath + ".</span>");
                    plhGateway.Controls.Add(error);
                }
            }
            else
            {
                LiteralControl error = new LiteralControl("<span class=\"NormalRed\">" + Localization.GetString("GatewayNotSelected", this.LocalResourceFile) + "</span>");
                plhGateway.Controls.Add(error);
            }
        }
Esempio n. 4
0
        private void loadGateways(string gatewayName)
        {
            GatewayController controller = new GatewayController(Server.MapPath(ModulePath));
            lstGateway.DataTextField = "GatewayName";
            lstGateway.DataValueField = "GatewayPath";
            lstGateway.DataSource = controller.GetGateways();
            lstGateway.DataBind();

            lstGateway.Items.Insert(0, new ListItem(Localization.GetString("EmptyComboValue", this.LocalResourceFile), Null.NullString));

            if (gatewayName != Null.NullString)
            {
                try
                {
                    GatewayInfo gateway = controller.GetGateway(gatewayName);
                    lstGateway.SelectedValue = gateway.GatewayPath;
                }
                catch{}
            }
        }
Esempio n. 5
0
        private void loadPaymentControl()
        {
            //StoreController storeController = new StoreController();
            //StoreInfo storeInfo = storeController.GetStoreInfo(PortalId);

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

            if (gateway != null)
            {
                string controlPath = gateway.GatewayPath + "\\" + gateway.PaymentControl;
                if (File.Exists(controlPath))
                {
                    controlPath = controlPath.Replace(Server.MapPath(ModulePath), ModulePath);

                    paymentControl = (PaymentControlBase)LoadControl(controlPath);
                    paymentControl.ID = "ctlGateway";
                    paymentControl.ParentControl = this as PortalModuleBase;
                    //paymentControl.StoreData = storeInfo;
                    paymentControl.CheckoutControl = this as ICheckoutControl;

                    paymentControl.EnableViewState = true;
                    paymentControl.PaymentSucceeded += new EventHandler(paymentControl_PaymentSucceeded);
                    paymentControl.PaymentCancelled += new EventHandler(paymentControl_PaymentCancelled);
                    paymentControl.PaymentFailed += new EventHandler(paymentControl_PaymentFailed);

                    plhGateway.Controls.Clear();
                    plhGateway.Controls.Add(paymentControl);
                }
                else
                {
                    //LiteralControl error = new LiteralControl("<span class=\"NormalRed\">Could not find " + controlPath + ".</span>");
                    LiteralControl error = new LiteralControl("<span class=\"NormalRed\">" + Localization.GetString("ErrorCouldNotFind", this.LocalResourceFile) + " " + controlPath + ".</span>");

                    plhGateway.Controls.Clear();
                    plhGateway.Controls.Add(error);
                }
            }
            else
            {
                    //LiteralControl error = new LiteralControl("<span class=\"NormalRed\">A Payment option has not be setup. Please contact the administrator to setup a payment option.</span>");
                    LiteralControl error = new LiteralControl("<span class=\"NormalRed\">" + Localization.GetString("ErrorPaymentOption", this.LocalResourceFile) + "</span>");

                    plhGateway.Controls.Clear();
                    plhGateway.Controls.Add(error);
            }
        }