private void ProcessCancellation(
            Cart cart,
            Store store,
            WorldPayPaymentResponse wpResponse,
            PayPalLog worldPayLog,
            Page page)
        {
            //string serializedResponse = SerializationHelper.SerializeToString(wpResponse);
            //log.Info("received cancellation worldpay postback, xml to follow");
            //log.Info(serializedResponse);

            // return an html order cancelled template for use at world pay
            if (config.WorldPayProduceShopperCancellationResponse)
            {
                string htmlTemplate = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentUICulture, config.WorldPayShopperCancellationResponseTemplate);
                StringBuilder finalOutput = new StringBuilder();
                finalOutput.Append(htmlTemplate);
                finalOutput.Replace("#WorldPayBannerToken", "<WPDISPLAY ITEM=banner>"); //required by worldpay
                finalOutput.Replace("#CustomerName", wpResponse.Name);
                finalOutput.Replace("#StoreName", store.Name);

                string storePageUrl = worldPayLog.RawResponse;

                finalOutput.Replace("#StorePageLink", "<a href='" + storePageUrl + "'>" + storePageUrl + "</a>");

                page.Response.Write(finalOutput.ToString());
                page.Response.Flush();

            }
        }
        public override bool HandleRequest(
            WorldPayPaymentResponse wpResponse,
            PayPalLog worldPayLog,
            Page page)
        {
            bool result = false;

            if (worldPayLog.SerializedObject.Length == 0) { return result; }

            Cart cart = (Cart)SerializationHelper.DeserializeFromString(typeof(Cart), worldPayLog.SerializedObject);

            Store store = new Store(cart.StoreGuid);
            //SiteSettings siteSettings = new SiteSettings(store.SiteGuid);
            config = SiteUtils.GetCommerceConfig();

            switch (wpResponse.TransStatus)
            {
                case "Y": //success
                    ProcessOrder(cart, store, wpResponse, worldPayLog, page);

                    result = true;
                    break;

                case "C": // cancelled
                default:
                    ProcessCancellation(cart, store, wpResponse, worldPayLog, page);
                    break;

            }

            return result;
        }
Ejemplo n.º 3
0
 public override bool HandleRequest(
     WorldPayPaymentResponse wpResponse,
     PayPalLog worldPayLog,
     Page page)
 {
     // do nothing
     return(false);
 }
 public override bool HandleRequest(
     WorldPayPaymentResponse wpResponse,
     PayPalLog worldPayLog,
     Page page)
 {
     // do nothing
     return false;
 }
        private void ProcessOrder(
            Cart cart,
            Store store,
            WorldPayPaymentResponse wpResponse,
            PayPalLog worldPayLog,
            Page page)
        {
            // process the cart into an order then
            // return an html order result template for use at world pay

            cart.DeSerializeCartOffers();

            if (wpResponse.CompName.Length > 0)
            {
                cart.OrderInfo.CustomerCompany = wpResponse.CompName;
            }
            if (wpResponse.Address1.Length > 0)
            {
                cart.OrderInfo.CustomerAddressLine1 = wpResponse.Address1;
            }

            if (wpResponse.Address2.Length > 0)
            {
                cart.OrderInfo.CustomerAddressLine2 = wpResponse.Address2;
            }

            if (wpResponse.Address3.Length > 0)
            {
                cart.OrderInfo.CustomerAddressLine2 += " " + wpResponse.Address3;
            }

            if (wpResponse.Town.Length > 0)
            {
                cart.OrderInfo.CustomerCity = wpResponse.Town;
            }
            //cart.OrderInfo.DeliveryFirstName = wpResponse.Name;
            if(
                (wpResponse.Name.Length > 0)
                && ((cart.OrderInfo.CustomerLastName.Length == 0) || (!wpResponse.Name.Contains((cart.OrderInfo.CustomerLastName))))
                )
            {
                cart.OrderInfo.CustomerLastName = wpResponse.Name; // this is full name
            }
            if (wpResponse.Postcode.Length > 0)
            {
                cart.OrderInfo.CustomerPostalCode = wpResponse.Postcode;
            }
            if (wpResponse.Region.Length > 0)
            {
                cart.OrderInfo.CustomerState = wpResponse.Region;
            }
            if (wpResponse.Country.Length > 0)
            {
                cart.OrderInfo.CustomerCountry = wpResponse.Country;
            }

            if (wpResponse.Tel.Length > 0)
            {
                cart.OrderInfo.CustomerTelephoneDay = wpResponse.Tel;
            }

            if (wpResponse.Email.Length > 0)
            {
                cart.OrderInfo.CustomerEmail = wpResponse.Email;
            }

            cart.CopyCustomerToBilling();
            cart.CopyCustomerToShipping();
            //cart.TaxTotal = taxAmount;
            //cart.OrderTotal = grossAmount;
            //if (shippingAmount > 0)
            //{
            //    cart.ShippingTotal = shippingAmount;
            //}

            StoreHelper.EnsureUserForOrder(cart);

            cart.Save();

            Order order = Order.CreateOrder(
                store,
                cart,
                wpResponse.TransId,
                wpResponse.TransId,
                string.Empty,
                wpResponse.Currency,
                "WorldPay",
                OrderStatus.OrderStatusFulfillableGuid);

            // grab the return url before we delete the un-needed logs
            string orderDetailUrl = worldPayLog.ReturnUrl;
            string storePageUrl = worldPayLog.RawResponse;

            // remove any previous logs
            GoogleCheckoutLog.DeleteByCart(order.OrderGuid);
            PayPalLog.DeleteByCart(order.OrderGuid);

            // create a final log that has the serialized reposnse from worldpay rather than the serialized cart
            worldPayLog = new PayPalLog();
            worldPayLog.SiteGuid = store.SiteGuid;
            worldPayLog.StoreGuid = store.Guid;
            worldPayLog.CartGuid = order.OrderGuid;
            worldPayLog.UserGuid = order.UserGuid;
            worldPayLog.ProviderName = "WebStoreWorldPayResponseHandler";
            worldPayLog.RequestType = "WorldPay";
            worldPayLog.PaymentStatus = "Paid";
            worldPayLog.PaymentType = "WorldPay";
            worldPayLog.CartTotal = order.OrderTotal;
            worldPayLog.PayPalAmt = wpResponse.AuthAmount;
            worldPayLog.TransactionId = wpResponse.TransId;
            worldPayLog.CurrencyCode = wpResponse.Currency;
            worldPayLog.ReasonCode = wpResponse.AVS;
            worldPayLog.RawResponse = SerializationHelper.SerializeToString(wpResponse);
            worldPayLog.CreatedUtc = DateTime.UtcNow;
            worldPayLog.ReturnUrl = orderDetailUrl;
            worldPayLog.Save();

            try
            {
                StoreHelper.ConfirmOrder(store, order);

            }
            catch (Exception ex)
            {
                log.Error("error sending confirmation email", ex);
            }

            // retrun the html

            if (config.WorldPayProduceShopperResponse)
            {
                CultureInfo currencyCulture = ResourceHelper.GetCurrencyCulture(wpResponse.Currency);

                string htmlTemplate = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentUICulture, config.WorldPayShopperResponseTemplate);
                StringBuilder finalOutput = new StringBuilder();
                finalOutput.Append(htmlTemplate);
                finalOutput.Replace("#WorldPayBannerToken", "<WPDISPLAY ITEM=banner>"); //required by worldpay
                finalOutput.Replace("#CustomerName", wpResponse.Name);
                finalOutput.Replace("#StoreName", store.Name);
                finalOutput.Replace("#OrderId", order.OrderGuid.ToString());
                finalOutput.Replace("#StorePageLink", "<a href='" + storePageUrl + "'>" + storePageUrl + "</a>");
                finalOutput.Replace("#OrderDetailLink", "<a href='" + orderDetailUrl + "'>" + orderDetailUrl + "</a>");

                StringBuilder orderDetails = new StringBuilder();
                DataSet dsOffers = Order.GetOrderOffersAndProducts(store.Guid, order.OrderGuid);

                foreach (DataRow row in dsOffers.Tables["Offers"].Rows)
                {
                    string og = row["OfferGuid"].ToString();
                    orderDetails.Append(row["Name"].ToString() + " ");
                    orderDetails.Append(row["Quantity"].ToString() + " @ ");
                    orderDetails.Append(string.Format(currencyCulture, "{0:c}", Convert.ToDecimal(row["OfferPrice"])));
                    orderDetails.Append("<br />");

                    string whereClause = string.Format("OfferGuid = '{0}'", og);
                    DataView dv = new DataView(dsOffers.Tables["Products"], whereClause, "", DataViewRowState.CurrentRows);

                    if (dv.Count > 1)
                    {
                        foreach (DataRow r in dsOffers.Tables["Products"].Rows)
                        {
                            string pog = r["OfferGuid"].ToString();
                            if (og == pog)
                            {
                                orderDetails.Append(r["Name"].ToString() + " ");
                                orderDetails.Append(r["Quantity"].ToString() + "  <br />");

                            }

                        }
                    }

                }

                finalOutput.Replace("#OrderDetails", orderDetails.ToString());
                page.Response.Write(finalOutput.ToString());
                page.Response.Flush();

            }
        }
Ejemplo n.º 6
0
        public static WorldPayPaymentResponse ParseRequest()
        {
            if (HttpContext.Current == null)
            {
                return(null);
            }
            if (HttpContext.Current.Request == null)
            {
                return(null);
            }

            WorldPayPaymentResponse wpResponse = new WorldPayPaymentResponse();

            WebUtils.TryLoadRequestParam <string>("instId", out wpResponse.installationId);
            WebUtils.TryLoadRequestParam <string>("cartId", out wpResponse.cartId);
            WebUtils.TryLoadRequestParam <string>("M_custom", out wpResponse.customData);

            WebUtils.TryLoadRequestParam <string>("currency", out wpResponse.currency);

            CultureInfo currencyCulture = CurrencyHelper.CultureInfoFromCurrencyISO(wpResponse.currency);

            if (currencyCulture == null)
            {
                currencyCulture = CultureInfo.CurrentCulture;
            }

            string amountString;

            WebUtils.TryLoadRequestParam <string>("amount", out amountString);
            if (!string.IsNullOrEmpty(amountString))
            {
                try
                {
                    wpResponse.amount = Convert.ToDecimal(amountString, currencyCulture);
                }
                catch (FormatException) { }
                catch (OverflowException) { }
            }

            WebUtils.TryLoadRequestParam <string>("authAmountString", out wpResponse.authAmountString);
            WebUtils.TryLoadRequestParam <string>("authMode", out wpResponse.authMode);
            WebUtils.TryLoadRequestParam <string>("testMode", out wpResponse.testMode);
            WebUtils.TryLoadRequestParam <string>("name", out wpResponse.name);
            WebUtils.TryLoadRequestParam <string>("address1", out wpResponse.address1);
            WebUtils.TryLoadRequestParam <string>("address2", out wpResponse.address2);
            WebUtils.TryLoadRequestParam <string>("address3", out wpResponse.address3);
            WebUtils.TryLoadRequestParam <string>("town", out wpResponse.town);
            WebUtils.TryLoadRequestParam <string>("region", out wpResponse.region);
            WebUtils.TryLoadRequestParam <string>("postcode", out wpResponse.postcode);
            WebUtils.TryLoadRequestParam <string>("country", out wpResponse.country);
            WebUtils.TryLoadRequestParam <string>("countryString", out wpResponse.countryString);
            WebUtils.TryLoadRequestParam <string>("tel", out wpResponse.tel);
            WebUtils.TryLoadRequestParam <string>("fax", out wpResponse.fax);
            WebUtils.TryLoadRequestParam <string>("email", out wpResponse.email);
            WebUtils.TryLoadRequestParam <string>("delvName", out wpResponse.delvName);
            WebUtils.TryLoadRequestParam <string>("delvAddress1", out wpResponse.delvAddress1);
            WebUtils.TryLoadRequestParam <string>("delvAddress2", out wpResponse.delvAddress2);
            WebUtils.TryLoadRequestParam <string>("delvAddress1", out wpResponse.delvAddress3);
            WebUtils.TryLoadRequestParam <string>("delvTown", out wpResponse.delvTown);
            WebUtils.TryLoadRequestParam <string>("delvRegion", out wpResponse.delvRegion);
            WebUtils.TryLoadRequestParam <string>("delvPostcode", out wpResponse.delvPostcode);
            WebUtils.TryLoadRequestParam <string>("delvCountry", out wpResponse.delvCountry);
            WebUtils.TryLoadRequestParam <string>("delvCountryString", out wpResponse.delvCountryString);
            WebUtils.TryLoadRequestParam <string>("compName", out wpResponse.compName);
            WebUtils.TryLoadRequestParam <string>("transId", out wpResponse.transId);
            WebUtils.TryLoadRequestParam <string>("transStatus", out wpResponse.transStatus);
            WebUtils.TryLoadRequestParam <string>("transTime", out wpResponse.transTime);
            WebUtils.TryLoadRequestParam <string>("authCurrency", out wpResponse.authCurrency);

            CultureInfo authCurrencyCulture = CurrencyHelper.CultureInfoFromCurrencyISO(wpResponse.authCurrency);

            if (authCurrencyCulture == null)
            {
                authCurrencyCulture = CultureInfo.CurrentCulture;
            }

            string authAmountString;

            WebUtils.TryLoadRequestParam <string>("authAmount", out authAmountString);
            if (!string.IsNullOrEmpty(authAmountString))
            {
                try
                {
                    wpResponse.authAmount = Convert.ToDecimal(amountString, authCurrencyCulture);
                }
                catch (FormatException) { }
                catch (OverflowException) { }
            }

            //


            WebUtils.TryLoadRequestParam <string>("rawAuthMessage", out wpResponse.rawAuthMessage);
            WebUtils.TryLoadRequestParam <string>("callbackPW", out wpResponse.callbackPW);
            WebUtils.TryLoadRequestParam <string>("cardType", out wpResponse.cardType);
            WebUtils.TryLoadRequestParam <string>("AVS", out wpResponse.avs);
            WebUtils.TryLoadRequestParam <string>("wafMerchMessage", out wpResponse.wafMerchMessage);
            WebUtils.TryLoadRequestParam <string>("authentication", out wpResponse.authentication);
            WebUtils.TryLoadRequestParam <string>("ipAddress", out wpResponse.ipAddress);
            WebUtils.TryLoadRequestParam <string>("charenc", out wpResponse.charenc);
            WebUtils.TryLoadRequestParam <string>("futurePayId", out wpResponse.futurePayId);
            WebUtils.TryLoadRequestParam <string>("futurePayStatusChange", out wpResponse.futurePayStatusChange);


            if (IsValidResponse(wpResponse))
            {
                return(wpResponse);
            }

            return(null);
        }
Ejemplo n.º 7
0
        //private static string GetFormParameter(HttpRequest request, string paramName)
        //{

        //    return string.Empty;
        //}

        private static bool IsValidResponse(WorldPayPaymentResponse wpResponse)
        {
            //TODO: make sure expected params exist and are valid

            return(true);
        }
Ejemplo n.º 8
0
 public abstract bool HandleRequest(
     WorldPayPaymentResponse wpResponse,
     PayPalLog worldPayLog,
     Page page); // we are piggy backing on the already existing paypal log rather than create a new table
Ejemplo n.º 9
0
        //private static string GetFormParameter(HttpRequest request, string paramName)
        //{
        //    return string.Empty;
        //}
        private static bool IsValidResponse(WorldPayPaymentResponse wpResponse)
        {
            //TODO: make sure expected params exist and are valid

            return true;
        }
Ejemplo n.º 10
0
        public static WorldPayPaymentResponse ParseRequest()
        {
            if (HttpContext.Current == null) { return null; }
            if (HttpContext.Current.Request == null) { return null; }

            WorldPayPaymentResponse wpResponse = new WorldPayPaymentResponse();

            WebUtils.TryLoadRequestParam<string>("instId", out wpResponse.installationId);
            WebUtils.TryLoadRequestParam<string>("cartId", out wpResponse.cartId);
            WebUtils.TryLoadRequestParam<string>("M_custom", out wpResponse.customData);

            WebUtils.TryLoadRequestParam<string>("currency", out wpResponse.currency);

            CultureInfo currencyCulture = CurrencyHelper.CultureInfoFromCurrencyISO(wpResponse.currency);
            if (currencyCulture == null) { currencyCulture = CultureInfo.CurrentCulture; }

            string amountString;
            WebUtils.TryLoadRequestParam<string>("amount", out amountString);
            if (!string.IsNullOrEmpty(amountString))
            {
                try
                {
                    wpResponse.amount = Convert.ToDecimal(amountString, currencyCulture);
                }
                catch (FormatException) { }
                catch (OverflowException) { }
            }

            WebUtils.TryLoadRequestParam<string>("authAmountString", out wpResponse.authAmountString);
            WebUtils.TryLoadRequestParam<string>("authMode", out wpResponse.authMode);
            WebUtils.TryLoadRequestParam<string>("testMode", out wpResponse.testMode);
            WebUtils.TryLoadRequestParam<string>("name", out wpResponse.name);
            WebUtils.TryLoadRequestParam<string>("address1", out wpResponse.address1);
            WebUtils.TryLoadRequestParam<string>("address2", out wpResponse.address2);
            WebUtils.TryLoadRequestParam<string>("address3", out wpResponse.address3);
            WebUtils.TryLoadRequestParam<string>("town", out wpResponse.town);
            WebUtils.TryLoadRequestParam<string>("region", out wpResponse.region);
            WebUtils.TryLoadRequestParam<string>("postcode", out wpResponse.postcode);
            WebUtils.TryLoadRequestParam<string>("country", out wpResponse.country);
            WebUtils.TryLoadRequestParam<string>("countryString", out wpResponse.countryString);
            WebUtils.TryLoadRequestParam<string>("tel", out wpResponse.tel);
            WebUtils.TryLoadRequestParam<string>("fax", out wpResponse.fax);
            WebUtils.TryLoadRequestParam<string>("email", out wpResponse.email);
            WebUtils.TryLoadRequestParam<string>("delvName", out wpResponse.delvName);
            WebUtils.TryLoadRequestParam<string>("delvAddress1", out wpResponse.delvAddress1);
            WebUtils.TryLoadRequestParam<string>("delvAddress2", out wpResponse.delvAddress2);
            WebUtils.TryLoadRequestParam<string>("delvAddress1", out wpResponse.delvAddress3);
            WebUtils.TryLoadRequestParam<string>("delvTown", out wpResponse.delvTown);
            WebUtils.TryLoadRequestParam<string>("delvRegion", out wpResponse.delvRegion);
            WebUtils.TryLoadRequestParam<string>("delvPostcode", out wpResponse.delvPostcode);
            WebUtils.TryLoadRequestParam<string>("delvCountry", out wpResponse.delvCountry);
            WebUtils.TryLoadRequestParam<string>("delvCountryString", out wpResponse.delvCountryString);
            WebUtils.TryLoadRequestParam<string>("compName", out wpResponse.compName);
            WebUtils.TryLoadRequestParam<string>("transId", out wpResponse.transId);
            WebUtils.TryLoadRequestParam<string>("transStatus", out wpResponse.transStatus);
            WebUtils.TryLoadRequestParam<string>("transTime", out wpResponse.transTime);
            WebUtils.TryLoadRequestParam<string>("authCurrency", out wpResponse.authCurrency);

            CultureInfo authCurrencyCulture = CurrencyHelper.CultureInfoFromCurrencyISO(wpResponse.authCurrency);
            if (authCurrencyCulture == null) { authCurrencyCulture = CultureInfo.CurrentCulture; }

            string authAmountString;
            WebUtils.TryLoadRequestParam<string>("authAmount", out authAmountString);
            if (!string.IsNullOrEmpty(authAmountString))
            {
                try
                {
                    wpResponse.authAmount = Convert.ToDecimal(amountString, authCurrencyCulture);
                }
                catch (FormatException) { }
                catch (OverflowException) { }
            }

            //

            WebUtils.TryLoadRequestParam<string>("rawAuthMessage", out wpResponse.rawAuthMessage);
            WebUtils.TryLoadRequestParam<string>("callbackPW", out wpResponse.callbackPW);
            WebUtils.TryLoadRequestParam<string>("cardType", out wpResponse.cardType);
            WebUtils.TryLoadRequestParam<string>("AVS", out wpResponse.avs);
            WebUtils.TryLoadRequestParam<string>("wafMerchMessage", out wpResponse.wafMerchMessage);
            WebUtils.TryLoadRequestParam<string>("authentication", out wpResponse.authentication);
            WebUtils.TryLoadRequestParam<string>("ipAddress", out wpResponse.ipAddress);
            WebUtils.TryLoadRequestParam<string>("charenc", out wpResponse.charenc);
            WebUtils.TryLoadRequestParam<string>("futurePayId", out wpResponse.futurePayId);
            WebUtils.TryLoadRequestParam<string>("futurePayStatusChange", out wpResponse.futurePayStatusChange);

            if(IsValidResponse(wpResponse))
            {
                return wpResponse;
            }

            return null;
        }
 public abstract bool HandleRequest(
     WorldPayPaymentResponse wpResponse,
     PayPalLog worldPayLog,
     Page page);