public IEnumerable <IOutgoingInvoice> SelectOutgoingInvoices(string purse, DateTime fromTime, DateTime toTime, bool fresh = false) { var request = new OutgoingInvoiceFilter(Purse.Parse(purse), fromTime, toTime) { Initializer = Session.AuthenticationService.ObtainInitializer() }; OutgoingInvoiceRegister response; try { response = request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } var outgoingInvoices = response.OutgoingInvoiceList.Select(oi => { var outgoingInvoice = new BusinessObjects.OutgoingInvoice(oi.PrimaryId, oi.SecondaryId, oi.OrderId, oi.SourceWmId, oi.TargetPurse.ToString(), oi.Amount, oi.Description, oi.Expiration, ConvertFrom.ApiTypeToContractType(oi.InvoiceState), oi.CreateTime, oi.UpdateTime) { Address = oi.Address }; if (oi.Period > 0) { outgoingInvoice.ProtectionPeriod = oi.Period; } if (oi.TransferId > 0) { outgoingInvoice.TransferId = oi.TransferId; } return(outgoingInvoice); }) .OrderByDescending(oi => oi.UpdateTime) .ToList(); return(outgoingInvoices); }
public static void UpdateOutgoingInvoices(DateTime startDate, List<Transfer> transfers) { startDate = (DateTime.Now - startDate).Days > 88 ? DateTime.Now.AddMonths(-3) : startDate; OutgoingInvoiceFilter oif = new OutgoingInvoiceFilter(Purse.Parse(Configuration.Purse), WmDateTime.Parse(startDate.ToString("dd.MM.yyyy HH:mm:ss")), WmDateTime.Parse(DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"))); ExistentOutgoingInvoice[] eoi = oif.Submit(); if (eoi != null) { foreach (ExistentOutgoingInvoice inv in eoi) { if (inv.State == InvoiceState.Paid && inv.OrderId != 0) { Transfer t = transfers.Where(p => p.TransferId == (int)inv.OrderId).SingleOrDefault(); if (t != null) { GT.BO.Implementation.BillingSystem.WebMoneyTransfer wm = new GT.BO.Implementation.BillingSystem.WebMoneyTransfer(); wm.TransferId = t.TransferId; wm.Description = inv.Description; wm.TargetPurse = inv.TargetPurse.ToString(); wm.SourcePurse = inv.SourcePurse != null ? inv.SourcePurse.Value.ToString() : null; wm.WmInvoiceId = (int)inv.Id; wm.WmTransferId = (int)inv.OperationId; wm.TransDate = ((DateTime)inv.UpdateTime).ToUniversalTime(); wm.RetCode = 0; WebMoneyTransferFacade.Add(wm); BillingSystemFacade.CompleteTransfer(t.TransferId); transfers.Remove(t); } } } } }