PayTrx.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using SinochemCloudClient.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using Wayne.Lib;
  5. using Wayne.Lib.StateEngine;
  6. using Wayne.Lib.StateEngine.Generic;
  7. namespace SinochemInternetPlusApp.States.Shared
  8. {
  9. class PayTrx : TimeoutState<FuelingPoint>
  10. {
  11. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  12. {
  13. base.Enter(stateEntry, ref transition);
  14. Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.BeforePayment);
  15. Main.LockTrxInXiaofei2AsEpsTrx();
  16. Main.SendPaymentToCloudAsync();
  17. }
  18. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  19. {
  20. if (stateEngineEvent.Type is EventType)
  21. {
  22. switch ((EventType)stateEngineEvent.Type)
  23. {
  24. case EventType.CloudPaymentOk:
  25. var genericEvent = stateEngineEvent as GenericEvent<PaymentResponse>;
  26. if (genericEvent != null)
  27. {
  28. Main.CurrentEpsTrx.Model.real_pay_amount = genericEvent.EventArgs.result.real_Pay_Amount;
  29. Main.CurrentEpsTrx.Model.bill_id = genericEvent.EventArgs.result.bill_ID;
  30. Main.CurrentEpsTrx.Model.shift_id = genericEvent.EventArgs.result.shift_ID;
  31. Main.CurrentEpsTrx.Model.business_date = genericEvent.EventArgs.result.business_Date;
  32. Main.CurrentEpsTrx.Model.card_no = genericEvent.EventArgs.result.card_No;
  33. Main.CurrentEpsTrx.Model.cardNo_masked = genericEvent.EventArgs.result.cardNo_Hide;
  34. Main.CurrentEpsTrx.Model.InvoiceUrl = genericEvent.EventArgs.result.invoiceUrl;
  35. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentOk;
  36. Main.CurrentEpsTrx.SaveToDb();
  37. transition = new Transition(this, TransitionType.CloudPaymentOk);
  38. }
  39. else
  40. {
  41. transition = HandleCloudPaymentFailed();
  42. }
  43. stateEngineEvent.Handled = true;
  44. break;
  45. case EventType.CloudPaymentFailed:
  46. transition = HandleCloudPaymentFailed();
  47. stateEngineEvent.Handled = true;
  48. break;
  49. }
  50. }
  51. }
  52. private Transition HandleCloudPaymentFailed()
  53. {
  54. DebugLog("HandleCloudPaymentFailed");
  55. Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.PaymentNeedConfirm);
  56. Main.CurrentEpsTrx.MoveBackToXiaofei2();
  57. // copy this failed trx to another fusion if neeeded
  58. MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentEpsTrx.Model.jihao, Main.CurrentEpsTrx.Model.liushuino, Main.DebugLogger);
  59. return new Transition(this, TransitionType.CloudPaymentFailed);
  60. }
  61. protected override void Timeout(ref Transition transition)
  62. {
  63. transition = HandleCloudPaymentFailed();
  64. }
  65. protected override int TimeoutInterval =>
  66. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_PayTrx, 15);
  67. }
  68. }