public void CreateInstructionSpace() { PayAction pay200 = new PayAction(200, Recipient.Bank); InstructionSpace payTax = new InstructionSpace(pay200); // correct instruction stored Assert.AreEqual(pay200, payTax.GetInstruction()); // implements IBoardSpace interface Assert.IsTrue(payTax is IBoardSpace); }
public void CreateChoiceAction() { IAction drawCard = new DrawCardAction(CardType.PotLuck); IAction payBank = new PayAction(50, Recipient.Bank); ChoiceAction choiceCard = new ChoiceAction(drawCard, payBank); // correct IActions stored Assert.AreEqual(drawCard, choiceCard.GetChoice1()); Assert.AreEqual(payBank, choiceCard.GetChoice2()); // implements IAction Assert.IsTrue(choiceCard is IAction); }
public void CreatePayAction() { int amount = 500; Recipient receiver = Recipient.Bank; PayAction pay = new PayAction(amount, receiver); // correct payment amount returned Assert.AreEqual(amount, pay.GetAmount()); // correct recipient enum returned Assert.AreEqual(receiver, pay.GetPayTo()); // IAction interface implemented Assert.IsTrue(pay is IAction); }
public ChoosePayWindow(PayAction action) { InitializeComponent(); this.itemsPay.CallBack = (o) => { PayItem = o; txtChoosePay.Text = "已选择“" + o.Title + "”"; txtAmount.SelectAll(); }; this.DataContext = this; this.Loaded += ChoosePayWindow_Loaded; this.InitDefualtSettings(); PayAction = action; this.MouseUp += ChoosePayWindow_MouseUp; }
public MultiPayViewModel(decimal _amount, PayAction _payAction, int reason = 0) { Amount = _amount; PayAction = _payAction; Reason = reason; if (isWipeZero) { WipeZeroAfter = Math.Round(_amount, 1, MidpointRounding.AwayFromZero); } else { WipeZeroAfter = _amount; } WipeZero = WipeZeroAfter - _amount;//摸零金额 StillOwe = WipeZeroAfter; }
public PayWayViewModel(decimal amount, PayAction mode, int reason = 0) { IsOperatEnabled = true; Amount = amount; Mode = mode; this.ViewModelBinded += PayWayViewModel_ViewModelBinded; Reason = reason; ShowMiltiPay = Visibility.Visible; if (Amount <= 0) { ShowMiltiPay = Visibility.Hidden; } this.OnPropertyChanged(o => o.ShowMiltiPay); var list = new List <char>(); for (var i = 65; i <= 90; i++) { list.Add((char)i); } keys = list.ToArray(); }
public MultiPay(decimal amount, PayAction action) { InitializeComponent(); MultiPayViewModel = new MultiPayViewModel(amount, action); MultiPayViewModel.PayItems = new ObservableCollection <MultiPayItemViewModel> { new MultiPayItemViewModel() { IsFrist = true, IsLast = false }, new MultiPayItemViewModel() { IsFrist = false, IsLast = true }, }; this.ApplyBindings(this, MultiPayViewModel); this.InitDefualtSettings(); this.PreviewKeyDown += MultiPay_PreviewKeyDown; this.Closing += MultiPay_Closing; this.Loaded += MultiPay_Loaded; }
/// <summary> /// Операция для получения токена /// </summary> /// <param name="amount">Стоимость</param> /// <param name="currencyCode">Валюта</param> /// <param name="action">Действие на сайте PayPal, которое пользователь должен будет сделать</param> /// <param name="cancelUrl">URL, куда перенаправят пользователя в случае ошибки или отказа от проведения платежа</param> /// <param name="returnUrl">URL, куда перенаправят пользователя в случае успешного выполнения платежа</param> /// <returns>Все параметры, которые пришли от PayPal</returns> public Dictionary<string, string> GetToken(Currency currencyCode, PayAction action, string cancelUrl, string returnUrl) { var errList = Validate(); if (errList.Count != 0) { throw new Exception("Can`t get PayPal token because an error has occurred: " + string.Join(",", errList.ToArray())); } if (string.IsNullOrWhiteSpace(cancelUrl)) { throw new Exception("Cancel url is not defined"); } if (string.IsNullOrWhiteSpace(returnUrl)) { throw new Exception("Successfull url is not defined"); } var retDict = new Dictionary<string, string>(); /* --- Получаем сумму для оплаты --- */ decimal amount = basket.Sum(t => Convert.ToDecimal(t.Amount)); /* --- !Получаем сумму для оплаты --- */ var client = new WebClient(); var requestStr = new StringBuilder(); requestStr.Append(string.Format("{0}/?USER={1}&PWD={2}&SIGNATURE={3}&METHOD=SetExpressCheckout&VERSION={4}&PAYMENTREQUEST_0_AMT={5}&PAYMENTREQUEST_0_CURRENCYCODE={6}&PAYMENTREQUEST_0_PAYMENTACTION={7}&cancelUrl={8}&returnUrl={9}", PayPalURL, User, Password, Signature, Version, amount.ToString("F").Replace(',','.'), currencyCode.ToString("F"), action.ToString("F"), cancelUrl, returnUrl)); requestStr.Append(currencyCode == Currency.RUB ? "&LOCALECODE=RU" : "&LOCALECODE=US"); for (int i = 0; i < basket.Count; i++) { requestStr.Append(string.Format("&L_PAYMENTREQUEST_0_NAME{0}={1}&L_PAYMENTREQUEST_0_DESC{0}={2}&L_PAYMENTREQUEST_0_AMT{0}={3}&L_PAYMENTREQUEST_0_QTY{0}={4}", i, basket[i].Name, basket[i].Description, basket[i].Amount.Replace(',', '.'), basket[i].Quantity)); } var sr = new StreamReader(client.OpenRead(requestStr.ToString())); string newLine; while ((newLine = sr.ReadLine()) != null) { foreach (var curPair in newLine.Split('&')) { var pairKeyVal = curPair.Split('='); retDict.Add(pairKeyVal[0], pairKeyVal[1]); } } TokenResponse = retDict; return retDict; }
public ZhiFuWanCheng(decimal _amount, decimal receipt, decimal change, IEnumerable <MultiPayItemViewModel> payItems, PayAction payAction, DateTime orderTime) { InitializeComponent(); this.InitDefualtSettings(); var model = new PayComplete(_amount, receipt, change, payItems, payAction, orderTime); this.ApplyBindings(this, model); // this.Closing += _This_Closing; }
/// <summary> /// /// </summary> /// <param name="_amount">应收</param> /// <param name="Receipt">实收</param> /// <param name="change">找零</param> public PayComplete(decimal _amount, decimal receipt, decimal change, IEnumerable <MultiPayItemViewModel> payItems, PayAction payAction, DateTime orderTime) { PosViewModel.Current.IsClearStatus = true; OrderTime = orderTime; Amount = _amount; ViewModelBinded += PayComplete_ViewModelBinded; //print #region 退换货打印 if ((payAction == PayAction.Change || payAction == PayAction.Refund || payAction == PayAction.RefundAll) && PosViewModel.Current.PrintStatus == PrintStatus.Open) { Task.Factory.StartNew(() => { //Printer var _machineInfo = Global.MachineSettings.MachineInformations; int printWidth = 40; PrintModelHelper printer = new PrintModelHelper(); TicketModel ticketModel = new TicketModel(); ticketModel.TicketWidth = printWidth;//发票宽度,按字符数计算,根据打印机型号有所区别(通常在30-70之间),建议系统提供配置入口 ticketModel.StoreName = _machineInfo.StoreName; ticketModel.DeviceNumber = _machineInfo.MachineSn; ticketModel.Cashier = Global.CurrentSaleMen.UserCode; List <ProductModel> productList = new List <ProductModel>(); IEnumerable <ChangingList> changeList = null; switch (payAction) { case PayAction.Change: changeList = RefundChangeViewModel.Current.Change.ChangeList; ticketModel.SN = RefundChangeViewModel.Current.Change.PaySn; break; case PayAction.Refund: changeList = RefundChangeViewModel.Current.Refund.ChangeList; ticketModel.SN = RefundChangeViewModel.Current.Refund.PaySn; break; case PayAction.RefundAll: ticketModel.SN = RefundChangeViewModel.Current.RefundOrder.CurrentReturnOrderSn; foreach (var item in RefundChangeViewModel.Current.RefundOrder.OrderList) { ProductModel productModel = new ProductModel(); productModel.Code = item.Barcode; productModel.Name = item.Title; productModel.Num = item.Number; productModel.Price = item.ActualPrice; productModel.SubTotal = item.Total; productList.Add(productModel); } ticketModel.CountNum = (int)RefundChangeViewModel.Current.RefundOrder.OrderList.Sum(o => o.Number); //对应状态 ticketModel.OrderType = 3; //对应状态 3=退单 break; } if (payAction == PayAction.Change || payAction == PayAction.Refund) { foreach (var item in changeList) { ProductModel productModel = new ProductModel(); productModel.Code = item.Barcode; productModel.Name = item.Title; productModel.Num = item.ChangeNumber; productModel.Price = item.ChangePrice; productModel.SubTotal = item.Total; productList.Add(productModel); } ticketModel.CountNum = (int)changeList.Sum(o => o.ChangeNumber);//对应状态 if (payAction == PayAction.Change) { ticketModel.OrderType = (int)RefundChangeViewModel.Current.Change.Status;//对应状态 } if (payAction == PayAction.Refund) { ticketModel.OrderType = (int)RefundChangeViewModel.Current.Refund.Status;//对应状态 } } ticketModel.ProductList = productList; ticketModel.TotalPrice = _amount.ToString("0.###"); ticketModel.Receivable = receipt.ToString("0.###"); ticketModel.Change = change; ticketModel.CreateDT = orderTime; // ticketModel.Weigh = "0 KG"; ticketModel.PayType = (payItems.Select(o => o.PayItem).Distinct().Count() == 1 ? payItems.FirstOrDefault(o => o.PayItem != null).PayName : "多方付"); //把会员卡对应的卡号 卡余额 加到打印对象 List <Dictionary <string, string> > cardAndBalance = new List <Dictionary <string, string> >(); foreach (var item in payItems) { if (item.PayItem.Mode == PayMode.StoredValueCard) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add(item.CardNo, item.Balance.ToString()); cardAndBalance.Add(dic); } } ticketModel.CardAndBalances = cardAndBalance; List <string> footItemList = new List <string>(); //if (PosViewModel.Current.Preferential > 0m) //{ // footItemList.Add("已优惠:" + string.Format("{0:N2}", 0)); //} //footItemList.Add("称重商品数量请参照条码标签"); footItemList.Add("欢迎光临"); footItemList.Add("服务电话:" + _machineInfo.Phone); footItemList.Add("请保留电脑小票,作为退换货凭证"); footItemList.Add("退换小票"); ticketModel.FootItemList = footItemList; string titleStr = string.Empty; string printStr = printer.GetPrintStr(ticketModel, out titleStr); PrintHelper.Print(printStr, titleStr); }); } #endregion if (payAction == PayAction.Sale && PosViewModel.Current.PrintStatus == PrintStatus.Open) { Task.Factory.StartNew(() => { //Printer var _machineInfo = Global.MachineSettings.MachineInformations; int printWidth = 40; PrintModelHelper printer = new PrintModelHelper(); TicketModel ticketModel = new TicketModel(); ticketModel.TicketWidth = printWidth;//发票宽度,按字符数计算,根据打印机型号有所区别(通常在30-70之间),建议系统提供配置入口 ticketModel.StoreName = _machineInfo.StoreName; ticketModel.DeviceNumber = _machineInfo.MachineSn; ticketModel.SN = PosViewModel.Current.OrderSn; ticketModel.Cashier = Global.CurrentSaleMen.UserCode; ticketModel.Preferential = PosViewModel.Current.Preferential; ticketModel.SaleMan = PosViewModel.Current.SalemanName; List <ProductModel> productList = new List <ProductModel>(); foreach (var item in PosViewModel.Current.OrderList) { ProductModel productModel = new ProductModel(); productModel.Code = item.Barcode; productModel.Name = item.Title; productModel.Num = item.Number; productModel.Price = item.ActualPrice; productModel.SubTotal = item.Total; productList.Add(productModel); } ticketModel.ProductList = productList; ticketModel.CountNum = (int)PosViewModel.Current.Num; ticketModel.TotalPrice = _amount.ToString("0.###"); ticketModel.Receivable = receipt.ToString("0.###"); ticketModel.Change = change; ticketModel.OrderType = 0; ticketModel.CreateDT = orderTime; // ticketModel.Weigh = "0 KG"; ticketModel.PayType = (payItems.Select(o => o.PayItem).Distinct().Count() == 1 ? payItems.FirstOrDefault(o => o.PayItem != null).PayName : "多方付"); //把会员卡对应的卡号 卡余额 加到打印对象 List <Dictionary <string, string> > cardAndBalance = new List <Dictionary <string, string> >(); foreach (var item in payItems) { if (item.PayItem.Mode == PayMode.StoredValueCard) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add(item.CardNo, item.Balance.ToString()); cardAndBalance.Add(dic); } } ticketModel.CardAndBalances = cardAndBalance; List <string> footItemList = new List <string>(); //if (PosViewModel.Current.Preferential > 0m) //{ // footItemList.Add("已优惠:" + string.Format("{0:N2}", PosViewModel.Current.Preferential)); //} //footItemList.Add("称重商品数量请参照条码标签"); footItemList.Add("欢迎光临"); footItemList.Add("服务电话:" + _machineInfo.Phone); footItemList.Add("请保留电脑小票,作为退换货凭证"); ticketModel.FootItemList = footItemList; string titleStr = string.Empty; string printStr = printer.GetPrintStr(ticketModel, out titleStr); PrintHelper.Print(printStr, titleStr); Application.Current.Dispatcher.Invoke(new Action(() => { PosViewModel.Current.ClearOrder.Execute(null); })); }); } else { Application.Current.Dispatcher.Invoke(new Action(() => { PosViewModel.Current.ClearOrder.Execute(null); })); } }
public MultiPay(decimal amount, PayAction action, PayItem _payItem) : this(amount, action) { this.payItem = _payItem; }