Esempio n. 1
0
        public SortedDictionary <string, string> GetBaseFields()
        {
            string returnUrl = string.Format("{0}/Apps/Ecommerce/CharityClear/Notification", GetSiteUrl());
            string total     = ((int)(_cart.TotalToPay * 100)).ToString();
            var    fields    = new SortedDictionary <string, string>
            {
                { "merchantID", _charityClearSettings.MerchantId },
                { "amount", total.Replace(".", "") },
                { "action", "SALE" },
                { "type", "1" },
                { "countryCode", _charityClearSettings.ISOCountryCode },
                { "currencyCode", _ecommerceSettings.CurrencyCode() },
                { "orderRef", _cart.CartGuid.ToString() },
                { "redirectURL", returnUrl },
                { "callbackURL", returnUrl }
            };

            if (!string.IsNullOrWhiteSpace(_charityClearSettings.MerchantPassword))
            {
                fields.Add("merchantPwd", _charityClearSettings.MerchantPassword);
            }
            if (_cart.BillingAddress != null)
            {
                fields.Add("customerName", _cart.BillingAddress.Name.Trim());
                string address =
                    _cart.BillingAddress.GetDescription(true)
                    .Replace(_cart.BillingAddress.PostalCode, "")
                    .Replace(",", "\n");
                fields.Add("customerAddress", address);
                fields.Add("customerPostCode", _cart.BillingAddress.PostalCode);
                fields.Add("customerPhone", _cart.BillingAddress.PhoneNumber);
                fields.Add("customerEmail", _cart.OrderEmail);
            }

            int i = 1;

            foreach (var cartItem in _cart.Items)
            {
                fields.Add("item" + i + "Description", cartItem.Name);
                fields.Add("item" + i + "Quantity", cartItem.Quantity.ToString());
                fields.Add("item" + i + "GrossValue", cartItem.Price.ToString("0.00").Replace(".", ""));
                i++;
            }

            fields.Add("merchantData", CalculateHash(_cart.CartGuid + _charityClearSettings.SignatureKey));

            return(fields);
        }
Esempio n. 2
0
        public TransactionRegistration BuildRegistration(CartModel cartModel)
        {
            var shoppingBasket          = _sagePayItemCreator.GetShoppingBasket(cartModel);
            var billingAddress          = _sagePayItemCreator.GetAddress(cartModel.BillingAddress);
            var deliveryAddress         = _sagePayItemCreator.GetAddress(cartModel.ShippingAddress ?? cartModel.BillingAddress);
            var transactionRegistration = new TransactionRegistration
            {
                AllowGiftAid       = _sagePaySettings.AllowGiftAidString,
                Amount             = shoppingBasket.Total,
                Apply3DSecure      = _sagePaySettings.Apply3DSecure,
                ApplyAVSCV2        = _sagePaySettings.ApplyAVSCV2,
                Basket             = shoppingBasket.ToString(),
                BillingAddress1    = billingAddress.Address1,
                BillingAddress2    = billingAddress.Address2,
                BillingCity        = billingAddress.City,
                BillingCountry     = billingAddress.Country,
                BillingFirstNames  = billingAddress.Firstnames,
                BillingPhone       = billingAddress.Phone,
                BillingPostcode    = billingAddress.PostCode,
                BillingState       = billingAddress.State,
                BillingSurname     = billingAddress.Surname,
                Currency           = _ecommerceSettings.CurrencyCode(),
                CustomerEMail      = cartModel.OrderEmail,
                DeliveryAddress1   = deliveryAddress.Address1,
                DeliveryAddress2   = deliveryAddress.Address2,
                DeliveryCity       = deliveryAddress.City,
                DeliveryCountry    = deliveryAddress.Country,
                DeliveryFirstNames = deliveryAddress.Firstnames,
                DeliveryPhone      = deliveryAddress.Phone,
                DeliveryPostcode   = deliveryAddress.PostCode,
                DeliveryState      = deliveryAddress.State,
                DeliverySurname    = deliveryAddress.Surname,
                Description        =
                    string.Format("Order from {0}", _site.Name),
                NotificationUrl = _sagePayUrlResolver.BuildNotificationUrl(),
                Profile         = _sagePaySettings.PaymentFormProfileString,
                TxType          = "PAYMENT",
                VPSProtocol     = _sagePaySettings.Protocol,
                Vendor          = _sagePaySettings.VendorName,
                VendorTxCode    = cartModel.CartGuid.ToString()
            };

            return(transactionRegistration);
        }
Esempio n. 3
0
        public WorldPayPostInfo GetInfo()
        {
            string schemeAndAuthority = GetSchemeAndAuthority();
            string returnUrl          = string.Format("{0}/Apps/Ecommerce/WorldPay/Notification", schemeAndAuthority);

            var postInfo = new WorldPayPostInfo();

            postInfo.PostUrl = _worldPaySettings.GetPostUrl();

            postInfo.instId = _worldPaySettings.InstanceId;
            postInfo.cartId = _cart.CartGuid.ToString();

            if (!string.IsNullOrEmpty(_worldPaySettings.PaymentMethod))
            {
                postInfo.paymentType = _worldPaySettings.PaymentMethod;
            }

            if (!string.IsNullOrEmpty(_worldPaySettings.CssName))
            {
                postInfo.MC_WorldPayCSSName = _worldPaySettings.CssName;
            }

            postInfo.currency     = _ecommerceSettings.CurrencyCode();
            postInfo.email        = _cart.OrderEmail;
            postInfo.withDelivery = _cart.RequiresShipping ? "true" : "false";
            postInfo.amount       = _cart.TotalToPay.ToString(new CultureInfo("en-US", false).NumberFormat);
            postInfo.desc         = _site.Name;
            postInfo.M_UserID     = _cart.UserGuid.ToString();
            postInfo.M_FirstName  = _cart.BillingAddress.FirstName;
            postInfo.M_LastName   = _cart.BillingAddress.LastName;
            postInfo.M_Addr1      = _cart.BillingAddress.Address1;
            postInfo.tel          = _cart.BillingAddress.PhoneNumber;
            postInfo.M_Addr2      = _cart.BillingAddress.Address2;
            postInfo.M_Business   = _cart.BillingAddress.Company;

            postInfo.lang = CurrentRequestData.CultureInfo.TwoLetterISOLanguageName;

            postInfo.M_StateCounty = _cart.BillingAddress.StateProvince;

            postInfo.testMode = _worldPaySettings.UseSandbox ? "100" : "0";
            postInfo.postcode = _cart.BillingAddress.PostalCode;
            postInfo.country  = _cart.BillingAddress.CountryCode;

            postInfo.address = string.Format("{0}{1}", _cart.BillingAddress.Address1,
                                             _cart.BillingAddress.GetCountryName());
            postInfo.MC_callback = returnUrl;
            postInfo.name        = string.Format("{0} {1}", _cart.BillingAddress.FirstName, _cart.BillingAddress.LastName);

            if (_cart.RequiresShipping)
            {
                postInfo.delvName = string.Format("{0} {1}", _cart.ShippingAddress.FirstName,
                                                  _cart.ShippingAddress.LastName);
                string delvAddress = _cart.ShippingAddress.Address1;
                delvAddress += (!string.IsNullOrEmpty(_cart.ShippingAddress.Address2))
                    ? string.Format(" {0}", _cart.ShippingAddress.Address2)
                    : string.Empty;
                postInfo.delvAddress  = delvAddress;
                postInfo.delvPostcode = _cart.ShippingAddress.PostalCode;
                postInfo.delvCountry  = _cart.ShippingAddress.CountryCode;
            }
            else
            {
                postInfo.HideShipping = true;
            }
            return(postInfo);
        }