예제 #1
0
        // Methods
        public IPaymentRequest GetPaymentRequest(PaymentRequestArgs args)
        {
            var request = new POSTPaymentRequest();

            var Request = HttpContext.Current.Request;
            var customer = Exigo.OData().Customers.Where(c => c.CustomerID == Order.CustomerID).FirstOrDefault();
            var urlhelper = new UrlHelper(Request.RequestContext);
            //var encryptor = new MD5CryptoServiceProvider();

            var url = GlobalSettings.Merchants.Ingenico.Address;
            var referenceCode = Order.OrderID.ToString() + "-" + args.Attempt;
            var orderToken = Security.Encrypt(new { OrderID = Order.OrderID, CustomerID = Order.CustomerID });
            var email = customer.Email;
            var tax = Order.TaxTotal;
            var language = GlobalUtilities.GetSelectedLanguage().Replace("-", "_");
            var recipient = Order.Recipient;
            var addressDisplay = (recipient.Address2.IsEmpty()) ? recipient.Address1 : recipient.Address1 + " " + recipient.Address2;

            // Format and set up our URL parameters
            var returnUrl = args.ReturnUrl;
            returnUrl += (returnUrl.Contains("?") ? "&" : "?") + "_p=" + ID;
            returnUrl += "&" + "_cid=" + Order.CustomerID;
            returnUrl += "&" + "token=" + orderToken;

            // We run our web alias logic below. If we are in a replicated site setting, we need to ensure the web alias is inserted correctly in the return urls
            var appPath = (args.RequiresWebAlias) ?  "/{0}/".FormatWith(args.WebAlias) : "/";
            var fullReturnUrl = FormatReturnURL(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, appPath, returnUrl);

            var successUrl = fullReturnUrl + "&paymentstatus=success";
            var errorUrl = fullReturnUrl + "&paymentstatus=error";
            var declineUrl = fullReturnUrl + "&paymentstatus=decline";
            var cancelUrl = fullReturnUrl + "&paymentstatus=cancel";
            var homeView = (args.RequiresWebAlias) ? urlhelper.Action("index", "home", new { webalias = args.WebAlias }) : urlhelper.Action("index", "dashboard");
            var homeUrl = FormatReturnURL(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Request.ApplicationPath, homeView.TrimStart('/'));
            var shopView = (args.RequiresWebAlias) ? urlhelper.Action("itemlist", "shopping", new { webalias = args.WebAlias }) : urlhelper.Action("itemlist", "shopping");
            var shopUrl = FormatReturnURL(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Request.ApplicationPath, shopView.TrimStart('/'));

            var shaPassPhrase = HashSalt;

            var data = new Dictionary<string, object>()
            {
                {"PSPID", "WINBV" },
                {"ORDERID", "WinExigoOrder" + Order.OrderID.ToString() },
                {"AMOUNT", (Order.Total * 100).ToString("0") },
                {"CURRENCY", CurrencyCodes.Euro },
                {"LANGUAGE", language },
                // optional customer details, highly recommended for fraud prevention
                {"CN", recipient.FirstName + " " + recipient.LastName },
                {"EMAIL", recipient.Email },
                {"OWNERADDRESS", addressDisplay },
                {"OWNERCTY", recipient.City },
                {"OWNERTELNO", recipient.Phone },
                {"OWNERZIP", recipient.Zip },
                {"COM", "Exigo Order {0}".FormatWith(Order.OrderID) },
                //<!-- link to your website: see Default reaction -->
                {"HOMEURL", homeUrl },
                {"CATALOGURL", shopUrl },
                //<!-- post payment redirection: see Redirection depending on the payment result -->
                {"ACCEPTURL", successUrl },
                {"DECLINEURL", declineUrl },
                {"EXCEPTIONURL", errorUrl },
                {"CANCELURL", cancelUrl }
            };

            var hashedData = GetHashedData(data, shaPassPhrase);

            data.Add("SHASIGN", hashedData);

            request.Method = PaymentRequestMethod.Post;
            request.RequestUrl = url;
            request.RequestForm = FormHelper.GetSelfPostingFormHtml(url, data);

            return request;
        }
예제 #2
0
        // Prepares Form Data for Posting to Payment Provider - Alan C, 25 June 2015
        public IPaymentRequest GetPaymentRequest(PaymentRequestArgs args)
        {
            // We will populate form data from the View and from static settings into this Strongly Typed Model
            // Which will collect our Variables and then assign them to a Dictionary of Form Properties expected by our Payment Providers
            // - Alan C 25 June 2015
            var postRequest = new POSTPaymentRequest(); // New instance of our Model for HTTP POST Form Data to 3rd Party Payment Providers - Location:

            #region Variables for Request Data

            var Request = HttpContext.Current.Request; // Access current URI information for Referring Page
            var customer = Exigo.OData().Customers.Where(c => c.CustomerID == Order.CustomerID).FirstOrDefault(); // Retrieve data for Customer placing the order
            var urlhelper = new UrlHelper(Request.RequestContext); // Access helper classes and methods for constructing dynamic URLs into the Absolute paths required by the Payment Provider
            //var encryptor = new MD5CryptoServiceProvider(); - Not being used at the moment - Alan C, 25 June 2015

            var url = GlobalSettings.Merchants.Ingenico.Address; // Switch to Test URL for UAT Sites and Production URL for Live Sites
            var referenceCode = Order.OrderID.ToString() + "-" + args.Attempt;
            var orderToken = Security.Encrypt(new { OrderID = Order.OrderID, CustomerID = Order.CustomerID });
            var email = customer.Email;
            var tax = Order.TaxTotal;
            var language = GlobalUtilities.GetSelectedLanguage().Replace("-", "_");
            var recipient = Order.Recipient;
            var addressDisplay = (recipient.Address2.IsEmpty()) ? recipient.Address1 : recipient.Address1 + " " + recipient.Address2;
            var phone = customer.Phone;

            // Set default payment method to iDeal to bypass payment method list screen on Ingenico
            var paymentMethod = "iDEAL";

            // Format and set up our parameters for the Return URL to which Payment Provider will return their Response
            var returnUrl = args.ReturnUrl;
            returnUrl += (returnUrl.Contains("?") ? "&" : "?") + "_p=" + ID; // Adds Payment Provider identifier to the Return URL
            returnUrl += "&" + "_cid=" + Order.CustomerID;// Adds CustomerID to the Return URL
            returnUrl += "&" + "_oID=" + Order.OrderID;
            returnUrl += "&" + "token=" + orderToken; // Adds tokenized status / response data from Payment Provider to the Return URL

            // We run our web alias logic below. If we are in a replicated site setting, we need to ensure the web alias is inserted correctly in the return urls
            var appPath = (args.RequiresWebAlias) ? "/{0}/".FormatWith(args.WebAlias) : "/";
            var fullReturnUrl = FormatReturnURL(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, appPath, returnUrl);

            var successUrl = fullReturnUrl + "&ps=success";
            var errorUrl = fullReturnUrl + "&ps=error";
            var declineUrl = fullReturnUrl + "&ps=decline";
            var cancelUrl = fullReturnUrl + "&ps=cancel";
            var homeView = (args.RequiresWebAlias) ? urlhelper.Action("index", "home", new { webalias = args.WebAlias }) : urlhelper.Action("index", "dashboard");
            var homeUrl = FormatReturnURL(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Request.ApplicationPath, homeView.TrimStart('/'));
            var shopView = (args.RequiresWebAlias) ? urlhelper.Action("itemlist", "shopping", new { webalias = args.WebAlias }) : urlhelper.Action("itemlist", "shopping");
            var shopUrl = FormatReturnURL(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Request.ApplicationPath, shopView.TrimStart('/'));

            var shaPassPhrase = HashSalt;

            var address = (args.BillingAddress != null) ? args.BillingAddress : new Address();
            //var address = (args.BillingAddress != null) ? args.BillingAddress : recipient;

            // Establish a variable for UTF8 encoding so we can properly encode necessary fields - Alan C, 25 June 2015
            var utf8 = Encoding.UTF8;

            // Encode the Customer's name to allow for the special characters and accents of Unicode that appear in European Names - Alan C, 25 June 2015
            byte[] utfBillingName = utf8.GetBytes(args.BillingName);

            //string stringName = utf8.GetString(utfBillingName); - Not being used - Alan C, 25 June 2015

            #endregion

            #region Populate Data into Form Properties

            // Establish Collection of Payment Provider Form Properties to which we Assign Values from our Variables - Alan C, 25 June 2015
            var data = new Dictionary<string, object>()
            {
                {"PSPID", "WINBV" },
                //{"ORDERID", "WinExigoOrder" + Order.OrderID.ToString() },
                {"ORDERID", Order.OrderID.ToString() }, // Changed to remove 'WinExigoOrder' per Ticket 67703 on 29 June 2015 - Alan C
                {"AMOUNT", (Order.Total * 100).ToString("0") },
                {"CURRENCY", CurrencyCodes.Euro },
                {"LANGUAGE", language },
                // optional customer details, highly recommended for fraud prevention
                {"CN", args.BillingName},
                {"EMAIL", recipient.Email },
                {"OWNERADDRESS", address.AddressDisplay },
                {"OWNERCTY", address.City },
                {"OWNERTELNO", recipient.Phone },
                {"OWNERZIP", address.Zip },
                {"COM", "Exigo Order {0}".FormatWith(Order.OrderID) },
                //<!-- link to your website: see Default reaction -->
                {"HOMEURL", homeUrl }, // Page to return customer to if they click "cancel" - constructed dynamically based onw whether Replciated Site or BackOffice - Alan C, 29 June 2015
                {"CATALOGURL", shopUrl }, // Shopping landing page if needed - constructed dynamically based onw whether Replciated Site or BackOffice - Alan C, 29 June 2015
                //<!-- post payment redirection: see Redirection depending on the payment result -->
                {"ACCEPTURL", successUrl },
                {"DECLINEURL", declineUrl },
                {"EXCEPTIONURL", errorUrl },
                {"CANCELURL", cancelUrl },
                //<!-- Tell Ingenico to skip the Payment Method List page and go directly to iDEAL - Alan C 29 June 2015 -->
                {"PM",  paymentMethod},

            };

            #endregion

            var hashedData = GetHashedData(data, shaPassPhrase); // Encrypt our Data Properties using our SHA-In Phrase - Alan C, 25 June 2015

            data.Add("SHASIGN", hashedData); // Add our SHA-In Signature and hashed (encrypted into string format) Form Data to Dictionary of Form Properties - Alan C, 25 June 2015

            postRequest.Method = PaymentRequestMethod.Post; // Define the HTTP Method we will use to gather and submit the data to the Payment Provider - Alan C, 25 June 2015
            postRequest.RequestUrl = url; // Add the URL to which we are submitting to our request - Alan C, 25 June 2015
            postRequest.RequestForm = FormHelper.GetSelfPostingFormHtml(url, data); // Call the helper classes and methods to format the data and prepare for submission - Alan C, 25 June 2015

            try
            {
                var context = Exigo.ODataLogging();
                context.AddToLogs(new Common.Api.ExigoOData.LoggingContext.Log { OrderID = Order.OrderID, Request = postRequest.RequestUrl + "  |  " + postRequest.RequestForm, RequestDate = DateTime.Now });
                context.SaveChanges();
            }
            catch (Exception exception) { var error = exception.Message; }

            return postRequest;
        }