Beispiel #1
0
        public IMerchantPayment FindPayment(string purse, long number,
                                            Contracts.BasicTypes.PaymentNumberKind numberKind)
        {
            if (null == purse)
            {
                throw new ArgumentNullException(nameof(purse));
            }

            var request = new MerchantOperationObtainer(Purse.Parse(purse), number,
                                                        ConvertFrom.ContractTypeToApiType(numberKind))
            {
                Initializer = CreateInitializer(purse)
            };

            MerchantOperation response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            var merchantPayment = new MerchantPayment(response.TransferId, response.InvoiceId,
                                                      response.Amount, response.CreateTime.ToUniversalTime(), response.Description, response.SourceWmId,
                                                      response.SourcePurse.ToString())
            {
                IsCapitaller  = response.CapitallerFlag,
                IsEnum        = response.EnumFlag,
                IPAddress     = response.IpAddress,
                TelepatPhone  = response.TelepatPhone,
                PaymerNumber  = response.PaymerNumber,
                PaymerEmail   = response.PaymerEmail,
                CashierNumber = response.CashierNumber,
                CashierDate   = response.CashierDate?.ToUniversalTime(),
                CashierAmount = response.CashierAmount,
            };


            if (null != response.TelepatMethod)
            {
                merchantPayment.TelepatMethod = ConvertFrom.ApiTypeToContractType(response.TelepatMethod.Value);
            }

            if (XmlInterfaces.BasicObjects.PaymerType.None != response.PaymerType)
            {
                merchantPayment.PaymerType = ConvertFrom.ApiTypeToContractType(response.PaymerType);
            }

            // TODO [L] Расшифровать тип e-invoicing платежа.
            if (null != response.SdpType)
            {
                merchantPayment.InvoicingMethod = (byte)response.SdpType.Value;
            }

            return(merchantPayment);
        }
        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);
        }
Beispiel #3
0
        public IEnumerable <ITransfer> SelectTransfers(string purse, DateTime fromTime, DateTime toTime)
        {
            if (null == purse)
            {
                throw new ArgumentNullException(nameof(purse));
            }

            var request = new TransferFilter(Purse.Parse(purse), fromTime, toTime)
            {
                Initializer = Session.AuthenticationService.ObtainInitializer()
            };

            TransferRegister response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            return(response.TransferList.Select(t =>
            {
                var transfer = new BusinessObjects.Transfer(Session.CurrentIdentifier, t.PrimaryId, t.SecondaryId,
                                                            t.SourcePurse.ToString(), t.TargetPurse.ToString(), t.Amount,
                                                            t.Commission, ConvertFrom.ApiTypeToContractType(t.TransferType), t.Description, t.Partner,
                                                            t.Rest,
                                                            t.CreateTime.ToUniversalTime(), t.UpdateTime.ToUniversalTime())
                {
                    InvoiceId = t.InvoiceId,
                    OrderId = t.OrderId,
                    PaymentId = t.PaymentId,
                    ProtectionPeriod = t.Period,
                    Locked = t.IsLocked,
                    Description = !string.IsNullOrEmpty(t.Description) ? t.Description : "[empty]"
                };


                return transfer;
            }));
        }
        public ITrustConfirmationInstruction RequestTrust(IOriginalExpressTrust originalExpressTrust)
        {
            if (null == originalExpressTrust)
            {
                throw new ArgumentNullException(nameof(originalExpressTrust));
            }

            XmlInterfaces.BasicObjects.ConfirmationType confirmationType =
                ConvertFrom.ContractTypeToApiType(originalExpressTrust.ConfirmationType);

            ExpressTrustRequest request;

            switch (originalExpressTrust.Identifier.Type)
            {
            case ExtendedIdentifierType.Phone:
                var phone = originalExpressTrust.Identifier.Value;

                if (!phone.StartsWith("+"))
                {
                    phone = $"+{phone}";
                }

                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, Phone.Parse(phone),
                                                  confirmationType);
                break;

            case ExtendedIdentifierType.WmId:
                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, WmId.Parse(originalExpressTrust.Identifier.Value),
                                                  confirmationType);
                break;

            case ExtendedIdentifierType.Email:
                MailAddress mailAddress = new MailAddress(originalExpressTrust.Identifier.Value);

                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, mailAddress,
                                                  confirmationType);
                break;

            case ExtendedIdentifierType.Purse:
                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, Purse.Parse(originalExpressTrust.Identifier.Value),
                                                  confirmationType);
                break;

            default:
                throw new InvalidOperationException("originalExpressTrust.Identifier.Type == " +
                                                    originalExpressTrust.Identifier.Type);
            }

            request.DayLimit   = (Amount)originalExpressTrust.DayLimit;
            request.WeekLimit  = (Amount)originalExpressTrust.WeekLimit;
            request.MonthLimit = (Amount)originalExpressTrust.MonthLimit;

            request.Initializer = Session.AuthenticationService.ObtainInitializer();

            ExpressTrustResponse response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            var instruction = new TrustConfirmationInstruction(response.Reference,
                                                               ConvertFrom.ApiTypeToContractType(response.ConfirmationType), response.Info, response.SmsReference);

            return(instruction);
        }
        public IEnumerable <IIncomingInvoice> SelectIncomingInvoices(DateTime fromTime, DateTime toTime, bool fresh = false)
        {
            var request = new IncomingInvoiceFilter((WmId)Session.CurrentIdentifier, fromTime, toTime)
            {
                Initializer = Session.AuthenticationService.ObtainInitializer()
            };

            IncomingInvoiceRegister response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            var incomingInvoices = response.IncomingInvoiceList.Select(ii =>
            {
                var incomingInvoice = new BusinessObjects.IncomingInvoice(ii.PrimaryId, ii.SecondaryId, ii.OrderId,
                                                                          ii.TargetWmId,
                                                                          ii.TargetPurse.ToString(),
                                                                          ii.Amount, ii.Description, ii.Expiration, ConvertFrom.ApiTypeToContractType(ii.InvoiceState),
                                                                          ii.CreateTime,
                                                                          ii.UpdateTime)
                {
                    Address = ii.Address
                };

                if (ii.Period > 0)
                {
                    incomingInvoice.ProtectionPeriod = ii.Period;
                }

                if (ii.TransferId > 0)
                {
                    incomingInvoice.TransferId = ii.TransferId;
                }

                return(incomingInvoice);
            })
                                   .OrderByDescending(ii => ii.UpdateTime)
                                   .ToList();

            return(incomingInvoices);
        }
        public ICertificate FindCertificate(long identifier, bool levelsRequested, bool claimsRequested, bool attachedLevelsRequested, bool fresh = false)
        {
            if (!fresh)
            {
                if (Session.AuthenticationService.HasConnectionSettings)
                {
                    using (var context = new DataContext(Session.AuthenticationService.GetConnectionSettings()))
                    {
                        var localCertificate = context.Certificates.Include("AttachedIdentifierSummaries")
                                               .FirstOrDefault(c => c.Identifier == identifier);

                        if (null != localCertificate)
                        {
                            return(localCertificate);
                        }
                    }
                }
            }

            var request =
                new PassportFinder((WmId)identifier)
            {
                Initializer = Session.AuthenticationService.ObtainInitializer()
            };

            Passport response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            int?bl = null;
            int?tl = null;

            if (levelsRequested)
            {
                var blObtainer =
                    new BLObtainer((WmId)identifier)
                {
                    Initializer = Session.AuthenticationService.ObtainInitializer()
                };
                var tlObtainer =
                    new TLObtainer((WmId)identifier)
                {
                    Initializer = Session.AuthenticationService.ObtainInitializer()
                };

                try
                {
                    bl = blObtainer.Submit().Value;
                    tl = tlObtainer.Submit().Value;
                }
                catch (WebException exception)
                {
                    Logger.Error(exception.Message, exception);

                    bl = null;
                    tl = null;
                }
            }

            int?positiveRating = null;
            int?negativeRating = null;

            if (claimsRequested)
            {
                var claimsObtainer =
                    new ClaimsObtainer((WmId)identifier)
                {
                    Initializer = Session.AuthenticationService.ObtainInitializer()
                };

                try
                {
                    var claimsReport = claimsObtainer.Submit();

                    positiveRating = claimsReport.PositiveCount;
                    negativeRating = claimsReport.NegativeCount;
                }
                catch (WebException exception)
                {
                    Logger.Error(exception.Message, exception);

                    positiveRating = null;
                    negativeRating = null;
                }
            }

            var certificate = new Certificate(response.WmId, ConvertFrom.ApiTypeToContractType(response.Degree),
                                              response.Revoked,
                                              response.CreateTime.ToUniversalTime(), response.IssuerId, response.IssuerAlias)
            {
                Status                         = ConvertFrom.ApiTypeToContractType(response.Status),
                Bl                             = bl,
                Tl                             = tl,
                PositiveRating                 = positiveRating,
                NegativeRating                 = negativeRating,
                Appointment                    = ConvertFrom.ApiTypeToContractType(response.Appointment),
                Basis                          = response.Basis,
                IdentifierAlias                = response.Alias,
                Information                    = response.Information,
                City                           = response.City,
                Region                         = response.Region,
                Country                        = response.Country,
                ZipCode                        = response.ZipCode,
                Address                        = response.Address,
                Surname                        = response.Surname,
                FirstName                      = response.FirstName,
                Patronymic                     = response.Patronymic,
                PassportNumber                 = response.PassportNumber,
                PassportDate                   = response.PassportDate?.ToUniversalTime(),
                PassportCountry                = response.PassportCountry,
                PassportCity                   = response.PassportCity,
                PassportIssuer                 = response.PassportIssuer,
                RegistrationCountry            = response.RegistrationCountry,
                RegistrationCity               = response.RegistrationCity,
                RegistrationAddress            = response.RegistrationAddress,
                Birthplace                     = response.Birthplace,
                Birthday                       = response.Birthday?.ToUniversalTime(),
                OrganizationName               = response.OrganizationName,
                OrganizationManager            = response.OrganizationManager,
                OrganizationAccountant         = response.OrganizationAccountant,
                OrganizationTaxId              = response.OrganizationTaxId,
                OrganizationId                 = response.OrganizationId,
                OrganizationActivityId         = response.OrganizationActivityId,
                OrganizationAddress            = response.OrganizationAddress,
                OrganizationCountry            = response.OrganizationCountry,
                OrganizationCity               = response.OrganizationCity,
                OrganizationZipCode            = response.OrganizationZipCode,
                OrganizationBankName           = response.OrganizationBankName,
                OrganizationBankId             = response.OrganizationBankId,
                OrganizationCorrAccount        = response.OrganizationCorrespondentAccount,
                OrganizationAccount            = response.OrganizationAccount,
                HomePhone                      = response.HomePhone,
                CellPhone                      = response.CellPhone,
                Icq                            = response.ICQ,
                Fax                            = response.Fax,
                Email                          = response.EMail,
                WebAddress                     = response.WebAddress,
                ContactPhone                   = response.ContactPhone,
                CapitallerParent               = response.CapitallerParent,
                PassportInspection             = response.PassportInspection,
                TaxInspection                  = response.TaxInspection,
                StatusAspects                  = (CertificateRecordAspects)response.StatusConfirmation,
                AppointmentAspects             = (CertificateRecordAspects)response.AppointmentConfirmation,
                BasisAspects                   = (CertificateRecordAspects)response.BasisConfirmation,
                AliasAspects                   = (CertificateRecordAspects)response.AliasConfirmation,
                InformationAspects             = (CertificateRecordAspects)response.InformationConfirmation,
                CityAspects                    = (CertificateRecordAspects)response.CityConfirmation,
                RegionAspects                  = (CertificateRecordAspects)response.RegionConfirmation,
                CountryAspects                 = (CertificateRecordAspects)response.CountryConfirmation,
                ZipCodeAspects                 = (CertificateRecordAspects)response.ZipCodeConfirmation,
                AddressAspects                 = (CertificateRecordAspects)response.AddressConfirmation,
                SurnameAspects                 = (CertificateRecordAspects)response.SurnameConfirmation,
                FirstNameAspects               = (CertificateRecordAspects)response.FirstNameConfirmation,
                PatronymicAspects              = (CertificateRecordAspects)response.PatronymicConfirmation,
                PassportNumberAspects          = (CertificateRecordAspects)response.PassportNumberConfirmation,
                PassportDateAspects            = (CertificateRecordAspects)response.PassportDateConfirmation,
                PassportCountryAspects         = (CertificateRecordAspects)response.PassportCountryConfirmation,
                PassportCityAspects            = (CertificateRecordAspects)response.PassportCityConfirmation,
                PassportIssuerAspects          = (CertificateRecordAspects)response.PassportIssuerConfirmation,
                RegistrationCountryAspects     = (CertificateRecordAspects)response.RegistrationCountryConfirmation,
                RegistrationCityAspects        = (CertificateRecordAspects)response.RegistrationCityConfirmation,
                RegistrationAddressAspects     = (CertificateRecordAspects)response.RegistrationAddressConfirmation,
                BirthplaceAspects              = (CertificateRecordAspects)response.BirthplaceConfirmation,
                BirthdayAspects                = (CertificateRecordAspects)response.BirthdayConfirmation,
                OrganizationNameAspects        = (CertificateRecordAspects)response.OrganizationNameConfirmation,
                OrganizationManagerAspects     = (CertificateRecordAspects)response.OrganizationManagerConfirmation,
                OrganizationAccountantAspects  = (CertificateRecordAspects)response.OrganizationAccountantConfirmation,
                OrganizationTaxIdAspects       = (CertificateRecordAspects)response.OrganizationTaxIdConfirmation,
                OrganizationIdAspects          = (CertificateRecordAspects)response.OrganizationIdConfirmation,
                OrganizationActivityIdAspects  = (CertificateRecordAspects)response.OrganizationActivityIdConfirmation,
                OrganizationAddressAspects     = (CertificateRecordAspects)response.OrganizationAddressConfirmation,
                OrganizationCountryAspects     = (CertificateRecordAspects)response.OrganizationCountryConfirmation,
                OrganizationCityAspects        = (CertificateRecordAspects)response.OrganizationCityConfirmation,
                OrganizationZipCodeAspects     = (CertificateRecordAspects)response.OrganizationZipCodeConfirmation,
                OrganizationBankNameAspects    = (CertificateRecordAspects)response.OrganizationBankNameConfirmation,
                OrganizationBankIdAspects      = (CertificateRecordAspects)response.OrganizationBankIdConfirmation,
                OrganizationCorrAccountAspects =
                    (CertificateRecordAspects)response.OrganizationCorrespondentAccountConfirmation,
                OrganizationAccountAspects = (CertificateRecordAspects)response.OrganizationAccountConfirmation,
                HomePhoneAspects           = (CertificateRecordAspects)response.HomePhoneConfirmation,
                CellPhoneAspects           = (CertificateRecordAspects)response.CellPhoneConfirmation,
                IcqAspects                = (CertificateRecordAspects)response.ICQConfirmation,
                FaxAspects                = (CertificateRecordAspects)response.FaxConfirmation,
                EmailAspects              = (CertificateRecordAspects)response.EMailConfirmation,
                WebAddressAspects         = (CertificateRecordAspects)response.WebAddressConfirmation,
                ContactPhoneAspects       = (CertificateRecordAspects)response.ContactPhoneConfirmation,
                CapitallerParentAspects   = (CertificateRecordAspects)response.CapitallerParentConfirmation,
                PassportInspectionAspects = (CertificateRecordAspects)response.PassportInspectionConfirmation,
                TaxInspectionAspects      = (CertificateRecordAspects)response.TaxInspectionConfirmation
            };

            if (null != response.PassportDate)
            {
                certificate.PassportDate = response.PassportDate.Value;
            }

            foreach (var wmIdInfo in response.WmIdInfoList)
            {
                var attachedIdentifier = new AttachedIdentifierSummary(wmIdInfo.WmId, wmIdInfo.Alias,
                                                                       wmIdInfo.Description, wmIdInfo.RegistrationDate)
                {
                    Certificate = certificate
                };

                if (attachedIdentifier.Identifier == identifier && null != bl && null != tl)
                {
                    attachedIdentifier.Bl = bl;
                    attachedIdentifier.Tl = tl;
                }

                if (attachedLevelsRequested && null == attachedIdentifier.Bl)
                {
                    var blObtainer =
                        new BLObtainer((WmId)attachedIdentifier.Identifier)
                    {
                        Initializer = Session.AuthenticationService.ObtainInitializer()
                    };
                    var tlObtainer =
                        new TLObtainer((WmId)attachedIdentifier.Identifier)
                    {
                        Initializer = Session.AuthenticationService.ObtainInitializer()
                    };

                    int?attachedBl;
                    int?attachedTl;

                    try
                    {
                        attachedBl = blObtainer.Submit().Value;
                        attachedTl = tlObtainer.Submit().Value;
                    }
                    catch (WebException exception)
                    {
                        Logger.Error(exception.Message, exception);

                        attachedBl = null;
                        attachedTl = null;
                    }

                    attachedIdentifier.Bl = attachedBl;
                    attachedIdentifier.Tl = attachedTl;

                    if (null == bl && identifier == attachedIdentifier.Identifier)
                    {
                        certificate.Bl = attachedBl;
                        certificate.Tl = attachedTl;
                    }
                }

                certificate.AttachedIdentifierSummaries.Add(attachedIdentifier);
            }

            if (Session.AuthenticationService.HasConnectionSettings)
            {
                using (var context = new DataContext(Session.AuthenticationService.GetConnectionSettings()))
                {
                    var localCertificate = context.Certificates.Include("AttachedIdentifierSummaries")
                                           .FirstOrDefault(c => c.Identifier == identifier);

                    if (null != localCertificate)
                    {
                        context.Certificates.Remove(localCertificate);

                        if (null != localCertificate.AttachedIdentifierSummaries &&
                            localCertificate.AttachedIdentifierSummaries.Count > 0)
                        {
                            context.AttachedIdentifierSummaries.RemoveRange(
                                localCertificate.AttachedIdentifierSummaries);
                        }
                    }

                    context.SaveChanges();

                    context.Certificates.Add(certificate);

                    context.SaveChanges();
                }
            }

            return(certificate);
        }
Beispiel #7
0
        public IPaymentConfirmationInstruction RequestPayment(IOriginalExpressPayment originalExpressPayment)
        {
            if (null == originalExpressPayment)
            {
                throw new ArgumentNullException(nameof(originalExpressPayment));
            }

            ExpressPaymentRequest request;

            switch (originalExpressPayment.ExtendedIdentifier.Type)
            {
            case ExtendedIdentifierType.Phone:
                var phone = originalExpressPayment.ExtendedIdentifier.Value;

                if (!phone.StartsWith("+"))
                {
                    phone = $"+{phone}";
                }

                request = new ExpressPaymentRequest(Purse.Parse(originalExpressPayment.TargetPurse),
                                                    originalExpressPayment.OrderId, (Amount)originalExpressPayment.Amount,
                                                    (Description)originalExpressPayment.Description,
                                                    Phone.Parse(phone),
                                                    ConvertFrom.ContractTypeToApiType(originalExpressPayment.ConfirmationType));
                break;

            case ExtendedIdentifierType.WmId:
                request = new ExpressPaymentRequest(Purse.Parse(originalExpressPayment.TargetPurse),
                                                    originalExpressPayment.OrderId, (Amount)originalExpressPayment.Amount,
                                                    (Description)originalExpressPayment.Description,
                                                    WmId.Parse(originalExpressPayment.ExtendedIdentifier.Value),
                                                    ConvertFrom.ContractTypeToApiType(originalExpressPayment.ConfirmationType));
                break;

            case ExtendedIdentifierType.Email:
                request = new ExpressPaymentRequest(Purse.Parse(originalExpressPayment.TargetPurse),
                                                    originalExpressPayment.OrderId, (Amount)originalExpressPayment.Amount,
                                                    (Description)originalExpressPayment.Description,
                                                    new MailAddress(originalExpressPayment.ExtendedIdentifier.Value),
                                                    ConvertFrom.ContractTypeToApiType(originalExpressPayment.ConfirmationType));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            request.Initializer = CreateInitializer(originalExpressPayment.TargetPurse, true);

            ExpressPaymentResponse response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            return(new PaymentConfirmationInstruction(response.InvoiceId,
                                                      ConvertFrom.ApiTypeToContractType(response.ConfirmationType), response.Info));
        }