Beispiel #1
0
        public string GetPaymentAttempt(ref FiscalizationData fiscal)
        {
            try
            {
                var getPaymentAttemptRequest = new GetPaymentAttemptRequest
                {
                    ShopID   = fiscal.ShopID,
                    OrderID  = fiscal.OrderID,
                    Password = _password
                };

                var signature = getPaymentAttemptRequest.Signature();
                getPaymentAttemptRequest.Signature = signature;

                var requestContent    = RequestFormedHelper.ToFormUrlEncodedContent(getPaymentAttemptRequest);
                var responseXmlString = GetResponse(unitellerCheckUrl, requestContent);
                var response          = DeserializeXml <XmlResponse>(responseXmlString);

                if (response == null ||
                    !string.Equals(response.Result, "0") ||
                    response.PaymentAttemptID == null)
                {
                    var errorMessage = (response == null || string.IsNullOrEmpty(response.ErrorMessage)) ? "GetPaymentAttemptError" : response.ErrorMessage;
                    logger.Error($"UnitellerProcessor.CreateFiscalCheck ShopId = {fiscal.ShopID}, OrderID = {fiscal.OrderID}, СustomerId = {fiscal.СustomerId}, " +
                                 $"Error = {errorMessage}");
                    fiscal.ErrorMessage = errorMessage;
                    return(string.Empty);
                }

                return(response.PaymentAttemptID);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"UnitellerProcessor.GetPaymentAttempt Exception ShopId = {fiscal.ShopID}, OrderID = {fiscal.OrderID} ");
                fiscal.ErrorMessage = ex.Message;
                return(string.Empty);
            }
        }
Beispiel #2
0
        internal bool CreateFiscalCheck(ref FiscalizationData fiscal)
        {
            try
            {
                var customer = new Сustomer
                {
                    id    = fiscal.СustomerId,
                    phone = fiscal.СustomerPhone,
                    email = fiscal.СustomerEmail,
                    name  = fiscal.СustomerName,
                    inn   = fiscal.СustomerInn
                };

                var lines = new Lines
                {
                    name     = fiscal.СustomerName,
                    price    = fiscal.PaidTotal,
                    qty      = 1,
                    sum      = fiscal.PaidTotal,
                    vat      = VAT.NotVAT,
                    payattr  = PayAttribute.PrepaidExpense,
                    lineattr = 10,
                };

                var payments = new Payments
                {
                    kind   = PaymentsKind.PaymentByAdditionalMeansPayment,
                    type   = PaymentsType.ExternalAcquiring,
                    amount = fiscal.PaidTotal
                };

                var receipt = new Receipt
                {
                    customer = customer,
                    lines    = new List <Lines> {
                        lines
                    },
                    taxmode  = Taxmode.SimplifiedTaxSystemIncomeMinusExpense,
                    payments = new List <Payments> {
                        payments
                    },
                    total = fiscal.PaidTotal
                };

                fiscal.Receipt = JsonConvert.SerializeObject(receipt);

                var createFiscalCheckRequest = new CreateFiscalCheckRequest
                {
                    ShopID           = fiscal.ShopID,
                    PaymentAttemptID = fiscal.PaymentAttemptID,
                    Subtotal         = fiscal.PaidTotal,
                    Receipt          = fiscal.Receipt,
                    Password         = _password
                };

                createFiscalCheckRequest.Receipt          = Base64Encode(fiscal.Receipt);
                createFiscalCheckRequest.ReceiptSignature = createFiscalCheckRequest.ReceiptSignature();
                createFiscalCheckRequest.Signature        = createFiscalCheckRequest.Signature();

                var requestContent    = RequestFormedHelper.ToFormUrlEncodedContent(createFiscalCheckRequest);
                var responseXmlString = GetResponse(unitellerPayUrl, requestContent);
                var response          = DeserializeXml <XmlResponse>(responseXmlString);

                if (response == null || !string.Equals(response.Result, "0"))
                {
                    var errorMessage = (response == null || string.IsNullOrEmpty(response.ErrorMessage)) ? "CreateFiscalCheckError" : response.ErrorMessage;
                    logger.Error($"UnitellerProcessor.CreateFiscalCheck ShopId = {fiscal.ShopID}, OrderID = {fiscal.OrderID}, СustomerId = {fiscal.СustomerId}, " +
                                 $"Error = {errorMessage}");
                    fiscal.ErrorMessage = errorMessage;
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"UnitellerProcessor.CreateFiscalCheck Exception ShopId = {fiscal.ShopID}, OrderID = {fiscal.OrderID}, СustomerId = {fiscal.СustomerId}");
                fiscal.ErrorMessage = ex.Message;
                return(false);
            }
        }