protected virtual string CheckStatus([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");

            var          configuration    = new PaymentSettingsReader(paymentSystem);
            string       protocolInput    = configuration.GetSetting("protocol");
            const string MsgtypeInput     = "status";
            string       merchantInput    = paymentSystem.Username;
            string       ordernumberInput = paymentArgs.ShoppingCart.OrderNumber;
            string       secretInput      = paymentSystem.Password;
            string       apiUrl           = configuration.GetSetting("apiURL");

            string tohashInput   = string.Concat(protocolInput, MsgtypeInput, merchantInput, ordernumberInput, secretInput);
            string hashInput     = this.GetMD5Hash(tohashInput);
            string requestString = string.Format(
                "protocol={0}&msgtype={1}&merchant={2}&ordernumber={3}&md5check={4}",
                protocolInput,
                MsgtypeInput,
                paymentSystem.Username,
                ordernumberInput,
                hashInput);

            string information = string.Empty;

            return(this.SendRequest(apiUrl, requestString, ref information));
        }
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");

            base.Invoke(paymentSystem, paymentArgs);

            string sequence  = new Random().Next(0, 1000).ToString();
            string timeStamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
            string currency  = this.Currency(paymentArgs.ShoppingCart.Currency.Code);

            string fingerprint = this.HmacMD5(paymentSystem.Password, paymentSystem.Username + "^" + sequence + "^" + timeStamp + "^" + paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.RoundToCents() + "^" + currency);


            NameValueCollection data = new NameValueCollection
            {
                { "x_login", paymentSystem.Username },
                { "x_invoice_num", paymentArgs.ShoppingCart.OrderNumber },
                { "x_po_num", paymentArgs.ShoppingCart.OrderNumber },
                { "x_receipt_link_url", paymentArgs.PaymentUrls.ReturnPageUrl },
                { "x_amount", paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.RoundToCents() },
                { "x_tax", paymentArgs.ShoppingCart.Totals.TotalVat.RoundToCents() },
                { "x_currency_code", currency },
                { "x_description", paymentArgs.Description },
                { "x_fp_sequence", sequence },
                { "x_fp_timestamp", timeStamp },
                { "x_customer_ip", HttpContext.Current.Request.UserHostAddress },
                { "x_fp_hash", fingerprint },
                { "x_first_name", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.Name },
                { "x_last_name", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.Name2 },
                { "x_address", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.Address },
                { "x_city", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.City },
                { "x_state", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.State },
                { "x_zip", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.Zip },
                { "x_country", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.Country.Title },
                { "x_ship_to_first_name", paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress.Name },
                { "x_ship_to_last_name", paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress.Name2 },
                { "x_ship_to_address", paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress.Address },
                { "x_ship_to_city", paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress.City },
                { "x_ship_to_state", paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress.State },
                { "x_ship_to_zip", paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress.Zip },
                { "x_ship_to_country", paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress.Country.Title },
                { "x_phone", paymentArgs.ShoppingCart.CustomerInfo.Phone },
                { "x_fax", paymentArgs.ShoppingCart.CustomerInfo.Fax },
                { "x_email", paymentArgs.ShoppingCart.CustomerInfo.Email },
                { "x_header_email_receipt", paymentArgs.ShoppingCart.CustomerInfo.Email },
            };

            PaymentSettingsReader paymentSettingsReader = new PaymentSettingsReader(paymentSystem);

            data.Add(paymentSettingsReader.GetProviderSettings());

            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SaveStartValues(paymentArgs.ShoppingCart.OrderNumber, paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.RoundToCents(), currency, paymentSystem.Code);

            this.PostData(paymentSystem.PaymentUrl, data);
        }
        /// <summary>
        /// Captures the payment
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        /// <param name="reservationTicket">The reservation ticket.</param>
        /// <param name="amount">The amount.</param>
        public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.ArgumentNotNull(reservationTicket, "reservationTicket");

            Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero");
            Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one");

            var configuration = new PaymentSettingsReader(paymentSystem);
            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            string       protocolInput = configuration.GetSetting("protocol");
            const string MsgtypeInput  = "capture";
            string       merchantInput = paymentSystem.Username;
            string       amountInput   = amount.ToCents();
            string       transaction   = reservationTicket.TransactionNumber;
            string       secretInput   = paymentSystem.Password;
            string       apiUrl        = configuration.GetSetting("apiURL");

            string tohashInput   = string.Concat(protocolInput, MsgtypeInput, merchantInput, amountInput, transaction, secretInput);
            string hashInput     = this.GetMD5Hash(tohashInput);
            string requestString = string.Format(
                "protocol={0}&msgtype={1}&merchant={2}&amount={3}&transaction={4}&md5check={5}",
                protocolInput,
                MsgtypeInput,
                paymentSystem.Username,
                amountInput,
                transaction,
                hashInput);

            string message     = "UnCaptured: ";
            string information = string.Empty;
            string xmlReturn   = this.SendRequest(apiUrl, requestString, ref information);

            if (!string.IsNullOrEmpty(xmlReturn))
            {
                var    quickPayResponse = this.ParseResult(xmlReturn);
                string secret           = paymentSystem.Password;
                string tohash           = string.Join(string.Empty, quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) + secret;
                string md5Check         = this.GetMD5Hash(tohash);

                if (md5Check.Equals(quickPayResponse["md5check"]) && quickPayResponse["qpstat"].Equals("000"))
                {
                    transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.CaptureSuccess);
                    return;
                }

                message += string.Format("qpstat={0}", quickPayResponse["qpstat"]);
            }
            else
            {
                message += information;
            }

            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, message);
        }
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            this.PaymentStatus = PaymentStatus.Failure;

            HttpRequest           request = HttpContext.Current.Request;
            ITransactionData      transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
            PaymentSettingsReader configuration           = new PaymentSettingsReader(paymentSystem);
            string autocapture = configuration.GetSetting("autocapture");

            if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse)
            {
                string xmlReturn = this.CheckStatus(paymentSystem, paymentArgs);
                if (!string.IsNullOrEmpty(xmlReturn))
                {
                    var    quickPayResponse = this.ParseResult(xmlReturn);
                    string secret           = paymentSystem.Password;
                    string tohash           = string.Join(string.Empty, quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) + secret;

                    string md5Check = this.GetMD5Hash(tohash);
                    if (md5Check.Equals(quickPayResponse["md5check"]) && quickPayResponse["qpstat"].Equals("000"))
                    {
                        this.PaymentStatus = PaymentStatus.Succeeded;
                        transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), quickPayResponse["transaction"], quickPayResponse["amount"], quickPayResponse["currency"], string.Empty, string.Empty, string.Empty, quickPayResponse["cardtype"]);
                        if (string.Compare(autocapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            string transactionAmount = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TotalAmount) as string;
                            string orderNumber       = paymentArgs.ShoppingCart.OrderNumber;
                            string transactionNumber = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TransactionNumber) as string;

                            decimal           amount            = transactionAmount.FromCents();
                            ReservationTicket reservationTicket = new ReservationTicket
                            {
                                InvoiceNumber     = orderNumber,
                                AuthorizationCode = PaymentConstants.EmptyAuthorizationCode,
                                TransactionNumber = transactionNumber,
                                Amount            = amount
                            };
                            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
                        }
                    }
                }
            }
            else
            {
                this.PaymentStatus = PaymentStatus.Canceled;
            }

            if (this.PaymentStatus != PaymentStatus.Succeeded)
            {
                transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
            }
        }
        /// <summary>
        /// Performs the completion of the conversation with PayPal.
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="orderRef">The order ref.</param>
        /// <param name="accountNumber">The account number.</param>
        /// <param name="hash">The hash.</param>
        /// <param name="transactionDataProvider">The transaction data provider.</param>
        protected void CompleteCallback(PaymentSystem paymentSystem, string orderRef, long accountNumber, string hash, ITransactionData transactionDataProvider)
        {
            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);
            string        purchaseOperation     = configuration.GetSetting("purchaseOperation");
            PaymentStatus paymentStatusResult   = PaymentStatus.Failure;

            PxOrder payexOrder = new PxOrder();
            string  xmlReturn  = payexOrder.Complete(accountNumber, orderRef, hash);

            string transactionNumber = this.ParseRes(xmlReturn, "/payex/transactionNumber");
            string orderNumber       = this.ParseRes(xmlReturn, "/payex/orderId");
            string transactionAmount = this.ParseRes(xmlReturn, "/payex/amount");
            string errorCode         = this.ParseRes(xmlReturn, "/payex/status/errorCode");
            int    transactionStatus = int.Parse(this.ParseRes(xmlReturn, "/payex/transactionStatus"));

            if (errorCode == "OK")
            {
                switch (transactionStatus)
                {
                case (int)TransactionStatus.Sale:
                case (int)TransactionStatus.Authorize:
                {
                    paymentStatusResult = PaymentStatus.Succeeded;
                    transactionDataProvider.SaveCallBackValues(orderNumber, paymentStatusResult.ToString(), transactionNumber, transactionAmount, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);

                    if (string.Compare(purchaseOperation, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        decimal           amount            = transactionAmount.FromCents();
                        ReservationTicket reservationTicket = new ReservationTicket
                        {
                            InvoiceNumber     = orderNumber,
                            AuthorizationCode = PaymentConstants.EmptyAuthorizationCode,
                            TransactionNumber = transactionNumber,
                            Amount            = amount
                        };
                        transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
                    }

                    break;
                }

                default:
                {
                    string transactionErrorCode = this.ParseRes(xmlReturn, "/payex/errorDetails/transactionErrorCode");
                    if (transactionErrorCode == OperationCanceledError)
                    {
                        paymentStatusResult = PaymentStatus.Canceled;
                    }

                    break;
                }
                }
            }

            this.PaymentStatus = paymentStatusResult;
        }
Example #6
0
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            this.PaymentStatus = PaymentStatus.Failure;

            HttpRequest           request                 = HttpContext.Current.Request;
            PaymentSettingsReader configuration           = new PaymentSettingsReader(paymentSystem);
            ITransactionData      transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
            string instantcapture = configuration.GetSetting("instantcapture");

            if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse)
            {
                string transactionNumber = request.QueryString["tid"];
                string cardid            = request.QueryString["cardid"];
                string currency          = request.QueryString["cur"];
                string orderid           = request.QueryString["orderid"];
                string amount            = request.QueryString["amount"];
                string hashString        = request.QueryString["eKey"];
                string date = request.QueryString["date"];

                if (!this.CallBackIsvalid(paymentSystem, paymentArgs, currency, transactionNumber, amount, orderid, hashString, date))
                {
                    Log.Error("Callback parameters are invalid.", this);
                }
                else
                {
                    this.PaymentStatus = PaymentStatus.Succeeded;
                    transactionDataProvider.SaveCallBackValues(orderid, this.PaymentStatus.ToString(), transactionNumber, amount, currency, string.Empty, string.Empty, string.Empty, cardid);

                    if (string.Compare(instantcapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        ReservationTicket reservationTicket = new ReservationTicket
                        {
                            InvoiceNumber     = orderid,
                            AuthorizationCode = hashString,
                            TransactionNumber = transactionNumber,
                            Amount            = amount.FromCents()
                        };
                        transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
                    }
                }
            }
            else
            {
                this.PaymentStatus = PaymentStatus.Canceled;
            }

            if (this.PaymentStatus != PaymentStatus.Succeeded)
            {
                transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
            }
        }
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            this.PaymentStatus = PaymentStatus.Failure;

            HttpRequest           request = HttpContext.Current.Request;
            ITransactionData      transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
            PaymentSettingsReader configuration           = new PaymentSettingsReader(paymentSystem);
            string transactionType = configuration.GetSetting("x_type");

            if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse)
            {
                string transactionId      = request.Form["x_split_tender_id"] ?? request.Form["x_trans_id"];
                string invoiceNumber      = request.Form["x_invoice_num"];
                string authorizationCode  = request.Form["x_auth_code"];
                string totalPrice         = request.Form["x_amount"];
                string responseCode       = request.Form["x_response_code"];
                string responseReasonCode = request.Form["x_response_reason_code"];
                string responseReasonText = request.Form["x_response_reason_text"];
                string method             = request.Form["x_method"];
                string hash = request.Form["x_MD5_Hash"];

                string hashMD5 = Crypto.GetMD5Hash(paymentSystem.Password + paymentSystem.Username + transactionId + totalPrice);

                if (!string.IsNullOrEmpty(hash) && !string.IsNullOrEmpty(hashMD5) && string.Equals(hashMD5, hash, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(responseCode) && responseCode.Equals("1"))
                {
                    this.PaymentStatus = PaymentStatus.Succeeded;
                    transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, PaymentStatus.Succeeded.ToString(), transactionId, totalPrice, string.Empty, responseCode, responseReasonCode, responseReasonText, method);

                    if (string.Compare(transactionType, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        ReservationTicket reservationTicket = new ReservationTicket
                        {
                            InvoiceNumber     = invoiceNumber,
                            AuthorizationCode = authorizationCode,
                            TransactionNumber = transactionId,
                            Amount            = TypeUtil.TryParse(totalPrice, decimal.Zero)
                        };
                        transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
                    }
                }
            }
            else
            {
                this.PaymentStatus = PaymentStatus.Canceled;
            }

            if (this.PaymentStatus != PaymentStatus.Succeeded)
            {
                transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
            }
        }
        /// <summary>
        /// Cancels payment reservation
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        /// <param name="reservationTicket">The reservation ticket.</param>
        public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
              Assert.ArgumentNotNull(reservationTicket, "reservationTicket");

              var configuration = new PaymentSettingsReader(paymentSystem);
              ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();

              string protocolInput = configuration.GetSetting("protocol");
              const string MsgtypeInput = "cancel";
              string merchantInput = paymentSystem.Username;
              string transaction = reservationTicket.TransactionNumber;
              string secretInput = paymentSystem.Password;
              string apiUrl = configuration.GetSetting("apiURL");

              string tohashInput = string.Concat(protocolInput, MsgtypeInput, merchantInput, transaction, secretInput);
              string hashInput = this.GetMD5Hash(tohashInput);

              string requestString = string.Format(
            "protocol={0}&msgtype={1}&merchant={2}&transaction={3}&md5check={4}",
            protocolInput,
            MsgtypeInput,
            paymentSystem.Username,
            transaction,
            hashInput);

              string message = "UnCanceled: ";
              string information = string.Empty;
              string xmlReturn = this.SendRequest(apiUrl, requestString, ref information);
              if (!string.IsNullOrEmpty(xmlReturn))
              {
            var quickPayResponse = this.ParseResult(xmlReturn);
            string secret = paymentSystem.Password;
            string tohash = string.Join(string.Empty, quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) + secret;
            string md5Check = this.GetMD5Hash(tohash);

            if (md5Check.Equals(quickPayResponse["md5check"]) && quickPayResponse["qpstat"].Equals("000"))
            {
              transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.CancelSuccess);
              return;
            }

            message += string.Format("qpstat={0}", quickPayResponse["qpstat"]);
              }
              else
              {
            message += information;
              }

              transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, message);
        }
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            this.PaymentStatus = PaymentStatus.Failure;

            HttpRequest           request = HttpContext.Current.Request;
            ITransactionData      transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
            PaymentSettingsReader configuration           = new PaymentSettingsReader(paymentSystem);
            bool capturenow = !string.IsNullOrEmpty(configuration.GetSetting("capturenow"));

            if (request[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse)
            {
                string transactionNumber = request["transact"];
                string amount            = request["amount"];
                string merchant          = request["merchant"];
                string orderid           = request["orderid"];
                string authkey           = request["authkey"];
                string cardType          = request["paytype"] ?? string.Empty;

                if (this.CallBackIsvalid(paymentSystem, paymentArgs, transactionNumber, amount, merchant, orderid))
                {
                    this.PaymentStatus = PaymentStatus.Succeeded;
                    transactionDataProvider.SaveCallBackValues(orderid, this.PaymentStatus.ToString(), transactionNumber, amount, string.Empty, string.Empty, string.Empty, string.Empty, cardType);

                    if (!capturenow)
                    {
                        ReservationTicket reservationTicket = new ReservationTicket
                        {
                            InvoiceNumber     = orderid,
                            AuthorizationCode = authkey,
                            TransactionNumber = transactionNumber,
                            Amount            = amount.FromCents()
                        };

                        transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
                    }
                }
            }
            else
            {
                this.PaymentStatus = PaymentStatus.Canceled;
            }

            if (this.PaymentStatus != PaymentStatus.Succeeded)
            {
                transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
            }
        }
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

            string protocol    = configuration.GetSetting("protocol");
            string msgtype     = configuration.GetSetting("msgtype");
            string merchant    = paymentSystem.Username;
            string language    = this.Language(Sitecore.Context.Language.Name);
            string ordernumber = paymentArgs.ShoppingCart.OrderNumber;
            string amount      = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents();
            string callbackurl = paymentArgs.PaymentUrls.ReturnPageUrl;
            string currency    = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
            string continueurl = paymentArgs.PaymentUrls.ReturnPageUrl;
            string cancelurl   = continueurl + PaymentConstants.CancelQueryString;
            string description = paymentArgs.Description;
            string ipaddress   = HttpContext.Current.Request.UserHostAddress;
            string testmode    = configuration.GetSetting("testmode");
            string autocapture = configuration.GetSetting("autocapture");
            string secret      = paymentSystem.Password;

            string tohash = string.Concat(protocol, msgtype, merchant, language, ordernumber, amount, currency, continueurl, cancelurl, callbackurl, autocapture, description, ipaddress, testmode, secret);
            string hash   = this.GetMD5Hash(tohash);

            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SaveStartValues(ordernumber, amount, currency, paymentSystem.Code);

            NameValueCollection data = new NameValueCollection
            {
                { "protocol", protocol },
                { "msgtype", msgtype },
                { "merchant", merchant },
                { "language", language },
                { "ordernumber", ordernumber },
                { "amount", amount },
                { "currency", currency },
                { "continueurl", continueurl },
                { "cancelurl", cancelurl },
                { "callbackurl", callbackurl },
                { "autocapture", autocapture },
                { "description", description },
                { "ipaddress", ipaddress },
                { "testmode", testmode },
                { "md5check", hash },
            };

            this.PostData(paymentSystem.PaymentUrl, data);
        }
Example #11
0
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

            string merchantId         = paymentSystem.Username;
            string ordernumber        = paymentArgs.ShoppingCart.OrderNumber;
            string amount             = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents();
            string currency           = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
            string key1               = configuration.GetSetting("key1");
            string key2               = configuration.GetSetting("key2");
            string concatanatedString = string.Format("merchant={0}&orderid={1}&currency={2}&amount={3}", merchantId, ordernumber, currency, amount);

            string acceptUrl = paymentArgs.PaymentUrls.ReturnPageUrl;
            string cancelUrl = acceptUrl + PaymentConstants.CancelQueryString;

            NameValueCollection data = new NameValueCollection
            {
                { "merchant", paymentSystem.Username },
                { "amount", amount },
                { "currency", currency },
                { "orderid", ordernumber },
                { "accepturl", acceptUrl },
                { "cancelurl", cancelUrl },
                { "ip", HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] },
                { "lang", this.Language(Sitecore.Context.Language.Name) },
                { "ordertext", paymentArgs.Description },
                { "delivery1.Navn", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.Name },
                { "delivery2.Adresse", paymentArgs.ShoppingCart.CustomerInfo.BillingAddress.Address },
                { "delivery3.Kommentar", string.Empty },
                { "md5key", this.CalculateMd5Key(key1, key2, concatanatedString) },
            };

            data.Add(configuration.GetProviderSettings(this.CustomSettings));

            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SaveStartValues(ordernumber, amount, currency, paymentSystem.Code);

            this.PostData(paymentSystem.PaymentUrl, data);
        }
Example #12
0
        /// <summary>
        /// Captures the payment
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        /// <param name="reservationTicket">The reservation ticket.</param>
        /// <param name="amount">The amount.</param>
        public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.ArgumentNotNull(reservationTicket, "reservationTicket");

            Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero");
            Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

            string key1 = configuration.GetSetting("key1");
            string key2 = configuration.GetSetting("key2");
            string url  = configuration.GetSetting("captureUrl");

            string merchant = paymentSystem.Username;
            string password = paymentSystem.Password;

            string       orderId     = reservationTicket.InvoiceNumber;
            string       transact    = reservationTicket.TransactionNumber;
            string       amountInput = amount.ToCents();
            const string Textreply   = "yes";
            const string Fullreply   = "yes";

            string forHash = string.Format("merchant={0}&orderid={1}&transact={2}&amount={3}", merchant, orderId, transact, amountInput);
            string md5Key  = this.CalculateMd5Key(key1, key2, forHash);

            NameValueCollection data = new NameValueCollection
            {
                { "merchant", merchant },
                { "orderid", orderId },
                { "transact", transact },
                { "amount", amountInput },
                { "md5key", md5Key },
                { "textreply", Textreply },
                { "fullreply", Fullreply },
            };

            NameValueCollection result = new NameValueCollection();
            ITransactionData    transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SavePersistentValue(orderId, this.SendRequest(merchant, password, url, data, ref result) ? PaymentConstants.CaptureSuccess : string.Format("UnCaptured. Reason={0}", result["reason"]));
        }
        /// <summary>
        /// Cancels the payment reservation.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        /// <param name="reservationTicket">The reservation ticket.</param>
        public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.ArgumentNotNull(reservationTicket, "reservationTicket");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);
            bool isTest;

            Boolean.TryParse(configuration.GetSetting("x_test_request"), out isTest);
            var request = new VoidRequest(reservationTicket.TransactionNumber);
            var gate    = new Gateway(paymentSystem.Username, paymentSystem.Password, isTest);

            var response = gate.Send(request);

            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, response.Approved ? PaymentConstants.CancelSuccess : response.Message);
        }
Example #14
0
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment Args.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.IsNotNull(paymentSystem, "Payment method is null");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

            string amount          = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents();
            string currency        = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
            string orderid         = paymentArgs.ShoppingCart.OrderNumber;
            string password        = paymentSystem.Password;
            string encryptedString = Crypto.GetMD5Hash(String.Concat(currency, amount, orderid, password));

            string merchantnumber = paymentSystem.Username;
            string acceptUrl      = paymentArgs.PaymentUrls.ReturnPageUrl;
            string declineUrl     = acceptUrl + PaymentConstants.CancelQueryString;
            string language       = this.Language(Sitecore.Context.Language.Name);

            NameValueCollection data = new NameValueCollection
            {
                { "merchantnumber", merchantnumber },
                { "amount", amount },
                { "currency", currency },
                { "orderid", orderid },
                { "accepturl", acceptUrl },
                { "declineurl", declineUrl },
                { "language", language },
                { "ordretext", paymentArgs.Description },
                { "description", paymentArgs.Description },
                { "MD5Key", encryptedString },
            };

            data.Add(configuration.GetProviderSettings());

            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SaveStartValues(orderid, amount, currency, paymentSystem.Code);
            transactionDataProvider.SavePersistentValue(orderid, TransactionConstants.TotalAmount, amount);

            this.PostData(paymentSystem.PaymentUrl, data);
        }
        /// <summary>
        /// Captures the payment
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment args.</param>
        /// <param name="reservationTicket">The reservation ticket.</param>
        /// <param name="amount">The amount.</param>
        public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.ArgumentNotNull(reservationTicket, "reservationTicket");

            Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero");
            Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);
            bool isTest;

            Boolean.TryParse(configuration.GetSetting("x_test_request"), out isTest);
            var request = new CaptureRequest(amount, reservationTicket.TransactionNumber, reservationTicket.AuthorizationCode);
            var gate    = new Gateway(paymentSystem.Username, paymentSystem.Password, isTest);

            var response = gate.Send(request);

            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, response.Approved ? PaymentConstants.CaptureSuccess : response.Message);
        }
Example #16
0
        /// <summary>
        /// Cancels the payment
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        /// <param name="reservationTicket">The reservation ticket.</param>
        public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.ArgumentNotNull(reservationTicket, "reservationTicket");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

            string key1 = configuration.GetSetting("key1");
            string key2 = configuration.GetSetting("key2");
            string url  = configuration.GetSetting("cancelReservationUrl");

            string merchant = paymentSystem.Username;
            string password = paymentSystem.Password;

            string       orderId   = reservationTicket.InvoiceNumber;
            string       transact  = reservationTicket.TransactionNumber;
            const string Textreply = "yes";
            const string Fullreply = "yes";

            string forHash = string.Format("merchant={0}&orderid={1}&transact={2}", merchant, orderId, transact);
            string md5Key  = this.CalculateMd5Key(key1, key2, forHash);

            NameValueCollection data = new NameValueCollection
            {
                { "merchant", merchant },
                { "orderid", orderId },
                { "transact", transact },
                { "md5key", md5Key },
                { "textreply", Textreply },
                { "fullreply", Fullreply },
            };

            NameValueCollection result = new NameValueCollection();
            ITransactionData    transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            transactionDataProvider.SavePersistentValue(orderId, this.SendRequest(merchant, password, url, data, ref result) ? PaymentConstants.CancelSuccess : string.Format("UnCanceled. Reason={0}", result["reason"]));
        }
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
              Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

              this.PaymentStatus = PaymentStatus.Failure;

              HttpRequest request = HttpContext.Current.Request;
              PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);
              ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();
              string instantcapture = configuration.GetSetting("instantcapture");

              if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse)
              {
            string transactionNumber = request.QueryString["tid"];
            string cardid = request.QueryString["cardid"];
            string currency = request.QueryString["cur"];
            string orderid = request.QueryString["orderid"];
            string amount = request.QueryString["amount"];
            string hashString = request.QueryString["eKey"];
            string date = request.QueryString["date"];

            if (!this.CallBackIsvalid(paymentSystem, paymentArgs, currency, transactionNumber, amount, orderid, hashString, date))
            {
              Log.Error("Callback parameters are invalid.", this);
            }
            else
            {
              this.PaymentStatus = PaymentStatus.Succeeded;
              transactionDataProvider.SaveCallBackValues(orderid, this.PaymentStatus.ToString(), transactionNumber, amount, currency, string.Empty, string.Empty, string.Empty, cardid);

              if (string.Compare(instantcapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0)
              {
            ReservationTicket reservationTicket = new ReservationTicket
            {
              InvoiceNumber = orderid,
              AuthorizationCode = hashString,
              TransactionNumber = transactionNumber,
              Amount = amount.FromCents()
            };
            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
              }
            }
              }
              else
              {
            this.PaymentStatus = PaymentStatus.Canceled;
              }

              if (this.PaymentStatus != PaymentStatus.Succeeded)
              {
            transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
              }
        }
Example #18
0
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.IsNotNull(paymentSystem, "Payment method is null");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

            string merchantId         = paymentSystem.Username;
            string token              = paymentSystem.Password;
            string amount             = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents();
            string currencyCode       = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
            string orderNumber        = paymentArgs.ShoppingCart.OrderNumber;
            string redirectUrl        = paymentArgs.PaymentUrls.ReturnPageUrl;
            string paymentSystemCode  = paymentSystem.Code;
            string webServicePlatform = configuration.GetSetting("webServicePlatform");
            string language           = configuration.GetSetting("language");

            RegisterRequest request = new RegisterRequest
            {
                Order = new Order
                {
                    Amount       = amount,
                    OrderNumber  = orderNumber,
                    CurrencyCode = currencyCode
                },
                Terminal = new Terminal
                {
                    Language    = language,
                    RedirectUrl = redirectUrl
                },
                Environment = new Services.Environment
                {
                    WebServicePlatform = webServicePlatform
                }
            };

            Netaxept client = new Netaxept();

            try
            {
                RegisterResponse    response = client.Register(merchantId, token, request);
                NameValueCollection data     = new NameValueCollection
                {
                    { "MerchantID", merchantId },
                    { "TransactionID", response.TransactionId }
                };

                ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
                transactionDataProvider.SaveStartValues(orderNumber, amount, currencyCode, paymentSystemCode);

                this.PostData(paymentSystem.PaymentUrl, data);
            }
            catch (Exception exception)
            {
                Log.Error(exception.Message, this);
                HttpContext.Current.Session["paymentErrorMessage"] = exception.Message;
                HttpContext.Current.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl, false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
        }
Example #19
0
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            this.PaymentStatus = PaymentStatus.Failure;

            HttpRequest           request                 = HttpContext.Current.Request;
            PaymentSettingsReader configuration           = new PaymentSettingsReader(paymentSystem);
            ITransactionData      transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
            string operation = configuration.GetSetting("operation");

            string transactionId = request.QueryString["transactionId"];
            string responseCode  = request.QueryString["responseCode"];

            if (string.Compare(responseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0)
            {
                string  merchantId  = paymentSystem.Username;
                string  token       = paymentSystem.Password;
                string  orderNumber = paymentArgs.ShoppingCart.OrderNumber;
                decimal amount      = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat;
                string  currency    = this.Currency(paymentArgs.ShoppingCart.Currency.Code);

                Netaxept       client         = new Netaxept();
                ProcessRequest processRequest = new ProcessRequest
                {
                    Operation     = operation,
                    TransactionId = transactionId
                };
                try
                {
                    ProcessResponse processResponse = client.Process(merchantId, token, processRequest);
                    if (string.Compare(processResponse.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.PaymentStatus = PaymentStatus.Succeeded;
                        transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), transactionId, amount.ToString(), currency, string.Empty, string.Empty, string.Empty, string.Empty);

                        if (string.Compare(operation, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            ReservationTicket reservationTicket = new ReservationTicket
                            {
                                Amount            = amount,
                                AuthorizationCode = processResponse.AuthorizationId,
                                InvoiceNumber     = orderNumber,
                                TransactionNumber = transactionId
                            };
                            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error(exception.Message, exception, this);
                }
            }
            else if (string.Compare(responseCode, "CANCEL", StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.PaymentStatus = PaymentStatus.Canceled;
            }

            if (this.PaymentStatus != PaymentStatus.Succeeded)
            {
                transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
            }
        }
        /// <summary>
        /// Performs the completion of the conversation with PayPal.
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="orderRef">The order ref.</param>
        /// <param name="accountNumber">The account number.</param>
        /// <param name="hash">The hash.</param>
        /// <param name="transactionDataProvider">The transaction data provider.</param>
        protected void CompleteCallback(PaymentSystem paymentSystem, string orderRef, long accountNumber, string hash, ITransactionData transactionDataProvider)
        {
            PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);
              string purchaseOperation = configuration.GetSetting("purchaseOperation");
              PaymentStatus paymentStatusResult = PaymentStatus.Failure;

              PxOrder payexOrder = new PxOrder();
              string xmlReturn = payexOrder.Complete(accountNumber, orderRef, hash);

              string transactionNumber = this.ParseRes(xmlReturn, "/payex/transactionNumber");
              string orderNumber = this.ParseRes(xmlReturn, "/payex/orderId");
              string transactionAmount = this.ParseRes(xmlReturn, "/payex/amount");
              string errorCode = this.ParseRes(xmlReturn, "/payex/status/errorCode");
              int transactionStatus = int.Parse(this.ParseRes(xmlReturn, "/payex/transactionStatus"));

              if (errorCode == "OK")
              {
            switch (transactionStatus)
            {
              case (int)TransactionStatus.Sale:
              case (int)TransactionStatus.Authorize:
              {
            paymentStatusResult = PaymentStatus.Succeeded;
            transactionDataProvider.SaveCallBackValues(orderNumber, paymentStatusResult.ToString(), transactionNumber, transactionAmount, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);

            if (string.Compare(purchaseOperation, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0)
            {
              decimal amount = transactionAmount.FromCents();
              ReservationTicket reservationTicket = new ReservationTicket
              {
                InvoiceNumber = orderNumber,
                AuthorizationCode = PaymentConstants.EmptyAuthorizationCode,
                TransactionNumber = transactionNumber,
                Amount = amount
              };
              transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
            }

            break;
              }

              default:
              {
            string transactionErrorCode = this.ParseRes(xmlReturn, "/payex/errorDetails/transactionErrorCode");
            if (transactionErrorCode == OperationCanceledError)
            {
              paymentStatusResult = PaymentStatus.Canceled;
            }

            break;
              }
            }
              }

              this.PaymentStatus = paymentStatusResult;
        }
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment Args.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.IsNotNull(paymentSystem, "Payment system is null");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
              Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

              ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();
              PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

              long accountNumber = TypeUtil.TryParse<long>(paymentSystem.Username, 0);
              string purchaseOperation = configuration.GetSetting("purchaseOperation");
              int price = int.Parse(paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents());
              int shippingPrice = int.Parse(paymentArgs.ShoppingCart.ShippingPrice.ToCents());
              string priceArgList = string.Empty;

              string currency = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
              const int Vat = 0;
              string orderID = paymentArgs.ShoppingCart.OrderNumber;
              string productNumber = paymentArgs.ShoppingCart.ShoppingCartLines.Aggregate(string.Empty, (accumulator, next) => string.Format("{0}, {1}", accumulator, next.Product.Code)).Trim().TrimStart(',');
              string description = paymentArgs.Description;
              string clientIpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
              string clientIdentifier = configuration.GetSetting("clientIdentifier");
              string additionalValues = configuration.GetSetting("additionalValues");
              string externalID = configuration.GetSetting("externalID");
              string returnUrl = paymentArgs.PaymentUrls.ReturnPageUrl;
              string cancelUrl = returnUrl + PaymentConstants.CancelQueryString;
              string view = configuration.GetSetting("view");
              string agreementRef = configuration.GetSetting("agreementRef");
              string clientLanguage = this.Language(Sitecore.Context.Language.Name);
              string encryptionKey = paymentSystem.Password;

              ArrayList param = new ArrayList
              {
            accountNumber.ToString(),
            purchaseOperation,
            price,
            priceArgList,
            currency,
            Vat,
            orderID,
            productNumber,
            description,
            clientIpAddress,
            clientIdentifier,
            additionalValues,
            externalID,
            returnUrl,
            view,
            agreementRef,
            cancelUrl,
            clientLanguage,
            encryptionKey
              };
              string hash = this.CreateMD5Hash(param);

              PxOrder order = new PxOrder();
              string xmlReturn = order.Initialize7(accountNumber, purchaseOperation, price, priceArgList, currency, Vat, orderID, productNumber, description, clientIpAddress, clientIdentifier, additionalValues, externalID, returnUrl, view, agreementRef, cancelUrl, clientLanguage, hash);

              string redirectUrl = this.ParseRes(xmlReturn, "/payex/redirectUrl");
              string orderRef = this.ParseRes(xmlReturn, "/payex/orderRef");
              int itemNumber = 1;
              string mainErrorDescription = this.ParseRes(xmlReturn, "/payex/status/description");
              List<string> errorCodes = new List<string>
              {
            this.ParseRes(xmlReturn, "/payex/status/errorCode"),
            mainErrorDescription,
            this.PrepareOrderLine(
              order,
              accountNumber,
              orderRef,
              itemNumber++.ToString(),
              description,
              paymentArgs.ShoppingCart.ShoppingCartLines.Count,
              price - shippingPrice,
              int.Parse(paymentArgs.ShoppingCart.Totals.TotalVat.ToCents()),
              int.Parse(paymentArgs.ShoppingCart.Totals.VAT.ToCents()) * 100,
              encryptionKey),
            this.PrepareOrderLine(
              order,
              accountNumber,
              orderRef,
              itemNumber++.ToString(),
              "Shipping price",
              1,
              shippingPrice,
              0,
              0,
              encryptionKey)
              };

              if (errorCodes.TrueForAll(x => x == "OK"))
              {
            transactionDataProvider.SaveStartValues(orderID, price.ToString(), currency, paymentSystem.Code);
              }
              else
              {
            transactionDataProvider.SavePersistentValue(orderID, TransactionConstants.PaymentStatus, PaymentStatus.Failure.ToString());
            redirectUrl = paymentArgs.PaymentUrls.FailurePageUrl;
            HttpContext.Current.Session["paymentErrorMessage"] = mainErrorDescription;
              }

              HttpContext.Current.Response.Redirect(redirectUrl, false);
              HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
              Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

              this.PaymentStatus = PaymentStatus.Failure;

              HttpRequest request = HttpContext.Current.Request;
              PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);
              ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();
              string operation = configuration.GetSetting("operation");

              string transactionId = request.QueryString["transactionId"];
              string responseCode = request.QueryString["responseCode"];

              if (string.Compare(responseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0)
              {
            string merchantId = paymentSystem.Username;
            string token = paymentSystem.Password;
            string orderNumber = paymentArgs.ShoppingCart.OrderNumber;
            decimal amount = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat;
            string currency = this.Currency(paymentArgs.ShoppingCart.Currency.Code);

            Netaxept client = new Netaxept();
            ProcessRequest processRequest = new ProcessRequest
            {
              Operation = operation,
              TransactionId = transactionId
            };
            try
            {
              ProcessResponse processResponse = client.Process(merchantId, token, processRequest);
              if (string.Compare(processResponse.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0)
              {
            this.PaymentStatus = PaymentStatus.Succeeded;
            transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), transactionId, amount.ToString(), currency, string.Empty, string.Empty, string.Empty, string.Empty);

            if (string.Compare(operation, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0)
            {
              ReservationTicket reservationTicket = new ReservationTicket
              {
                Amount = amount,
                AuthorizationCode = processResponse.AuthorizationId,
                InvoiceNumber = orderNumber,
                TransactionNumber = transactionId
              };
              transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
            }
              }
            }
            catch (Exception exception)
            {
              Log.Error(exception.Message, exception, this);
            }
              }
              else if (string.Compare(responseCode, "CANCEL", StringComparison.OrdinalIgnoreCase) == 0)
              {
            this.PaymentStatus = PaymentStatus.Canceled;
              }

              if (this.PaymentStatus != PaymentStatus.Succeeded)
              {
            transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
              }
        }
        /// <summary>
        /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters
        /// that is returned from the payment provider.
        /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage.
        /// This information is important and used in the GetPaymentStatus().
        /// </summary>
        /// <param name="paymentSystem">The payment system.</param>
        /// <param name="paymentArgs">The payment args.</param>
        public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
              Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

              this.PaymentStatus = PaymentStatus.Failure;

              HttpRequest request = HttpContext.Current.Request;
              ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();
              PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);
              string autocapture = configuration.GetSetting("autocapture");

              if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse)
              {
            string xmlReturn = this.CheckStatus(paymentSystem, paymentArgs);
            if (!string.IsNullOrEmpty(xmlReturn))
            {
              var quickPayResponse = this.ParseResult(xmlReturn);
              string secret = paymentSystem.Password;
              string tohash = string.Join(string.Empty, quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) + secret;

              string md5Check = this.GetMD5Hash(tohash);
              if (md5Check.Equals(quickPayResponse["md5check"]) && quickPayResponse["qpstat"].Equals("000"))
              {
            this.PaymentStatus = PaymentStatus.Succeeded;
            transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), quickPayResponse["transaction"], quickPayResponse["amount"], quickPayResponse["currency"], string.Empty, string.Empty, string.Empty, quickPayResponse["cardtype"]);
            if (string.Compare(autocapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0)
            {
              string transactionAmount = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TotalAmount) as string;
              string orderNumber = paymentArgs.ShoppingCart.OrderNumber;
              string transactionNumber = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TransactionNumber) as string;

              decimal amount = transactionAmount.FromCents();
              ReservationTicket reservationTicket = new ReservationTicket
              {
                InvoiceNumber = orderNumber,
                AuthorizationCode = PaymentConstants.EmptyAuthorizationCode,
                TransactionNumber = transactionNumber,
                Amount = amount
              };
              transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket);
            }
              }
            }
              }
              else
              {
            this.PaymentStatus = PaymentStatus.Canceled;
              }

              if (this.PaymentStatus != PaymentStatus.Succeeded)
              {
            transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
              }
        }
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.IsNotNull(paymentSystem, "Payment method is null");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
              Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

              PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

              string merchantId = paymentSystem.Username;
              string token = paymentSystem.Password;
              string amount = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents();
              string currencyCode = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
              string orderNumber = paymentArgs.ShoppingCart.OrderNumber;
              string redirectUrl = paymentArgs.PaymentUrls.ReturnPageUrl;
              string paymentSystemCode = paymentSystem.Code;
              string webServicePlatform = configuration.GetSetting("webServicePlatform");
              string language = configuration.GetSetting("language");

              RegisterRequest request = new RegisterRequest
              {
            Order = new Order
            {
              Amount = amount,
              OrderNumber = orderNumber,
              CurrencyCode = currencyCode
            },
            Terminal = new Terminal
            {
              Language = language,
              RedirectUrl = redirectUrl
            },
            Environment = new Services.Environment
            {
              WebServicePlatform = webServicePlatform
            }
              };

              Netaxept client = new Netaxept();

              try
              {
            RegisterResponse response = client.Register(merchantId, token, request);
            NameValueCollection data = new NameValueCollection
              {
            { "MerchantID", merchantId },
            { "TransactionID", response.TransactionId }
              };

            ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();
            transactionDataProvider.SaveStartValues(orderNumber, amount, currencyCode, paymentSystemCode);

            this.PostData(paymentSystem.PaymentUrl, data);
              }
              catch (Exception exception)
              {
            Log.Error(exception.Message, this);
            HttpContext.Current.Session["paymentErrorMessage"] = exception.Message;
            HttpContext.Current.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl, false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
              }
        }
        protected virtual string CheckStatus([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");

              var configuration = new PaymentSettingsReader(paymentSystem);
              string protocolInput = configuration.GetSetting("protocol");
              const string MsgtypeInput = "status";
              string merchantInput = paymentSystem.Username;
              string ordernumberInput = paymentArgs.ShoppingCart.OrderNumber;
              string secretInput = paymentSystem.Password;
              string apiUrl = configuration.GetSetting("apiURL");

              string tohashInput = string.Concat(protocolInput, MsgtypeInput, merchantInput, ordernumberInput, secretInput);
              string hashInput = this.GetMD5Hash(tohashInput);
              string requestString = string.Format(
            "protocol={0}&msgtype={1}&merchant={2}&ordernumber={3}&md5check={4}",
            protocolInput,
            MsgtypeInput,
            paymentSystem.Username,
            ordernumberInput,
            hashInput);

              string information = string.Empty;
              return this.SendRequest(apiUrl, requestString, ref information);
        }
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment Args.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.IsNotNull(paymentSystem, "Payment method is null");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
              Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

              PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

              string amount = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents();
              string currency = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
              string orderid = paymentArgs.ShoppingCart.OrderNumber;
              string password = paymentSystem.Password;
              string encryptedString = Crypto.GetMD5Hash(String.Concat(currency, amount, orderid, password));

              string merchantnumber = paymentSystem.Username;
              string acceptUrl = paymentArgs.PaymentUrls.ReturnPageUrl;
              string declineUrl = acceptUrl + PaymentConstants.CancelQueryString;
              string language = this.Language(Sitecore.Context.Language.Name);

              NameValueCollection data = new NameValueCollection
              {
            { "merchantnumber", merchantnumber },
            { "amount", amount },
            { "currency", currency },
            { "orderid", orderid },
            { "accepturl", acceptUrl },
            { "declineurl", declineUrl },
            { "language", language },
            { "ordretext", paymentArgs.Description },
            { "description", paymentArgs.Description },
            { "MD5Key", encryptedString },
              };

              data.Add(configuration.GetProviderSettings());

              ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();
              transactionDataProvider.SaveStartValues(orderid, amount, currency, paymentSystem.Code);
              transactionDataProvider.SavePersistentValue(orderid, TransactionConstants.TotalAmount, amount);

              this.PostData(paymentSystem.PaymentUrl, data);
        }
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.ArgumentNotNull(paymentSystem, "paymentSystem");
              Assert.ArgumentNotNull(paymentArgs, "paymentArgs");

              PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem);

              string protocol = configuration.GetSetting("protocol");
              string msgtype = configuration.GetSetting("msgtype");
              string merchant = paymentSystem.Username;
              string language = this.Language(Sitecore.Context.Language.Name);
              string ordernumber = paymentArgs.ShoppingCart.OrderNumber;
              string amount = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents();
              string callbackurl = paymentArgs.PaymentUrls.ReturnPageUrl;
              string currency = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
              string continueurl = paymentArgs.PaymentUrls.ReturnPageUrl;
              string cancelurl = continueurl + PaymentConstants.CancelQueryString;
              string description = paymentArgs.Description;
              string ipaddress = HttpContext.Current.Request.UserHostAddress;
              string testmode = configuration.GetSetting("testmode");
              string autocapture = configuration.GetSetting("autocapture");
              string secret = paymentSystem.Password;

              string tohash = string.Concat(protocol, msgtype, merchant, language, ordernumber, amount, currency, continueurl, cancelurl, callbackurl, autocapture, description, ipaddress, testmode, secret);
              string hash = this.GetMD5Hash(tohash);

              ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>();
              transactionDataProvider.SaveStartValues(ordernumber, amount, currency, paymentSystem.Code);

              NameValueCollection data = new NameValueCollection
              {
            { "protocol", protocol },
            { "msgtype", msgtype },
            { "merchant", merchant },
            { "language", language },
            { "ordernumber", ordernumber },
            { "amount", amount },
            { "currency", currency },
            { "continueurl", continueurl },
            { "cancelurl", cancelurl },
            { "callbackurl", callbackurl },
            { "autocapture", autocapture },
            { "description", description },
            { "ipaddress", ipaddress },
            { "testmode", testmode },
            { "md5check", hash },
              };

              this.PostData(paymentSystem.PaymentUrl, data);
        }
        /// <summary>
        /// Begins the payment.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment Args.</param>
        public override void Invoke([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs)
        {
            Assert.IsNotNull(paymentSystem, "Payment system is null");
            Assert.ArgumentNotNull(paymentArgs, "paymentArgs");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");

            ITransactionData      transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
            PaymentSettingsReader configuration           = new PaymentSettingsReader(paymentSystem);

            long   accountNumber     = TypeUtil.TryParse <long>(paymentSystem.Username, 0);
            string purchaseOperation = configuration.GetSetting("purchaseOperation");
            int    price             = int.Parse(paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToCents());
            int    shippingPrice     = int.Parse(paymentArgs.ShoppingCart.ShippingPrice.ToCents());
            string priceArgList      = string.Empty;

            string    currency         = this.Currency(paymentArgs.ShoppingCart.Currency.Code);
            const int Vat              = 0;
            string    orderID          = paymentArgs.ShoppingCart.OrderNumber;
            string    productNumber    = paymentArgs.ShoppingCart.ShoppingCartLines.Aggregate(string.Empty, (accumulator, next) => string.Format("{0}, {1}", accumulator, next.Product.Code)).Trim().TrimStart(',');
            string    description      = paymentArgs.Description;
            string    clientIpAddress  = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            string    clientIdentifier = configuration.GetSetting("clientIdentifier");
            string    additionalValues = configuration.GetSetting("additionalValues");
            string    externalID       = configuration.GetSetting("externalID");
            string    returnUrl        = paymentArgs.PaymentUrls.ReturnPageUrl;
            string    cancelUrl        = returnUrl + PaymentConstants.CancelQueryString;
            string    view             = configuration.GetSetting("view");
            string    agreementRef     = configuration.GetSetting("agreementRef");
            string    clientLanguage   = this.Language(Sitecore.Context.Language.Name);
            string    encryptionKey    = paymentSystem.Password;

            ArrayList param = new ArrayList
            {
                accountNumber.ToString(),
                      purchaseOperation,
                      price,
                      priceArgList,
                      currency,
                      Vat,
                      orderID,
                      productNumber,
                      description,
                      clientIpAddress,
                      clientIdentifier,
                      additionalValues,
                      externalID,
                      returnUrl,
                      view,
                      agreementRef,
                      cancelUrl,
                      clientLanguage,
                      encryptionKey
            };
            string hash = this.CreateMD5Hash(param);

            PxOrder order     = new PxOrder();
            string  xmlReturn = order.Initialize7(accountNumber, purchaseOperation, price, priceArgList, currency, Vat, orderID, productNumber, description, clientIpAddress, clientIdentifier, additionalValues, externalID, returnUrl, view, agreementRef, cancelUrl, clientLanguage, hash);

            string        redirectUrl          = this.ParseRes(xmlReturn, "/payex/redirectUrl");
            string        orderRef             = this.ParseRes(xmlReturn, "/payex/orderRef");
            int           itemNumber           = 1;
            string        mainErrorDescription = this.ParseRes(xmlReturn, "/payex/status/description");
            List <string> errorCodes           = new List <string>
            {
                this.ParseRes(xmlReturn, "/payex/status/errorCode"),
                mainErrorDescription,
                this.PrepareOrderLine(
                    order,
                    accountNumber,
                    orderRef,
                    itemNumber++.ToString(),
                    description,
                    paymentArgs.ShoppingCart.ShoppingCartLines.Count,
                    price - shippingPrice,
                    int.Parse(paymentArgs.ShoppingCart.Totals.TotalVat.ToCents()),
                    int.Parse(paymentArgs.ShoppingCart.Totals.VAT.ToCents()) * 100,
                    encryptionKey),
                this.PrepareOrderLine(
                    order,
                    accountNumber,
                    orderRef,
                    itemNumber++.ToString(),
                    "Shipping price",
                    1,
                    shippingPrice,
                    0,
                    0,
                    encryptionKey)
            };

            if (errorCodes.TrueForAll(x => x == "OK"))
            {
                transactionDataProvider.SaveStartValues(orderID, price.ToString(), currency, paymentSystem.Code);
            }
            else
            {
                transactionDataProvider.SavePersistentValue(orderID, TransactionConstants.PaymentStatus, PaymentStatus.Failure.ToString());
                redirectUrl = paymentArgs.PaymentUrls.FailurePageUrl;
                HttpContext.Current.Session["paymentErrorMessage"] = mainErrorDescription;
            }

            HttpContext.Current.Response.Redirect(redirectUrl, false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }