1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using SinochemCloudClient.Models;
- using SinochemPosClient.Models;
- namespace SinochemInternetPlusApp.EpsTrxCleanup
- {
- public class EpsTrxCleanupManager : StateManager
- {
- private Eps eps;
- public EpsTrxCleanupManager(Eps eps) : base(0, "EpsTrxCleanup")
- {
- debugLogger.Add("EpsTrxCleanupManager is constructed");
- this.eps = eps;
- }
- public override string EntityType => "EpsTrxCleanup";
- public override string EntitySubType => "";
- protected override void ConfigStates()
- {
- States.CONFIGURATION.Config(stateMachine.StateTransitionLookup);
- }
- internal List<EpsTransaction> GetNeedRefundEpsTrxes()
- {
- DateTime dummyTime = DateTime.Now;
- return EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime
- (EpsTrxStatus.PaymentOkButNeedRefund, dummyTime, true);
- }
- internal List<EpsTransaction> GetNeedConfirmEpsTrxes()
- {
- DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.NeedConfirmEpsTrxExpirationInMinutes);
- debugLogger.Add("NeedConfirmEpsTrxes expiration datetime: " + expirationDatetime);
- List<EpsTransaction> needConfirmEpsTrxes = EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime
- (EpsTrxStatus.PaymentNeedConfirm, expirationDatetime, false);
- debugLogger.Add(needConfirmEpsTrxes.Count() + " eps trxes need confirmation");
- return needConfirmEpsTrxes;
- }
- internal List<EpsTransaction> GetNeedResendPosNotifyEpsTrxes()
- {
- DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.ResendPosNotifyExpirationInMinutes);
- debugLogger.Add("NeedResendPosNotifyEpsTrxes expiration datetime: " + expirationDatetime);
- List<EpsTransaction> needResendPosNotifyEpsTrxes = EpsTransactionQuery.GetEpsTrxesByNotifyPosFlagAndCreatedTime
- (NotifyPosFlag.NotifyFailed, expirationDatetime);
- debugLogger.Add(needResendPosNotifyEpsTrxes.Count() + " eps trxes need resending pos notify");
- return needResendPosNotifyEpsTrxes;
- }
- internal RefundResponse RefundEpsTrxInCloud(EpsTransactionModel trxModel)
- {
- return eps.SendRefundToCloud(trxModel, debugLogger);
- }
- internal TrxStatusInquiryResponse InquiryCloudTrxStatus(EpsTransactionModel trxModel)
- {
- return eps.SendTrxQueryToCloud(trxModel, debugLogger);
- }
- internal TrxNotificationResponse NotifySuccessfulTrxToPos(EpsTransactionModel trxModel)
- {
- return eps.NotifySuccessfulTrxToPos(trxModel, debugLogger);
- }
- internal void RemoveEpsTrxHistoryBeforeCertainDate()
- {
- //Remove the old trxes
- DateTime oldEnoughDatetime = DateTime.Now.AddDays(-1 * ConfigurationValues.EpsTrxHistoryArchiveInDays);
- debugLogger.Add("RemoveEpsTrxHistory before datetime: " + oldEnoughDatetime);
- EpsTransactionQuery.DeleteEpsTrxesBefore(oldEnoughDatetime);
- //Remove the eps trxes that the status is "before fueling"
- DateTime epsPendingTrxExpiredHours = DateTime.Now.AddHours(-1 * ConfigurationValues.EpsPendingTrxExpiredInHours);
- debugLogger.Add("Remove Eps Pending Trx before datetime: " + epsPendingTrxExpiredHours);
- EpsTransactionQuery.DeleteEpsTrxPendingBefore(epsPendingTrxExpiredHours);
- }
- }
- }
|