예제 #1
0
        public void GetResponseResultOk(int name)
        {
            var    robokassaApi   = new RobokassaApi(null);
            string responseResult = robokassaApi.GetResponseResultOk(name);

            Assert.That(responseResult, Is.EqualTo("OK" + name));
        }
예제 #2
0
        /// <summary>
        /// Метод вызывается платежной системой после оплаты и после сообщения нам о платеже(см. метод Result <see cref="Result"/>)
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult Success()
        {
            RobokassaApi           robokassaApi  = ApiFactory.GetRobokassaApi(WebSettingsConfig.Instance);
            RobokassaPaymentResult paymentResult = robokassaApi.ProcessSuccess(Request.Params);

            if (paymentResult == null)
            {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PaymentController.Success. PaymentResult is null. Params={0}",
                                            HttpContextHelper.ParamsToString(Request.Params, RobokassaApi.IsValidParamName));
                return(GetFailView());
            }

            var            purchasedGoogsQuery = new PurchasedGoodsQuery();
            PurchasedGoods purchasedGoods      = purchasedGoogsQuery.Get(paymentResult.PaymentId);

            if (purchasedGoods == null)
            {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PaymentController.Success. GetUniqueDownloadId не вернул уникальный идентификатор скачивания. PaymentId={0}, Price={1}, Params={2}",
                                            paymentResult.PaymentId, paymentResult.Price,
                                            HttpContextHelper.ParamsToString(Request.Params, RobokassaApi.IsValidParamName));
                return(GetFailView());
            }

            LoggerWrapper.RemoteMessage(LoggingType.Info,
                                        "PaymentController.Success. Перед тем как сообщить пользователю об успешном платеже на сумму {0} с идентификатором {1}",
                                        MoneyFormatter.ToRubles(paymentResult.Price), paymentResult.PaymentId);

            return(GetSuccessView(purchasedGoods));
        }
예제 #3
0
        public ActionResult Result()
        {
            RobokassaApi           robokassaApi  = ApiFactory.GetRobokassaApi(WebSettingsConfig.Instance);
            RobokassaPaymentResult paymentResult = robokassaApi.ProcessResult(Request.Params);

            if (paymentResult == null)
            {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PaymentController.Result. PaymentResult is null. Params={0}",
                                            HttpContextHelper.ParamsToString(Request.Params, RobokassaApi.IsValidParamName));
                return(Content(ERROR_MESSAGE));
            }

            var  purchasedGoogsQuery = new PurchasedGoodsQuery();
            bool isSuccess           = purchasedGoogsQuery.SuccessfullyPurchased(paymentResult.PaymentId, paymentResult.Price);

            if (!isSuccess)
            {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PaymentController.Result. SuccessfullyPurchased вернул false. PaymentId={0}, Price={1}, Params={2}",
                                            paymentResult.PaymentId, paymentResult.Price,
                                            HttpContextHelper.ParamsToString(Request.Params, RobokassaApi.IsValidParamName));
                return(Content(ERROR_MESSAGE));
            }

            LoggerWrapper.RemoteMessage(LoggingType.Info,
                                        "PaymentController.Result. Прошла оплата на сумму {0} с идентификатором {1}",
                                        MoneyFormatter.ToRubles(paymentResult.Price), paymentResult.PaymentId);

            string response = robokassaApi.GetResponseResultOk(paymentResult.PaymentId);

            return(Content(response));
        }
예제 #4
0
        /// <summary>
        /// Метод вызывается платежной системой если платеж не удался
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult Fail()
        {
            RobokassaApi           robokassaApi  = ApiFactory.GetRobokassaApi(WebSettingsConfig.Instance);
            RobokassaPaymentResult paymentResult = robokassaApi.ProcessFail(Request.Params);

            if (paymentResult == null)
            {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PaymentController.Fail. PaymentResult is null. Params={0}",
                                            HttpContextHelper.ParamsToString(Request.Params, RobokassaApi.IsValidParamName));
                return(GetCancelView());
            }

            var  purchasedGoogsQuery = new PurchasedGoodsQuery();
            bool isSuccess           = purchasedGoogsQuery.FailedPurchased(paymentResult.PaymentId);

            if (!isSuccess)
            {
                LoggerWrapper.RemoteMessage(LoggingType.Error,
                                            "PaymentController.Fail. FailedPurchased вернул false. PaymentId={0}, Price={1}, Params={2}",
                                            paymentResult.PaymentId, paymentResult.Price,
                                            HttpContextHelper.ParamsToString(Request.Params, RobokassaApi.IsValidParamName));
                return(GetCancelView());
            }

            LoggerWrapper.RemoteMessage(LoggingType.Info,
                                        "PaymentController.Fail. Перед тем как сообщить пользователю об отменене платежа на сумму {0} с идентификатором {1}",
                                        MoneyFormatter.ToRubles(paymentResult.Price), paymentResult.PaymentId);

            return(GetCancelView());
        }
예제 #5
0
        public void GetPaymentUrl(string password1, int paymentId, decimal price, string description, string expectedUrl)
        {
            var securityParams = new RobokassaSecurityParams(LOGIN, password1, PASSWORD2);
            var robokassaApi   = new RobokassaApi(securityParams);

            string url = robokassaApi.GetPaymentUrl(paymentId, price, description);

            Assert.That(url, Is.EqualTo(expectedUrl));
        }
예제 #6
0
        public void ProcessResultNull(string password2, string paymentId, string price, string crc)
        {
            var securityParams       = new RobokassaSecurityParams(LOGIN, PASSWORD1, password2);
            var robokassaApi         = new RobokassaApi(securityParams);
            NameValueCollection pars = CreateNameValueCollection(paymentId, price, crc);

            RobokassaPaymentResult robokassaPaymentResult = robokassaApi.ProcessResult(pars);

            Assert.That(robokassaPaymentResult, Is.Null);
        }
예제 #7
0
        public void ProcessFail(string paymentId,
                                string price,
                                int expectedPaymentId,
                                decimal expectedPrice)
        {
            var securityParams       = new RobokassaSecurityParams(LOGIN, PASSWORD1, PASSWORD2);
            var robokassaApi         = new RobokassaApi(securityParams);
            NameValueCollection pars = CreateNameValueCollection(paymentId, price, null);

            RobokassaPaymentResult robokassaPaymentResult = robokassaApi.ProcessFail(pars);

            Assert.That(robokassaPaymentResult, Is.Not.Null);
            Assert.That(robokassaPaymentResult.PaymentId, Is.EqualTo(expectedPaymentId));
            Assert.That(robokassaPaymentResult.Price, Is.EqualTo(expectedPrice));
        }
예제 #8
0
        public void IsValidParamName(string name, bool expectedResult)
        {
            bool isValid = RobokassaApi.IsValidParamName(name);

            Assert.That(isValid, Is.EqualTo(expectedResult));
        }