PosManager.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using SinochemPosClient;
  2. using SinochemPosClient.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Wayne.Lib.Log;
  10. namespace SinochemInternetPlusApp
  11. {
  12. public class PosManager
  13. {
  14. private readonly string UrlPrefix = GenericSinochemEpsApp.AppSettings["SinochemPosUrlPrefix"];
  15. private readonly string TrxNotifyApi = GenericSinochemEpsApp.AppSettings["SinochemPosNotifyApi"];
  16. static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("SinochemEpsApp");
  17. public TrxNotificationResponse NotifyPosSuccessfulTrx(EpsTransactionModel epsTrxModel, DebugLogger debugLogger)
  18. {
  19. PosCommunicator<TrxNotificationRequest, TrxNotificationResponse> communicator =
  20. new PosCommunicator<TrxNotificationRequest, TrxNotificationResponse>(UrlPrefix + TrxNotifyApi);
  21. TrxNotificationRequest request = new TrxNotificationRequest
  22. {
  23. ticketId = epsTrxModel.ttc,
  24. person = "pump",
  25. cardNo = epsTrxModel.card_no,
  26. //oilCard=1, weixin=8
  27. cardType = ((int)epsTrxModel.cardType).ToString(),
  28. oilName = epsTrxModel.youpin,
  29. units = epsTrxModel.qty,
  30. price = epsTrxModel.danjia,
  31. totalAmount = epsTrxModel.amount,
  32. amount = epsTrxModel.real_pay_amount,
  33. oilLiuShuiNo = epsTrxModel.liushuino,
  34. gunNum = epsTrxModel.jihao.ToString(),
  35. oilTime = epsTrxModel.xf_time,
  36. promDiscount = 0.00,
  37. //01 -- oilCard, 07 -- weixin
  38. payMethod = epsTrxModel.payMethod,
  39. transId = epsTrxModel.bill_id,
  40. openId = epsTrxModel.openId
  41. };
  42. if (epsTrxModel.cardType == CardType.OilCard)
  43. {
  44. request.cardDiscount = epsTrxModel.amount - epsTrxModel.real_pay_amount;
  45. request.promDiscount = 0;
  46. }
  47. else
  48. {
  49. request.cardDiscount = 0;
  50. request.promDiscount = epsTrxModel.amount - epsTrxModel.real_pay_amount;
  51. }
  52. logger.Info("Send TrxNotify to Pos: \n" + request.ToString());
  53. communicator.SendRequest(request);
  54. logger.Info("Got TrxNotify response: " + communicator.Response?.ToString());
  55. return communicator.Response;
  56. }
  57. }
  58. }