コード例 #1
0
        /// <summary>
        /// Логирует отправляемый Мобикому запрос состояния платежа
        /// </summary>
        /// <param name="request">Отправлемый запрос</param>
        /// <param name="initialMessage">Запись в таблице ClientMessages, на оснолвании которой сформирован отправляемый запрос</param>
        /// <returns>Заведенная в БД запись</returns>
        private MobicomMessage LogMobicomStatusRequest(MobicomStatusRequest request, ClientMessage initialMessage)
        {
            var logEntry = _storage.MobicomMessages.CreateObject();

            logEntry.ClientMessage = initialMessage;

            logEntry.Id           = Guid.NewGuid();
            logEntry.CreateTime   = DateTime.Now;
            logEntry.Method       = "MobicomStatusRequestOperation";
            logEntry.Action       = "Request";
            logEntry.AgreagatorId = Truncate(request.Agregator.id.ToString(), 10);
            logEntry.OwnerId      = Truncate(request.Owner.id, 50);
            logEntry.Hash         = Truncate(request.hash, 50);
            logEntry.Version      = Truncate(request.version, 10);

            _storage.MobicomMessages.AddObject(logEntry);

            return(logEntry);
        }
コード例 #2
0
        public Resp GetDebitState(ReqState request)
        {
            //MobicomMessage initialResponse = null;
            Func <int, string, Resp> createAndSaveDebitStateResp =
                (i, com) => CreateAndSaveResp(request.PaymentId, i, com, "GetDebitState", null);

            try
            {
                var initialRequest = LogReqState(request);

                Guid paymentId;
                if (!Guid.TryParse(request.PaymentId, out paymentId))
                {
                    return(createAndSaveDebitStateResp(2, "Incorrect parameter: PaymentId"));
                }

                string wrongParameter;
                if (!request.CheckParametersRegex(out wrongParameter))
                {
                    return(createAndSaveDebitStateResp(2, "Incorrect parameter: " + wrongParameter));
                }

                var payment =
                    _storage.Payments.SingleOrDefault(p => p.Id == paymentId && p.Partner.Code == request.PartnerCode);
                if (payment == null)
                {
                    return(createAndSaveDebitStateResp(1, "Unknown pair (PaymentId, PartnerCode)"));
                }

                if (!request.CheckHashCode(payment.Partner.Password))
                {
                    return(createAndSaveDebitStateResp(4, "Incorrect hash-value"));
                }

                if (payment.Status != null && payment.Status.IsTerminal)
                {
                    return(CreateAndSaveResp(request.PaymentId, payment.Status.PartnerCode, payment.Status.PartnerDescription,
                                             "GetDebitState", null));
                }

                var mobiRequest = new MobicomStatusRequest();
                mobiRequest.version = payment.Merchant.Bank.ProtocolVersion;
                mobiRequest.Owner   = new Owner {
                    id = payment.OwnerId
                };
                mobiRequest.Agregator = new Agregator {
                    id = payment.Merchant.Bank.AgregarorId
                };
                mobiRequest.hash = GetHash(mobiRequest.Owner.id + payment.Merchant.Bank.Password);
                LogMobicomStatusRequest(mobiRequest, initialRequest);

                var mobiClient = new mobicomTypeClient();
                var response   = mobiClient.MobicomStatusRequestOperation(mobiRequest);

                return(CreateNLogStateResponse(payment, response));
            }
            catch (Exception e)
            {
                Trace.WriteLine("Ошибка в GetDebitState: " + e);
                return(createAndSaveDebitStateResp(13, "UniplatService internal error"));
            }
            finally
            {
                TrySaveChanges();
            }
        }