1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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<FuelingPoint>
- {
- protected override void Enter(StateEntry stateEntry, ref Transition transition)
- {
- base.Enter(stateEntry, ref transition);
- Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.BeforePayment);
- Main.DebugLogger.Add($"Recovering trx, jihao: {Main.CurrentEpsTrx.Model.jihao}, liushuino: {Main.CurrentEpsTrx.Model.liushuino}, amount: {Main.CurrentEpsTrx.Model.amount}");
- 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<PaymentResponse>;
- 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);
- }
- }
|