public void CreateTrust(IOriginalTrust trust) { if (null == trust) { throw new ArgumentNullException(nameof(trust)); } var request = new OriginalTrust((WmId)trust.MasterIdentifier, Purse.Parse(trust.Purse)) { InvoiceAllowed = trust.InvoiceAllowed, TransferAllowed = trust.TransferAllowed, BalanceAllowed = trust.BalanceAllowed, HistoryAllowed = trust.HistoryAllowed, DayLimit = (Amount)trust.DayLimit, WeekLimit = (Amount)trust.WeekLimit, MonthLimit = (Amount)trust.MonthLimit, Initializer = Session.AuthenticationService.ObtainInitializer() }; try { request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } }
public IExpressPayment ConfirmPayment(IPaymentConfirmation confirmation) { if (null == confirmation) { throw new ArgumentNullException(nameof(confirmation)); } var request = new ExpressPaymentConfirmation(Purse.Parse(confirmation.TargetPurse), confirmation.ConfirmationCode, (uint)confirmation.InvoiceId) { Initializer = CreateInitializer(confirmation.TargetPurse, true) }; ExpressPaymentReport response; try { response = request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } var expressPayment = new ExpressPayment(response.TransferId, response.InvoiceId, response.Amount, response.Date.ToUniversalTime(), response.ClientPurse.ToString(), response.ClientWmId); return(expressPayment); }
public void RedeemPaymer(string purse, string number, string key) { if (null == purse) { throw new ArgumentNullException(nameof(purse)); } if (null == number) { throw new ArgumentNullException(nameof(number)); } if (null == key) { throw new ArgumentNullException(nameof(key)); } var request = new PaymerTransfer(Purse.Parse(purse), (Description)number, (Description)key) { Initializer = Session.AuthenticationService.ObtainInitializer() }; try { request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } }
public string CreatePaymentLink(IPaymentLinkRequest paymentLinkRequest) { if (null == paymentLinkRequest) { throw new ArgumentNullException(nameof(paymentLinkRequest)); } var request = new OriginalMerchantPayment(paymentLinkRequest.OrderId, Purse.Parse(paymentLinkRequest.StorePurse), (Amount)paymentLinkRequest.Amount, (Description)paymentLinkRequest.Description, (ushort)paymentLinkRequest.Lifetime) { Initializer = CreateInitializer(paymentLinkRequest.StorePurse) }; MerchantPaymentToken response; try { response = request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } return(response.Token); }
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 string ObtainCurrencyByAccountNumber(string accountNumber) { if (null == accountNumber) { throw new ArgumentNullException(nameof(accountNumber)); } return(Purse.CurrencyToLetter(Purse.Parse(accountNumber).Type).ToString()); }
public long?FindIdentifier(string purse) { if (null == purse) { throw new ArgumentNullException(nameof(purse)); } if (Session.AuthenticationService.HasConnectionSettings) { using (var context = new DataContext(Session.AuthenticationService.GetConnectionSettings())) { var purseSummary = context.PurseSummaries.FirstOrDefault(ps => ps.Purse == purse); if (null != purseSummary) { return(purseSummary.Identifier); } } } var request = new WmIdFinder(Purse.Parse(purse)) { Initializer = Session.AuthenticationService.ObtainInitializer() }; WmIdReport response; try { response = request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } if (null == response.WmId) { return(null); } if (Session.AuthenticationService.HasConnectionSettings) { using (var context = new DataContext(Session.AuthenticationService.GetConnectionSettings())) { context.PurseSummaries.Add(new PurseSummary(purse, response.WmId.Value)); context.SaveChanges(); } } return(response.WmId); }
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 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 void CreateOutgoingInvoice(IOriginalOutgoingInvoice outgoingInvoice) { if (null == outgoingInvoice) { throw new ArgumentNullException(nameof(outgoingInvoice)); } var request = new OriginalInvoice(outgoingInvoice.OrderId, (WmId)outgoingInvoice.ClientIdentifier, Purse.Parse(outgoingInvoice.StorePurse), (Amount)outgoingInvoice.Amount) { Initializer = Session.AuthenticationService.ObtainInitializer() }; if (null != outgoingInvoice.Description) { request.Description = (Description)outgoingInvoice.Description; } if (null != outgoingInvoice.Address) { request.Address = (Description)outgoingInvoice.Address; } if (null != outgoingInvoice.ProtectionPeriod) { request.Period = outgoingInvoice.ProtectionPeriod.Value; } request.Expiration = outgoingInvoice.ExpirationPeriod; try { request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } }
public long CreateTransfer(IOriginalTransfer originalTransfer) { if (null == originalTransfer) { throw new ArgumentNullException(nameof(originalTransfer)); } var request = new OriginalTransfer(originalTransfer.PaymentId, Purse.Parse(originalTransfer.SourcePurse), Purse.Parse(originalTransfer.TargetPurse), (Amount)originalTransfer.Amount) { Description = (Description)originalTransfer.Description, Period = originalTransfer.ProtectionPeriod, Code = (Description)originalTransfer.ProtectionCode, Force = originalTransfer.Force, Initializer = Session.AuthenticationService.ObtainInitializer() }; if (null != originalTransfer.InvoiceId) { request.InvoiceId = (uint)originalTransfer.InvoiceId.Value; } TransferEnvelope response; try { response = request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } return(response.Transfer.PrimaryId); }
/// <summary> /// Initializes a new instance of the <see cref="InvoiceReader"/> class. /// </summary> /// <param name="manager">The manager.</param> public InvoiceReader(TransferManager manager) { _purse = Purse.Parse(ConfigurationManager.AppSettings["WebMoneyReaderPurse"]); _manager = manager; }
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 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)); }