using SinochemCloudClient.Models; using System; using System.Collections.Generic; using Wayne.Lib; using Wayne.Lib.StateEngine; using Wayne.Lib.StateEngine.Generic; namespace SinochemInternetPlusApp.States.Shared { class PayTrx : TimeoutState { protected override void Enter(StateEntry stateEntry, ref Transition transition) { base.Enter(stateEntry, ref transition); Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.BeforePayment); Main.LockTrxInXiaofei2AsEpsTrx(); Main.SendPaymentToCloudAsync(); } protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition) { if (stateEngineEvent.Type is EventType) { switch ((EventType)stateEngineEvent.Type) { case EventType.CloudPaymentOk: var genericEvent = stateEngineEvent as GenericEvent; if (genericEvent != null) { Main.CurrentEpsTrx.Model.real_pay_amount = genericEvent.EventArgs.result.real_Pay_Amount; Main.CurrentEpsTrx.Model.bill_id = genericEvent.EventArgs.result.bill_ID; Main.CurrentEpsTrx.Model.shift_id = genericEvent.EventArgs.result.shift_ID; Main.CurrentEpsTrx.Model.business_date = genericEvent.EventArgs.result.business_Date; Main.CurrentEpsTrx.Model.card_no = genericEvent.EventArgs.result.card_No; Main.CurrentEpsTrx.Model.cardNo_masked = genericEvent.EventArgs.result.cardNo_Hide; Main.CurrentEpsTrx.Model.InvoiceUrl = genericEvent.EventArgs.result.invoiceUrl; Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentOk; Main.CurrentEpsTrx.SaveToDb(); transition = new Transition(this, TransitionType.CloudPaymentOk); } else { transition = HandleCloudPaymentFailed(); } stateEngineEvent.Handled = true; break; case EventType.CloudPaymentFailed: transition = HandleCloudPaymentFailed(); stateEngineEvent.Handled = true; break; } } } private Transition HandleCloudPaymentFailed() { DebugLog("HandleCloudPaymentFailed"); Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.PaymentNeedConfirm); Main.CurrentEpsTrx.MoveBackToXiaofei2(); // copy this failed trx to another fusion if neeeded MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentEpsTrx.Model.jihao, Main.CurrentEpsTrx.Model.liushuino, Main.DebugLogger); return new Transition(this, TransitionType.CloudPaymentFailed); } protected override void Timeout(ref Transition transition) { transition = HandleCloudPaymentFailed(); } protected override int TimeoutInterval => TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_PayTrx, 15); } }