コード例 #1
0
        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));
        }
コード例 #2
0
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public virtual void Process(PipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            ShoppingCart    shoppingCart    = Context.Entity.GetInstance <ShoppingCart>();
            PaymentProvider paymentProvider = Context.Entity.Resolve <PaymentProvider>(shoppingCart.PaymentSystem.Code);

            PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver();
            PaymentArgs        paymentArgs        = new PaymentArgs
            {
                ShoppingCart = shoppingCart,
                PaymentUrls  = paymentUrlResolver.Resolve(),
            };

            StringBuilder description = new StringBuilder();

            foreach (ShoppingCartLine shoppingCartLine in shoppingCart.ShoppingCartLines)
            {
                description.Append(shoppingCartLine.Product.Title);
                description.Append(", ");
            }

            paymentArgs.Description = description.ToString().Trim().TrimEnd(',');

            paymentProvider.Invoke(shoppingCart.PaymentSystem, paymentArgs);

            args.AbortPipeline();
        }
コード例 #3
0
        /// <summary>
        /// Processes the specified order.
        /// </summary>
        /// <typeparam name="T">The order type.</typeparam>
        /// <param name="order">The order instance.</param>
        /// <exception cref="InvalidTypeException">The provider doesn't implement IReservable interface.</exception>
        protected override void Process <T>(T order)
        {
            bool cancelSuccess = false;
            ReservationTicket reservationTicket = new ReservationTicket(order);
            PaymentArgs       paymentArgs       = new PaymentArgs();

            PaymentProvider paymentProvider    = Context.Entity.Resolve <PaymentProvider>(order.PaymentSystem.Code);
            IReservable     reservableProvider = paymentProvider as IReservable;

            if (reservableProvider != null)
            {
                reservableProvider.CancelReservation(order.PaymentSystem, paymentArgs, reservationTicket);

                ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();
                string           result = transactionDataProvider.GetPersistentValue(order.OrderNumber) as string;

                if (string.Compare(result, "Canceled", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    cancelSuccess = true;
                }
            }

            if (!cancelSuccess)
            {
                order.Status = Context.Entity.Resolve <OrderStatus>("Processing");
                IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >();
                orderManager.SaveOrder(order);
            }

            if (reservableProvider == null)
            {
                throw new InvalidTypeException("The provider doesn't implement IReservable interface.");
            }
        }
コード例 #4
0
        /// <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");

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

            long   accountNumber     = TypeUtil.TryParse <long>(paymentSystem.Username, 0);
            int    transactionNumber = int.Parse(reservationTicket.TransactionNumber);
            string encryptionKey     = paymentSystem.Password;

            ArrayList param = new ArrayList
            {
                accountNumber,
                transactionNumber,
                encryptionKey
            };
            string hash = this.CreateMD5Hash(param);

            PxOrder order       = new PxOrder();
            string  xmlReturn   = order.Cancel2(accountNumber, transactionNumber, hash);
            string  errorCode   = this.ParseRes(xmlReturn, "/payex/status/errorCode");
            string  description = this.ParseRes(xmlReturn, "/payex/status/description");

            if (errorCode == "OK" && description == "OK")
            {
                transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.CancelSuccess);
            }
            else
            {
                transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, string.Format("errorCode={0} description={1}", errorCode, description));
            }
        }
コード例 #5
0
    /// <summary>
    /// Processes the specified arguments.
    /// </summary>
    /// <param name="args">The arguments.</param>
    public virtual void Process(PipelineArgs args)
    {
      Assert.ArgumentNotNull(args, "args");

      ShoppingCart shoppingCart = Context.Entity.GetInstance<ShoppingCart>();
      PaymentProvider paymentProvider = Context.Entity.Resolve<PaymentProvider>(shoppingCart.PaymentSystem.Code);

      PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver();
      PaymentArgs paymentArgs = new PaymentArgs
      {
        ShoppingCart = shoppingCart,
        PaymentUrls = paymentUrlResolver.Resolve(),
      };

      StringBuilder description = new StringBuilder();
      foreach (ShoppingCartLine shoppingCartLine in shoppingCart.ShoppingCartLines)
      {
        description.Append(shoppingCartLine.Product.Title);
        description.Append(", ");
      }

      paymentArgs.Description = description.ToString().Trim().TrimEnd(',');

      paymentProvider.Invoke(shoppingCart.PaymentSystem, paymentArgs);

      args.AbortPipeline();
    }
コード例 #6
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");

            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);
        }
コード例 #7
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");

            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);
        }
コード例 #8
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;
            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());
            }
        }
コード例 #9
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());
            }
        }
コード例 #10
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;
            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());
            }
        }
コード例 #11
0
        /// <summary>
        /// Calls the back isvalid.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment Args.</param>
        /// <param name="currency">The currency.</param>
        /// <param name="transactionNumber">The transaction number.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="orderId">The order id.</param>
        /// <param name="hashString">The hash string.</param>
        /// <param name="date">The current date.</param>
        /// <returns>
        /// the back is valid.
        /// </returns>
        protected bool CallBackIsvalid(PaymentSystem paymentSystem, PaymentArgs paymentArgs, string currency, string transactionNumber, string amount, string orderId, string hashString, string date)
        {
            if (string.IsNullOrEmpty(currency) || string.IsNullOrEmpty(transactionNumber) || string.IsNullOrEmpty(amount) || string.IsNullOrEmpty(orderId))
            {
                return(false);
            }

            string currentData = DateTime.Now.ToString("yyyyMMdd");

            return(orderId.Contains(paymentArgs.ShoppingCart.OrderNumber) && currentData.Equals(date));
        }
コード例 #12
0
        public override void InvokePayment()
        {
            PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver();
            PaymentArgs        paymentArgs        = new PaymentArgs
            {
                PaymentUrls  = paymentUrlResolver.Resolve(),
                ShoppingCart = this.ShoppingCart,
                Description  = this.Description
            };

            this.Invoke(this.PaymentSystem, paymentArgs);
        }
コード例 #13
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 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);
        }
コード例 #14
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;
            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());
            }
        }
コード例 #15
0
        /// <summary>
        /// Cancels the 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");

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

            Payment payment      = new Payment();
            int     pbsResponse  = 0;
            bool    deleteResult = payment.delete(int.Parse(paymentSystem.Username), long.Parse(reservationTicket.TransactionNumber), string.Empty, paymentSystem.Password, ref pbsResponse);

            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, deleteResult ? PaymentConstants.CancelSuccess : string.Format("pbsResponse={0}", pbsResponse));
        }
コード例 #16
0
        public virtual void ProcessPaymentCallBack([NotNull] HttpRequest request)
        {
            Assert.ArgumentNotNull(request, "request");

            Assert.IsNotNull(this.ShoppingCart, "Shopping cart is null");

            PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver();
            PaymentArgs        paymentArgs        = new PaymentArgs
            {
                PaymentUrls  = paymentUrlResolver.Resolve(),
                ShoppingCart = this.ShoppingCart,
                Description  = this.Description
            };

            this.ProcessCallback(this.PaymentSystem, paymentArgs);
        }
コード例 #17
0
        /// <summary>Calls the back isvalid.</summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment Args.</param>
        /// <param name="transactionNumber">The transaction number.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="merchant">The merchant.</param>
        /// <param name="orderId">The order id.</param>
        /// <returns>The back isvalid result.</returns>
        protected bool CallBackIsvalid(PaymentSystem paymentSystem, PaymentArgs paymentArgs, string transactionNumber, string amount, string merchant, string orderId)
        {
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");
            bool   result = false;
            string originalTotalAmount = Context.Entity.Resolve <ITransactionData>().GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TotalAmount) as string;
            string originalMerchantId  = paymentSystem.Username;
            string originalOrderId     = paymentArgs.ShoppingCart.OrderNumber;

            if (!string.IsNullOrEmpty(transactionNumber) && !string.IsNullOrEmpty(amount) && !string.IsNullOrEmpty(merchant) && !string.IsNullOrEmpty(orderId))
            {
                result = (!string.IsNullOrEmpty(originalTotalAmount) && amount.Contains(originalTotalAmount)) && merchant.Contains(originalMerchantId) &&
                         orderId.Contains(originalOrderId) && !string.IsNullOrEmpty(transactionNumber);
            }

            return(result);
        }
コード例 #18
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;
            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse)
            {
                string orderRef      = request["orderRef"];
                long   accountNumber = TypeUtil.TryParse <long>(paymentSystem.Username, 0);
                string secretKey     = paymentSystem.Password;

                if (!string.IsNullOrEmpty(orderRef) && accountNumber > 0)
                {
                    ArrayList param = new ArrayList
                    {
                        accountNumber,
                        orderRef,
                        secretKey
                    };
                    string hash = this.CreateMD5Hash(param);
                    try
                    {
                        this.CompleteCallback(paymentSystem, orderRef, accountNumber, hash, transactionDataProvider);
                    }
                    catch (Exception exception)
                    {
                        Log.Warn(exception.Message, exception, this);
                    }
                }
            }
            else
            {
                this.PaymentStatus = PaymentStatus.Canceled;
            }

            if (this.PaymentStatus != PaymentStatus.Succeeded)
            {
                transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString());
            }
        }
コード例 #19
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");

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

            Payment payment       = new Payment();
            int     pbsResponse   = 0;
            int     epayresponse  = 0;
            bool    captureResult = payment.capture(int.Parse(paymentSystem.Username), long.Parse(reservationTicket.TransactionNumber), int.Parse(amount.ToCents()), string.Empty, paymentSystem.Password, ref pbsResponse, ref epayresponse);

            transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, captureResult ? PaymentConstants.CaptureSuccess : string.Format("pbsResponse={0} epayresponse={1}", pbsResponse, epayresponse));
        }
コード例 #20
0
        /// <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);
        }
コード例 #21
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"]));
        }
コード例 #22
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);
        }
コード例 #23
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);
        }
コード例 #24
0
        /// <summary>
        /// Cancels the 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");

            const string     Operation               = "ANNUL";
            string           orderNumber             = reservationTicket.InvoiceNumber;
            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            try
            {
                ProcessResponse processResponse = this.Process(paymentSystem, reservationTicket, reservationTicket.Amount, Operation);
                transactionDataProvider.SavePersistentValue(orderNumber, processResponse.ResponseCode == "OK" ? PaymentConstants.CancelSuccess : processResponse.ResponseText);
            }
            catch (Exception exception)
            {
                Log.Warn(exception.Message, exception, this);
                transactionDataProvider.SavePersistentValue(orderNumber, exception.Message);
            }
        }
コード例 #25
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");

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

            long accountNumber     = TypeUtil.TryParse <long>(paymentSystem.Username, 0);
            int  transactionNumber = int.Parse(reservationTicket.TransactionNumber);
            int  amountInput       = int.Parse(amount.ToCents());

            string encryptionKey = paymentSystem.Password;

            ArrayList param = new ArrayList
            {
                accountNumber,
                transactionNumber,
                amountInput,
                encryptionKey
            };
            string hash = this.CreateMD5Hash(param);

            PxOrder order       = new PxOrder();
            string  xmlReturn   = order.Capture2(accountNumber, transactionNumber, amountInput, hash);
            string  errorCode   = this.ParseRes(xmlReturn, "/payex/status/errorCode");
            string  description = this.ParseRes(xmlReturn, "/payex/status/description");

            if (errorCode == "OK" && description == "OK")
            {
                transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.CaptureSuccess);
            }
            else
            {
                transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, string.Format("errorCode={0} description={1}", errorCode, description));
            }
        }
コード例 #26
0
    /// <summary>
    /// Initializes the payment.</summary>
    /// <param name="paymentSystem">The payment System.</param>
    /// <param name="paymentArgs">The payment arguments.</param>
    public override void Invoke(DomainModel.Payments.PaymentSystem paymentSystem, PaymentArgs paymentArgs)
    {
      Assert.IsNotNull(HttpContext.Current, "Http context is null");

      Assert.IsNotNull(paymentSystem, "Payment system is null");
      Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");
      Assert.IsNotNull(paymentArgs.ShoppingCart.Totals, "Shopping cart totals were not set");
      Assert.IsNotNull(paymentArgs.ShoppingCart.Currency, "Shopping cart currency was not set");
      Assert.IsNotNull(paymentArgs.ShoppingCart.CustomerInfo, "Customer information was not set");
      Assert.IsNotNull(paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress, "Customer shipping address was not set");
      Assert.IsNotNull(paymentArgs.ShoppingCart.CustomerInfo.BillingAddress, "Customer billing address was not set");
      Assert.IsNotNull(paymentArgs.Description, "Description is empty");

      Assert.IsNotNullOrEmpty(paymentSystem.Code, "Payment system code was not set");
      Assert.IsNotNullOrEmpty(paymentSystem.Username, "Payment system user name was not set");
      Assert.IsNotNullOrEmpty(paymentSystem.Password, "Payment system password was not set");
      Assert.IsNotNullOrEmpty(paymentArgs.ShoppingCart.OrderNumber, "Order number was not set");
      Assert.IsNotNullOrEmpty(paymentArgs.PaymentUrls.ReturnPageUrl, "Return page was not set");
      Assert.IsNotNullOrEmpty(paymentSystem.PaymentUrl, "Payment url was not set");

      Assert.IsTrue(paymentArgs.ShoppingCart.Totals.TotalPriceIncVat > 0, "Price is empty");
    }
コード例 #27
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);
            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);
        }
コード例 #28
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"]));
        }
コード例 #29
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");

            const string     Operation               = "CAPTURE";
            string           orderNumber             = reservationTicket.InvoiceNumber;
            ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>();

            try
            {
                ProcessResponse processResponse = this.Process(paymentSystem, reservationTicket, amount, Operation);
                transactionDataProvider.SavePersistentValue(orderNumber, processResponse.ResponseCode == "OK" ? PaymentConstants.CaptureSuccess : processResponse.ResponseText);
            }
            catch (Exception exception)
            {
                Log.Warn(exception.Message, exception, this);
                transactionDataProvider.SavePersistentValue(orderNumber, exception.Message);
            }
        }
コード例 #30
0
 /// <summary>
 /// Invokes the payment.
 /// </summary>
 /// <param name="paymentSystem">The payment system.</param>
 /// <param name="paymentArgs">The payment args.</param>
 public abstract void Invoke(PaymentSystem paymentSystem, PaymentArgs paymentArgs);
コード例 #31
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <exception cref="ValidatorException">Order could not be created.</exception>
        protected void Page_Load(object sender, EventArgs e)
        {
            DomainModel.Carts.ShoppingCart shoppingCart = Sitecore.Ecommerce.Context.Entity.GetInstance<DomainModel.Carts.ShoppingCart>();
              if (string.IsNullOrEmpty(shoppingCart.PaymentSystem.Code))
              {
            return;
              }

              PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver();
              PaymentArgs paymentArgs = new PaymentArgs
              {
            PaymentUrls = paymentUrlResolver.Resolve(),
            ShoppingCart = shoppingCart
              };

              ITransactionData transactionData = Sitecore.Ecommerce.Context.Entity.Resolve<ITransactionData>();

              PaymentProvider paymentProvider = Sitecore.Ecommerce.Context.Entity.Resolve<PaymentProvider>(shoppingCart.PaymentSystem.Code);
              DomainModel.Payments.PaymentSystem paymentSystem = shoppingCart.PaymentSystem;

              try
              {
            paymentProvider.ProcessCallback(paymentSystem, paymentArgs);
              }
              catch (Exception exception)
              {
            IOrderManager<Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>();
            shoppingCart.OrderNumber = orderManager.GenerateOrderNumber();
            transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

            HttpContext.Current.Session["paymentErrorMessage"] = exception.Message;
            this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl);

            return;
              }

              switch (paymentProvider.PaymentStatus)
              {
            case PaymentStatus.Succeeded:
              {
            IOrderManager<Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>();
            Order order = orderManager.CreateOrder(shoppingCart);

            if (order != null)
            {
              // Redirect to order confirmation page
              string orderId = shoppingCart.OrderNumber;
              ICheckOut checkOut = Sitecore.Ecommerce.Context.Entity.Resolve<ICheckOut>();
              if (checkOut is CheckOut)
              {
                ((CheckOut)checkOut).ResetCheckOut();
              }

              if (MainUtil.IsLoggedIn())
              {
                orderId = string.Format("orderid={0}", orderId);
              }
              else
              {
                string encryptKey = Crypto.EncryptTripleDES(orderId, "5dfkjek5");
                orderId = string.Format("key={0}", Uri.EscapeDataString(encryptKey));
              }

              this.StartOrderCreatedPipeline(order.OrderNumber);

              if (!string.IsNullOrEmpty(orderId))
              {
                UrlString url = new UrlString(paymentArgs.PaymentUrls.SuccessPageUrl);
                url.Append(new UrlString(orderId));
                this.Response.Redirect(url.ToString());
              }
            }
            else
            {
              IOrderManager<Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>();
              shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber();
              transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

              HttpContext.Current.Session["paymentErrorMessage"] = "Order could not be created.";
              this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl);
            }

            break;
              }

            case PaymentStatus.Canceled:
              {
            IOrderManager<Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>();
            shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber();
            transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

            HttpContext.Current.Session["paymentErrorMessage"] = "Payment has been aborted by user.";
            this.Response.Redirect(paymentArgs.PaymentUrls.CancelPageUrl);

            break;
              }

            case PaymentStatus.Failure:
              {
            IOrderManager<Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve<IOrderManager<Order>>();
            shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber();
            transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

            this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl);

            break;
              }
              }
        }
コード例 #32
0
 /// <summary>
 /// Invokes the specified payment args.
 /// </summary>
 /// <param name="paymentArgs">The payment args.</param>
 public virtual void Invoke(PaymentArgs paymentArgs)
 {
   this.Invoke(this.PaymentOption, paymentArgs);
 }
コード例 #33
0
 /// <summary>
 /// Processes the callback.
 /// </summary>
 /// <param name="paymentArgs">The payment args.</param>
 public virtual void ProcessCallback(PaymentArgs paymentArgs)
 {
   this.ProcessCallback(this.PaymentOption, paymentArgs);
 }
コード例 #34
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 PaymentStatus.
 /// </summary>
 /// <param name="paymentSystem">The payment system.</param>
 /// <param name="paymentArgs">The payment arguments.</param>
 public abstract void ProcessCallback(PaymentSystem paymentSystem, PaymentArgs paymentArgs);
コード例 #35
0
        /// <summary>
        /// Calls the back isvalid.
        /// </summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment Args.</param>
        /// <param name="currency">The currency.</param>
        /// <param name="transactionNumber">The transaction number.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="orderId">The order id.</param>
        /// <param name="hashString">The hash string.</param>
        /// <param name="date">The current date.</param>
        /// <returns>
        /// the back is valid.
        /// </returns>
        protected bool CallBackIsvalid(PaymentSystem paymentSystem, PaymentArgs paymentArgs, string currency, string transactionNumber, string amount, string orderId, string hashString, string date)
        {
            if (string.IsNullOrEmpty(currency) || string.IsNullOrEmpty(transactionNumber) || string.IsNullOrEmpty(amount) || string.IsNullOrEmpty(orderId))
              {
            return false;
              }

              string currentData = DateTime.Now.ToString("yyyyMMdd");
              return orderId.Contains(paymentArgs.ShoppingCart.OrderNumber) && currentData.Equals(date);
        }
コード例 #36
0
        /// <summary>
        /// Initializes the payment.</summary>
        /// <param name="paymentSystem">The payment System.</param>
        /// <param name="paymentArgs">The payment arguments.</param>
        public override void Invoke(DomainModel.Payments.PaymentSystem paymentSystem, PaymentArgs paymentArgs)
        {
            Assert.IsNotNull(HttpContext.Current, "Http context is null");

            Assert.IsNotNull(paymentSystem, "Payment system is null");
            Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null");
            Assert.IsNotNull(paymentArgs.ShoppingCart.Totals, "Shopping cart totals were not set");
            Assert.IsNotNull(paymentArgs.ShoppingCart.Currency, "Shopping cart currency was not set");
            Assert.IsNotNull(paymentArgs.ShoppingCart.CustomerInfo, "Customer information was not set");
            Assert.IsNotNull(paymentArgs.ShoppingCart.CustomerInfo.ShippingAddress, "Customer shipping address was not set");
            Assert.IsNotNull(paymentArgs.ShoppingCart.CustomerInfo.BillingAddress, "Customer billing address was not set");
            Assert.IsNotNull(paymentArgs.Description, "Description is empty");

            Assert.IsNotNullOrEmpty(paymentSystem.Code, "Payment system code was not set");
            Assert.IsNotNullOrEmpty(paymentSystem.Username, "Payment system user name was not set");
            Assert.IsNotNullOrEmpty(paymentSystem.Password, "Payment system password was not set");
            Assert.IsNotNullOrEmpty(paymentArgs.ShoppingCart.OrderNumber, "Order number was not set");
            Assert.IsNotNullOrEmpty(paymentArgs.PaymentUrls.ReturnPageUrl, "Return page was not set");
            Assert.IsNotNullOrEmpty(paymentSystem.PaymentUrl, "Payment url was not set");

            Assert.IsTrue(paymentArgs.ShoppingCart.Totals.TotalPriceIncVat > 0, "Price is empty");
        }
コード例 #37
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());
            }
        }
コード例 #38
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();
            }
        }