PayTrx.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.DebugLogger.Add($"Recovering trx, jihao: {Main.CurrentEpsTrx.Model.jihao}, liushuino: {Main.CurrentEpsTrx.Model.liushuino}, amount: {Main.CurrentEpsTrx.Model.amount}");
  16. Main.LockTrxInXiaofei2AsEpsTrx();
  17. Main.SendPaymentToCloudAsync();
  18. }
  19. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  20. {
  21. if (stateEngineEvent.Type is EventType)
  22. {
  23. switch ((EventType)stateEngineEvent.Type)
  24. {
  25. case EventType.CloudPaymentOk:
  26. var genericEvent = stateEngineEvent as GenericEvent<PaymentResponse>;
  27. if (genericEvent != null)
  28. {
  29. Main.CurrentEpsTrx.Model.real_pay_amount = genericEvent.EventArgs.result.real_Pay_Amount;
  30. Main.CurrentEpsTrx.Model.bill_id = genericEvent.EventArgs.result.bill_ID;
  31. Main.CurrentEpsTrx.Model.shift_id = genericEvent.EventArgs.result.shift_ID;
  32. Main.CurrentEpsTrx.Model.business_date = genericEvent.EventArgs.result.business_Date;
  33. Main.CurrentEpsTrx.Model.card_no = genericEvent.EventArgs.result.card_No;
  34. Main.CurrentEpsTrx.Model.cardNo_masked = genericEvent.EventArgs.result.cardNo_Hide;
  35. Main.CurrentEpsTrx.Model.InvoiceUrl = genericEvent.EventArgs.result.invoiceUrl;
  36. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentOk;
  37. Main.CurrentEpsTrx.SaveToDb();
  38. transition = new Transition(this, TransitionType.CloudPaymentOk);
  39. }
  40. else
  41. {
  42. transition = HandleCloudPaymentFailed();
  43. }
  44. stateEngineEvent.Handled = true;
  45. break;
  46. case EventType.CloudPaymentFailed:
  47. transition = HandleCloudPaymentFailed();
  48. stateEngineEvent.Handled = true;
  49. break;
  50. }
  51. }
  52. }
  53. private Transition HandleCloudPaymentFailed()
  54. {
  55. DebugLog("HandleCloudPaymentFailed");
  56. Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.PaymentNeedConfirm);
  57. Main.CurrentEpsTrx.MoveBackToXiaofei2();
  58. // copy this failed trx to another fusion if neeeded
  59. MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentEpsTrx.Model.jihao, Main.CurrentEpsTrx.Model.liushuino, Main.DebugLogger);
  60. return new Transition(this, TransitionType.CloudPaymentFailed);
  61. }
  62. protected override void Timeout(ref Transition transition)
  63. {
  64. transition = HandleCloudPaymentFailed();
  65. }
  66. protected override int TimeoutInterval =>
  67. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_PayTrx, 15);
  68. }
  69. }