コード例 #1
0
        /// <summary>
        ///  Логирует полученный от Мобикома ответ на запрос состояния платежа
        /// </summary>
        /// <param name="response">Полученный ответ</param>
        /// <returns>Заведенная в БД запись</returns>
        private MobicomMessage LogMobicomStatusResponse(MobicomStatusResponse response)
        {
            var logEntry = _storage.MobicomMessages.CreateObject();

            logEntry.Id                    = Guid.NewGuid();
            logEntry.CreateTime            = DateTime.Now;
            logEntry.Method                = "MobicomStatusResponseOperation";
            logEntry.Action                = "Response";
            logEntry.AgreagatorId          = Truncate(response.Agregator.id.ToString(), 10);
            logEntry.MerchantId            = Truncate(response.Merchant.id.ToString(), 10);
            logEntry.OwnerId               = Truncate(response.Owner.id, 50);
            logEntry.ClientPhoneNumber     = Truncate(response.Client.Phone.number, 10);
            logEntry.ClientPhoneProvider   = Truncate(response.Client.Phone.provider.ToString(), 3);
            logEntry.PaymentAmount         = Truncate(response.Payment.amount.ToString(), 10);
            logEntry.PaymentCurrency       = Truncate(response.Payment.currency.ToString(), 3);
            logEntry.PaymentResult         = Truncate(response.Payment.result.ToString(), 10);
            logEntry.ResultCode            = Truncate(response.Result.code.ToString(), 10);
            logEntry.ResultComment         = Truncate(response.Result.comment, 255);
            logEntry.StartResultCode       = Truncate(response.Start.Result.code.ToString(), 10);
            logEntry.StartResultComment    = Truncate(response.Start.Result.comment, 255);
            logEntry.ReserveResultCode     = Truncate(response.Reserve.Result.code.ToString(), 10);
            logEntry.ReserveResultComment  = Truncate(response.Reserve.Result.comment, 255);
            logEntry.RegisterResultCode    = Truncate(response.Register.Result.code.ToString(), 10);
            logEntry.RegisterResultComment = Truncate(response.Register.Result.comment, 255);
            logEntry.RefundResultCode      = Truncate(response.Refund.Result.code.ToString(), 10);
            logEntry.RefundResultComment   = Truncate(response.Refund.Result.comment, 255);
            logEntry.Version               = Truncate(response.version, 10);

            _storage.MobicomMessages.AddObject(logEntry);

            return(logEntry);
        }
コード例 #2
0
        /// <summary>
        /// Формирует ответ клиенту на основании ответа полученного от Мобикома
        /// </summary>
        /// <param name="response">Полученный от Мобикома ответ</param>
        /// <param name="payment">Платеж, состояние которого запрашивает клиент</param>
        /// <returns></returns>
        private Resp CreateNLogStateResponse(UniplatServiceData.Payment payment, MobicomStatusResponse response)
        {
            var                      paymentId                   = payment.Id.ToString();
            MobicomMessage           initialResponse             = LogMobicomStatusResponse(response);
            Func <int, string, Resp> createAndSaveDebitStateResp =
                (i, com) => CreateAndSaveResp(paymentId, i, com, "GetDebitState", initialResponse);

            string name = "InProcess";
            int    code = 0;

            // Если ошибка в запросе
            if (response.Result.code.HasValue && response.Result.code.Value != 0)
            {
                name = "ProtocolError";
                code = response.Result.code.Value;
                payment.StatusDescription = response.Result.comment;
            }
            // Если ошибка при инициации платежа
            else if (response.Start.Result.code.HasValue && response.Start.Result.code.Value != 0)
            {
                name = null;
                code = response.Start.Result.code.Value;
                payment.StatusDescription = response.Start.Result.comment;
            }
            // Если установлен статус платежа
            else if (response.Payment.result.HasValue)
            {
                name = null;
                code = response.Payment.result.Value;
            }

            var status = GetOrCreateStatus(name, code, response.Client.Phone.provider);

            payment.Status     = status;
            payment.StatusTime = DateTime.Now;

            return(createAndSaveDebitStateResp(status.PartnerCode, status.PartnerDescription));
        }