Пример #1
0
        private void BindFromRixty()
        {
            try
            {
                var proxy    = new RixtyProxy();
                var products = proxy.GetProducts();
                var dt       = new DataTable();
                dt.Columns.Add("Nome");
                dt.Columns.Add("Descricao");
                dt.Columns.Add("ProductCode");
                dt.Columns.Add("IsStockAvailable");
                dt.Columns.Add("Comission");
                dt.Columns.Add("SellingPrice");
                dt.Columns.Add("UnitPrice");

                DataRow dr;
                foreach (var p in products.OrderBy(p => p.ProductName))
                {
                    dr    = dt.NewRow();
                    dr[0] = p.ProductName;
                    dr[1] = p.ProductDescription;
                    dr[2] = "013" + p.ProductCode;
                    dr[3] = p.IsStockAvailable ? "Sim" : "Não";
                    dr[4] = (p.Commission / 100).ToString("P");
                    dr[5] = p.SellingPrice.ToString("C");
                    dr[6] = p.UnitPrice.ToString("C");
                    dt.Rows.Add(dr);
                }
                dgProdutos.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro");
            }
        }
Пример #2
0
        private void btnRecovery_Click(object sender, EventArgs e)
        {
            var proxy = new RixtyProxy();

            if (string.IsNullOrEmpty(txtRefID.Text))
            {
                MessageBox.Show("O campo Reference ID é obrigatório", "Atenção");
                return;
            }
            if (string.IsNullOrEmpty(txtToken.Text))
            {
                MessageBox.Show("O campo Validated Token é obrigatório", "Atenção");
                return;
            }
            var result = proxy.GetPurchaseConfirmation(txtRefID.Text, txtToken.Text);

            if (result == null || !result.Coupons.Any())
            {
                MessageBox.Show("PIN não encontrado", "Atenção");
                return;
            }
            txtPID.Text     = result.PaymentId;
            txtCodProd.Text = result.ProductCode;
            txtPrice.Text   = result.TotalPrice.ToString();
            txtQtd.Text     = result.Quantity;
            txtProd.Text    = result.ProductDescription;

            var pins       = result.Coupons.SelectMany(c => c.Pins).ToList();
            var serials    = result.Coupons.SelectMany(c => c.Serials).ToList();
            var total      = pins.Count() > serials.Count() ? pins.Count() : serials.Count();
            var pinSerials = new List <PinAndSerial>();

            for (int i = 0; i < total; i++)
            {
                pinSerials.Add(new PinAndSerial
                {
                    PIN    = i < pins.Count() ? pins[i] : string.Empty,
                    Serial = i < serials.Count() ? serials[i] : string.Empty
                });
            }
            dgvResultado.DataSource = pinSerials;
        }
Пример #3
0
        private List <PurchaseResult> Purchase(string productCode, int qtd)
        {
            try
            {
                var proxy      = new RixtyProxy();
                var refId      = Guid.NewGuid().ToString();
                var initiation = proxy.GetPurchaseInitiation(refId, productCode, qtd);
                if (initiation.InitiationResultCode != "00")
                {
                    //MessageBox.Show(proxy.GetErrorCode(initiation.InitiationResultCode), "Atenção");
                    return(Enumerable.Range(0, qtd).Select(i => new PurchaseResult
                    {
                        Serial = "ERRO",
                        PIN = proxy.GetErrorCode(initiation.InitiationResultCode),
                        DeliveredQuantity = "0",
                        Quantity = qtd.ToString()
                    }).ToList());
                }
                var result = proxy.GetPurchaseConfirmation(refId, initiation.ValidatedToken);
                if (result == null || !result.Coupons.Any())
                {
                    //MessageBox.Show("PIN não encontrado", "Atenção");
                    return(Enumerable.Range(0, qtd).Select(i => new PurchaseResult
                    {
                        Serial = "ERRO",
                        PIN = "PIN não encontrado",
                        DeliveredQuantity = "0",
                        Quantity = qtd.ToString()
                    }).ToList());
                }

                var pins       = result.Coupons.SelectMany(c => c.Pins).ToList();
                var serials    = result.Coupons.SelectMany(c => c.Serials).ToList();
                var total      = pins.Count() > serials.Count() ? pins.Count() : serials.Count();
                var pinSerials = new List <PinAndSerial>();
                var items      = Enumerable.Range(0, total).Select(i => new PurchaseResult
                {
                    PurchaseStatusDate = result.PurchaseStatusDate.ToString("dd/MM/yyyy hh:mm"),
                    ExpiryDate         = result.Coupons[i].ExpiryDate.ToString("dd/MM/yyyy hh:mm"),
                    UnitPrice          = result.UnitPrice,
                    PaymentId          = result.PaymentId,
                    ProductCode        = result.ProductCode,
                    ProductDescription = result.ProductDescription,
                    PIN               = result.Coupons[i].Pins[0],
                    ReferenceId       = result.ReferenceId,
                    Serial            = result.Coupons[i].Serials[0],
                    DeliveredQuantity = result.DeliveredQuantity,
                    TotalPrice        = result.TotalPrice,
                    Quantity          = result.Quantity
                }).ToList();
                return(items);
            }
            catch (Exception ex)
            {
                return(Enumerable.Range(0, qtd).Select(i => new PurchaseResult
                {
                    Serial = "ERRO",
                    PIN = ex.Message,
                    DeliveredQuantity = "0",
                    Quantity = qtd.ToString()
                }).ToList());
            }
        }