Beispiel #1
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("invoice"); // <invoice>

            xmlRequestBuilder.WriteElement("orderid", OrderId);
            xmlRequestBuilder.WriteElement("customerwmid", SourceWmId.ToString());
            xmlRequestBuilder.WriteElement("storepurse", TargetPurse.ToString());
            xmlRequestBuilder.WriteElement("amount", Amount.ToString());
            xmlRequestBuilder.WriteElement("desc", Description);
            xmlRequestBuilder.WriteElement("address", Address);
            xmlRequestBuilder.WriteElement("period", Period);
            xmlRequestBuilder.WriteElement("expiration", Expiration);
            xmlRequestBuilder.WriteElement("onlyauth", Force ? 0 : 1);

            if (null != ShopId)
            {
                xmlRequestBuilder.WriteElement("lmi_shop_id", ShopId.Value);
            }

            xmlRequestBuilder.WriteEndElement(); // </invoice>
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("trust"); // <trust>

            xmlRequestBuilder.AppendAttribute("inv", InvoiceAllowed ? 1 : 0);
            xmlRequestBuilder.AppendAttribute("trans", TransferAllowed ? 1 : 0);
            xmlRequestBuilder.AppendAttribute("purse", BalanceAllowed ? 1 : 0);
            xmlRequestBuilder.AppendAttribute("transhist", HistoryAllowed ? 1 : 0);

            xmlRequestBuilder.WriteElement("masterwmid", Master.ToString());
            xmlRequestBuilder.WriteElement("slavewmid", Initializer.Id.ToString());
            xmlRequestBuilder.WriteElement("purse", Purse.ToString());

            xmlRequestBuilder.WriteElement("limit", Limit.ToString());
            xmlRequestBuilder.WriteElement("daylimit", DayLimit.ToString());
            xmlRequestBuilder.WriteElement("weeklimit", WeekLimit.ToString());
            xmlRequestBuilder.WriteElement("monthlimit", MonthLimit.ToString());

            xmlRequestBuilder.WriteEndElement(); // </trust>
        }
        StringContent CreateMessageEntityBody(Message message)
        {
            var messageToSend = new RestMSMessage
            {
                Address   = message.Header.Topic,
                MessageId = message.Header.Id.ToString(),
                Content   = new RestMSMessageContent
                {
                    Value    = message.Body.Value,
                    Type     = MediaTypeNames.Text.Plain,
                    Encoding = Encoding.ASCII.WebName
                }
            };

            var messageHeaders = new List <RestMSMessageHeader> {
                new RestMSMessageHeader {
                    Name = "MessageType", Value = message.Header.MessageType.ToString()
                }
            };

            messageHeaders.AddRange(message.Header.Bag.Select(customHeader => new RestMSMessageHeader {
                Name = customHeader.Key, Value = Encoding.ASCII.GetString((byte[])customHeader.Value)
            }));

            messageToSend.Headers = messageHeaders.ToArray();

            string messageContent;

            if (!XmlRequestBuilder.TryBuild(messageToSend, out messageContent))
            {
                return(null);
            }
            return(new StringContent(messageContent));
        }
        protected override void BuildXmlHead(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartDocument();

            xmlRequestBuilder.WriteStartElement("merchant.request"); // <merchant.request>

            xmlRequestBuilder.WriteStartElement("signtags");         // <signtags>

            xmlRequestBuilder.WriteElement("wmid", Initializer.Id.ToString());
            xmlRequestBuilder.WriteElement("validityperiodinhours", Lifetime.ToString(CultureInfo.InvariantCulture));

            ulong requestNumber = Initializer.GetRequestNumber();

            switch (Initializer.Mode)
            {
            case AuthorizationMode.Merchant:
                xmlRequestBuilder.WriteElement(
                    "md5", Utilities.CryptographyUtility.ComputeHash(BuildMessage(requestNumber) + Initializer.SecretKey));
                break;

            case AuthorizationMode.Classic:
                xmlRequestBuilder.WriteElement("sign", Initializer.Sign(BuildMessage(requestNumber)));
                break;

            default:
                throw new InvalidOperationException("Initializer.Mode=" + Initializer.Mode);
            }

            xmlRequestBuilder.WriteEndElement(); // </signtags>
        }
Beispiel #5
0
        protected virtual void BuildXmlBody(XmlRequestBuilder requestBuilder)
        {
            if (null == requestBuilder)
            {
                throw new ArgumentNullException(nameof(requestBuilder));
            }

            throw new NotSupportedException();
        }
Beispiel #6
0
        protected virtual void BuildXmlFoot(XmlRequestBuilder requestBuilder)
        {
            if (null == requestBuilder)
            {
                throw new ArgumentNullException(nameof(requestBuilder));
            }

            requestBuilder.WriteEndElement(); // </w3s.request>
            requestBuilder.WriteEndDocument();
        }
Beispiel #7
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteElement("mode", Mode);
            xmlRequestBuilder.WriteElement("contractid", ContractId);
        }
        /// <summary>
        /// Creates the entity body.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="feed">The feed.</param>
        /// <returns>StringContent.</returns>
        public StringContent CreateEntityBody <T>(T feed) where T : class, new()
        {
            string feedRequest;

            if (!XmlRequestBuilder.TryBuild(feed, out feedRequest))
            {
                return(null);
            }
            return(new StringContent(feedRequest));
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteElement("lmi_payee_purse", TargetPurse.ToString());
            xmlRequestBuilder.WriteElement("lmi_payment_no_type", (int)NumberType);
            xmlRequestBuilder.WriteElement("lmi_payment_no", PaymentNumber);
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteElement("lmi_purseid", Reference);
            xmlRequestBuilder.WriteElement("lmi_clientnumber_code", ConfirmationCode);
            xmlRequestBuilder.WriteElement("lang", Culture.Name);
        }
        protected override void BuildXmlFoot(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteEndElement(); // </request>

            xmlRequestBuilder.WriteEndDocument();
        }
Beispiel #12
0
        protected override void WriteContent(XmlWriter xmlWriter)
        {
            if (null == xmlWriter)
            {
                throw new ArgumentNullException(nameof(xmlWriter));
            }

            var xmlRequestBuilder = new XmlRequestBuilder(xmlWriter);

            BuildXmlHead(xmlRequestBuilder);
            BuildXmlBody(xmlRequestBuilder);
            BuildXmlFoot(xmlRequestBuilder);
        }
Beispiel #13
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteElement("lmi_payee_purse", StorePurse.ToString());
            xmlRequestBuilder.WriteElement(
                "lmi_clientnumber_code", ConfirmationCode);
            xmlRequestBuilder.WriteElement("lmi_wminvoiceid", InvoiceId);
            xmlRequestBuilder.WriteElement("lang", Culture.Name);
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("rejectprotect"); // <rejectprotect>

            xmlRequestBuilder.WriteElement("wmtranid", OperationId);

            xmlRequestBuilder.WriteEndElement(); // </rejectprotect>
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("getpurses"); // <getpurses>

            xmlRequestBuilder.WriteElement("wmid", WmId.ToString());

            xmlRequestBuilder.WriteEndElement(); // </getpurses>
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("invoicerefuse"); // <invoicerefuse>

            xmlRequestBuilder.WriteElement("wmid", WmId.ToString());
            xmlRequestBuilder.WriteElement("wminvid", InvoiceId);

            xmlRequestBuilder.WriteEndElement(); // </invoicerefuse>
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("createpurse"); // <createpurse>

            xmlRequestBuilder.WriteElement("wmid", WmId.ToString());
            xmlRequestBuilder.WriteElement("pursetype", Purse.CurrencyToLetter(PurseType).ToString());
            xmlRequestBuilder.WriteElement("desc", Description);

            xmlRequestBuilder.WriteEndElement(); // </createpurse>
        }
Beispiel #18
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("testsign"); // <testsign>

            xmlRequestBuilder.WriteElement("wmid", WmId.ToString());
            xmlRequestBuilder.WriteElement("plan", Message);
            xmlRequestBuilder.WriteElement("sign", Signature);

            xmlRequestBuilder.WriteEndElement(); // </testsign>
        }
Beispiel #19
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("message"); // <message>

            xmlRequestBuilder.WriteElement("receiverwmid", WmId.ToString());
            xmlRequestBuilder.WriteElement("msgsubj", Subject);
            xmlRequestBuilder.WriteElement("msgtext", Content);

            xmlRequestBuilder.WriteEndElement(); // </message>
        }
        protected override void WriteContent(XmlWriter xmlWriter)
        {
            if (null == xmlWriter)
            {
                throw new ArgumentNullException(nameof(xmlWriter));
            }

            var xmlRequestBuilder = new XmlRequestBuilder(xmlWriter);

            xmlRequestBuilder.WriteStartElement("WMIDLevel.request"); // <WMIDLevel.request>

            xmlRequestBuilder.WriteElement("wmid", WmId.ToString());

            xmlRequestBuilder.WriteEndElement(); // </WMIDLevel.request>
        }
Beispiel #21
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("trans"); // <trans>

            xmlRequestBuilder.WriteElement("inwmtranid", OperationId);
            xmlRequestBuilder.WriteElement("amount", Amount.ToString());
            xmlRequestBuilder.WriteElement("moneybackphone", Phone.ToString());

            xmlRequestBuilder.WriteEndElement(); // </trans>
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteElement("lmi_payee_purse", StorePurse.ToString());
            xmlRequestBuilder.WriteElement("lmi_day_limit", DayLimit.ToString());
            xmlRequestBuilder.WriteElement("lmi_week_limit", WeekLimit.ToString());
            xmlRequestBuilder.WriteElement("lmi_month_limit", MonthLimit.ToString());
            xmlRequestBuilder.WriteElement("lmi_clientnumber", GetClientId());
            xmlRequestBuilder.WriteElement("lmi_clientnumber_type", ((int)ClientIdType).ToString(CultureInfo.InvariantCulture));
            xmlRequestBuilder.WriteElement("lmi_sms_type", ((int)ConfirmationType).ToString(CultureInfo.InvariantCulture));
            xmlRequestBuilder.WriteElement("lang", Culture.Name);
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("getininvoices"); // <getininvoices>

            xmlRequestBuilder.WriteElement("wmid", WmId.ToString());
            xmlRequestBuilder.WriteElement("wminvid", InvoiceId);
            xmlRequestBuilder.WriteElement("datestart", StartTime.ToServerString());
            xmlRequestBuilder.WriteElement("datefinish", FinishTime.ToServerString());

            xmlRequestBuilder.WriteEndElement(); // </getininvoices>
        }
Beispiel #24
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteElement("lmi_payee_purse", StorePurse.ToString());
            xmlRequestBuilder.WriteElement("lmi_payment_no", OrderId);
            xmlRequestBuilder.WriteElement("lmi_payment_amount", Amount.ToString());
            xmlRequestBuilder.WriteElement("lmi_payment_desc", Description);
            xmlRequestBuilder.WriteElement("lmi_clientnumber", GetClientId());
            xmlRequestBuilder.WriteElement("lmi_clientnumber_type", (int)ClientIdType);
            xmlRequestBuilder.WriteElement("lmi_sms_type", (int)ConfirmationType);
            xmlRequestBuilder.WriteElement("lang", Culture.Name);
        }
Beispiel #25
0
        public string Run()
        {
            var client = new HttpClientGateway().Client();

            try
            {
                client.BaseAddress = _baseAddres;
                var order = new AddOrderModel()
                {
                    CustomerName = "Winnie the Pooh",
                    Description  = "Pot of Honey",
                    DueDate      = DateTime.UtcNow.ToString("o")
                };

                string orderBody;
                XmlRequestBuilder.TryBuild(order, out orderBody);
                var requestMessage = CreateRequest("orders", new StringContent(orderBody));
                var response       = client.SendAsync(requestMessage).Result;
                response.EnsureSuccessStatusCode();
                return(response.Content.ReadAsStringAsync().Result);
            }
            catch (AggregateException ae)
            {
                foreach (var e in ae.Flatten().InnerExceptions)
                {
                    Console.Write(e.Message);
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(" : " + e.InnerException);
                    }
                    else
                    {
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception he)
            {
                Console.WriteLine("Exception talking to server: {0}", he);
            }
            finally
            {
                client.Dispose();
            }
            return(null);
        }
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteElement("passportwmid", WmId.ToString());

            xmlRequestBuilder.WriteStartElement("params"); // <params>

            xmlRequestBuilder.WriteElement("dict", 0);
            xmlRequestBuilder.WriteElement("info", 1);
            xmlRequestBuilder.WriteElement("mode", AuthorizationMode.Classic == Initializer.Mode ? 1 : 0);

            xmlRequestBuilder.WriteEndElement(); // </params>
        }
Beispiel #27
0
        protected override void WriteContent(XmlWriter xmlWriter)
        {
            if (null == xmlWriter)
            {
                throw new ArgumentNullException(nameof(xmlWriter));
            }

            var xmlRequestBuilder = new XmlRequestBuilder(xmlWriter);

            xmlRequestBuilder.WriteStartElement("trustlimits"); // <trustlimits>
            xmlRequestBuilder.WriteStartElement("getlevels");   // <getlevels>

            xmlRequestBuilder.WriteElement("wmid", WmId.ToString());

            xmlRequestBuilder.WriteEndElement(); // </getlevels>
            xmlRequestBuilder.WriteEndElement(); // </trustlimits>
        }
        private string PostOrder(HttpClient client)
        {
            var order = new AddOrderModel()
            {
                CustomerName = "Winnie the Pooh",
                Description  = "Pot of Honey",
                DueDate      = DateTime.UtcNow.ToString("o")
            };

            string orderBody;

            XmlRequestBuilder.TryBuild(order, out orderBody);
            var requestMessage = CreateRequest("orders", new StringContent(orderBody));
            var response       = client.SendAsync(requestMessage).Result;

            response.EnsureSuccessStatusCode();
            return(response.Content.ReadAsStringAsync().Result);
        }
Beispiel #29
0
        protected override void BuildXmlBody(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartElement("paymer2purse"); // <paymer2purse>

            xmlRequestBuilder.WriteElement("purse", Purse.ToString());

            xmlRequestBuilder.WriteStartElement("paymer"); // <paymer>
            xmlRequestBuilder.WriteElement("number", Number);
            xmlRequestBuilder.WriteElement("code", Code);
            xmlRequestBuilder.WriteEndElement(); // </paymer>

            xmlRequestBuilder.WriteEndElement(); // </paymer2purse>
        }
        protected override void BuildXmlHead(XmlRequestBuilder xmlRequestBuilder)
        {
            if (null == xmlRequestBuilder)
            {
                throw new ArgumentNullException(nameof(xmlRequestBuilder));
            }

            xmlRequestBuilder.WriteStartDocument();

            ulong requestNumber = Initializer.GetRequestNumber();

            xmlRequestBuilder.WriteStartElement("request"); // <request>
            xmlRequestBuilder.WriteElement("wmid", Initializer.Id.ToString());

            xmlRequestBuilder.WriteElement("sign",
                                           AuthorizationMode.Classic == Initializer.Mode
                    ? Initializer.Sign(BuildMessage(requestNumber))
                    : string.Empty);
        }