Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="sender"></param>
        internal static void Read(XmlReader reader, Sender sender)
        {

            if (reader.IsEmptyElement)
            {
                XMLParserUtils.SkipNode(reader);
                return;
            }

            reader.ReadStartElement(SenderSerializer.Sender);
            reader.MoveToContent();

            while (!reader.EOF)
            {
                if (XMLParserUtils.IsEndElement(reader, SenderSerializer.Sender))
                {
                    XMLParserUtils.SkipNode(reader);
                    break;
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case SenderSerializer.Name:
                            sender.Name = reader.ReadElementContentAsString();
                            break;
                        case SenderSerializer.Email:
                            sender.Email = reader.ReadElementContentAsString();
                            break;
                        case PhoneSerializer.Phone:
                            Phone phone = new Phone();
                            PhoneSerializer.Read(reader, phone);
                            sender.Phone = phone;
                            break;
                        default:
                            XMLParserUtils.SkipElement(reader);
                            break;
                    }
                }
                else
                {
                    XMLParserUtils.SkipNode(reader);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="transaction"></param>
        internal static void Read(XmlReader reader, Transaction transaction, bool preApproval)
        {

            if (reader.IsEmptyElement)
            {
                XMLParserUtils.SkipNode(reader);
                return;
            }

            if (preApproval == true)
                reader.ReadStartElement(TransactionSerializerHelper.PreApproval);
            else
                reader.ReadStartElement(TransactionSerializerHelper.Transaction);
            reader.MoveToContent();

            while (!reader.EOF)
            {
                if (preApproval == true)
                {
                    if (XMLParserUtils.IsEndElement(reader, TransactionSerializerHelper.PreApproval))
                    {
                        XMLParserUtils.SkipNode(reader);
                        break;
                    }
                }
                else
                {
                    if (XMLParserUtils.IsEndElement(reader, TransactionSerializerHelper.Transaction))
                    {
                        XMLParserUtils.SkipNode(reader);
                        break;
                    }
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case TransactionSerializerHelper.Code:
                            transaction.Code = reader.ReadElementContentAsString();
                            break;
                        case TransactionSerializerHelper.Date:
                            transaction.Date = reader.ReadElementContentAsDateTime();
                            break;
                        case TransactionSerializerHelper.Reference:
                            transaction.Reference = reader.ReadElementContentAsString();
                            break;
                        case TransactionSerializerHelper.TransactionType:
                            transaction.TransactionType = reader.ReadElementContentAsInt();
                            break;
                        case TransactionSerializerHelper.TransactionStatus:
                            if (preApproval == true)
                                transaction.Status = reader.ReadElementContentAsString();
                            else
                                transaction.TransactionStatus = reader.ReadElementContentAsInt();
                            break;
                        case TransactionSerializerHelper.GrossAmount:
                            transaction.GrossAmount = reader.ReadElementContentAsDecimal();
                            break;
                        case TransactionSerializerHelper.DiscountAmount:
                            transaction.DiscountAmount = reader.ReadElementContentAsDecimal();
                            break;
                        case TransactionSerializerHelper.FeeAmount:
                            transaction.FeeAmount = reader.ReadElementContentAsDecimal();
                            break;
                        case TransactionSerializerHelper.NetAmount:
                            transaction.NetAmount = reader.ReadElementContentAsDecimal();
                            break;
                        case TransactionSerializerHelper.ExtraAmount:
                            transaction.ExtraAmount = reader.ReadElementContentAsDecimal();
                            break;
                        case TransactionSerializerHelper.LastEventDate:
                            transaction.LastEventDate = reader.ReadElementContentAsDateTime();
                            break;
                        case TransactionSerializerHelper.InstallmentCount:
                            transaction.InstallmentCount = reader.ReadElementContentAsInt();
                            break;
                        case TransactionSerializerHelper.Name:
                            transaction.Name = reader.ReadElementContentAsString();
                            break;
                        case TransactionSerializerHelper.Tracker:
                            transaction.Tracker = reader.ReadElementContentAsString();
                            break;
                        case TransactionSerializerHelper.Charge:
                            transaction.Charge = reader.ReadElementContentAsString();
                            break;
                        case PaymentMethodSerializer.PaymentMethod:
                            PaymentMethod paymentMethod = new PaymentMethod();
                            PaymentMethodSerializer.Read(reader, paymentMethod);
                            transaction.PaymentMethod = paymentMethod;
                            break;
                        case ItemListSerializer.Items:
                            ItemListSerializer.Read(reader, transaction.Items);
                            break;
                        case SenderSerializer.Sender:
                            Sender sender = new Sender();
                            SenderSerializer.Read(reader, sender);
                            transaction.Sender = sender;
                            break;
                        case ShippingSerializer.Shipping:
                            Shipping shipping = new Shipping();
                            ShippingSerializer.Read(reader, shipping);
                            transaction.Shipping = shipping;
                            break;
                        default:
                            XMLParserUtils.SkipElement(reader);
                            break;
                    }
                }
                else
                {
                    XMLParserUtils.SkipNode(reader);
                }
            }
        }
Exemplo n.º 3
0
        static void SenderExample()
        {
            PaymentRequest paymentRequest = new PaymentRequest();

            // Sender representa quem enviará dinheiro
            // na transação, normalmente o comprador
            Sender sender =
                new Sender(
                    "José Comprador",       // Nome
                    "*****@*****.**", // Email
                    new Phone("11", "56273440") // Telefone
                    );

            paymentRequest.Sender = sender;
            if (paymentRequest.Sender != null)
            {
                Console.WriteLine(paymentRequest.Sender.Name);
                Console.WriteLine(paymentRequest.Sender.Email);
                if (paymentRequest.Sender.Phone != null)
                {
                    Console.WriteLine(paymentRequest.Sender.Phone.AreaCode);
                    Console.WriteLine(paymentRequest.Sender.Phone.Number);
                }
            }
        }