コード例 #1
0
        public HttpResponseMessage CompletePayment([FromBody] CompletePaymentInputModel model)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,PaymentController,CompletePayment,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            ErrorMessage        errorMessage;
            string              userCode;
            HttpResponseMessage httpResponseMessage;

            if (GetUserCode(out userCode, out httpResponseMessage))
            {
                return(httpResponseMessage);
            }
            if (model == null)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.BadRequest,
                           new ErrorResponse
                {
                    Error = new MessageStyle {
                        Message = Constants.InvalidRequest, MessageType = 0
                    }
                }));
            }

            bool            openCashDrawer;
            bool            isRefund;
            string          changeDue;
            CustomerDisplay lcdMsg;
            var             receipts = _paymentManager.CompletePayment(model.SaleNumber, model.TillNumber,
                                                                       model.TransactionType, userCode, model.IssueStoreCredit, out errorMessage, out openCashDrawer,
                                                                       out changeDue, out isRefund, out lcdMsg);

            var kickbackCommunicationMsg = _paymentManager.KickbackCommunicationError();

            if (!string.IsNullOrEmpty(errorMessage?.MessageStyle?.Message))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse
                {
                    Error = errorMessage.MessageStyle
                }));
            }

            var newSale                      = _saleManager.InitializeSale(model.TillNumber, model.RegisterNumber, userCode, out errorMessage);
            var tillLimitExeceeded           = _paymentManager.CheckTillLimit(model.TillNumber);
            var completePaymentResponseModel = new FinishPaymentResponseModel
            {
                NewSale = new NewSale
                {
                    SaleNumber = newSale.Sale_Num,
                    TillNumber = newSale.TillNumber,
                    Customer   = newSale.Customer.Name
                },
                OpenCashDrawer     = openCashDrawer,
                LimitExceedMessage = tillLimitExeceeded,
                ChangeDue          = changeDue,
                CustomerDisplays   = new List <CustomerDisplay> {
                    lcdMsg, newSale.CustomerDisplay
                },
                Receipts            = receipts,
                kickabckServerError = kickbackCommunicationMsg
            };

            KickBackManager.ExchangeRate = 0;
            return(Request.CreateResponse(HttpStatusCode.OK, completePaymentResponseModel));
        }