コード例 #1
0
        private List <Transaction> GetListTransaction(AzionePayPal azione, string guid)
        {
            using (DatabaseContext db = new DatabaseContext())
            {
                switch (azione)
                {
                case AzionePayPal.Acquisto:
                    AcquistoViewModel acquisto = Session["PayPalCompra"] as AcquistoViewModel;
                    //AnnuncioModel annuncio = Session["PayPalAnnuncio"] as AnnuncioModel;
                    AnnuncioModel annuncio = new AnnuncioModel((Session["PayPalAnnuncio"] as AnnuncioModel).TOKEN, db);
                    return(GetListTransactionFromAcquisto(acquisto, annuncio, guid));

                case AzionePayPal.Offerta:
                    //OffertaModel offerta = Session["PayPalOfferta"] as OffertaModel;
                    int          idOfferta = (Session["PayPalOfferta"] as OffertaModel).ID;
                    var          model     = db.OFFERTA.SingleOrDefault(m => m.ID == idOfferta);
                    OffertaModel offerta   = new OffertaModel(model);
                    return(GetListTransactionFromOfferta(offerta, guid));

                case AzionePayPal.OffertaOK:
                    AcquistoViewModel acquistoOfferta = Session["PayPalCompra"] as AcquistoViewModel;
                    //AnnuncioModel annuncioOfferta = Session["PayPalAnnuncio"] as AnnuncioModel;
                    AnnuncioModel annuncioOfferta = new AnnuncioModel((Session["PayPalAnnuncio"] as AnnuncioModel).TOKEN, db);
                    return(GetListTransactionFromAcquisto(acquistoOfferta, annuncioOfferta, guid));
                }
            }
            return(null);
        }
コード例 #2
0
        private bool SaveOffertaCompleta(PayPalIndexViewModel paypal, Payment payment)
        {
            AcquistoViewModel viewModel = Session["PayPalCompra"] as AcquistoViewModel;
            AnnuncioModel     model     = Session["PayPalAnnuncio"] as AnnuncioModel;

            using (DatabaseContext db = new DatabaseContext())
            {
                // AGGIUNGERE TRANSAZIONE NELLA TABELLA LOG_PAGAMENTO
                LOG_PAGAMENTO log      = new LOG_PAGAMENTO();
                ANNUNCIO      annuncio = db.ANNUNCIO.SingleOrDefault(m => m.TOKEN.ToString() == viewModel.Token &&
                                                                     m.SESSIONE_COMPRATORE == model.SESSIONE_COMPRATORE);
                log.ID_ANNUNCIO         = annuncio.ID;
                log.ID_COMPRATORE       = (Session["utente"] as PersonaModel).Persona.ID;
                log.SESSIONE_COMPRATORE = paypal.Guid;
                log.ID_PAGAMENTO        = payment.id;
                //log.ID_PAGAMENTO = "TEST";
                log.ISTITUTO_PAGAMENTO = "PAYPAL";
                log.NOME_ANNUNCIO      = "Pagamento spedizione per " + annuncio.NOME;
                log.DATA_INSERIMENTO   = DateTime.Now;
                db.LOG_PAGAMENTO.Add(log);
                db.SaveChanges();
                int idPayPal = SavePayPal(db, payment);

                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    viewModel.PagamentoFatto = true;
                    AnnuncioModel annuncioModel = new AnnuncioModel(annuncio);
                    Models.Enumerators.VerificaAcquisto verifica = annuncioModel.Acquisto(db, viewModel, true);
                    if (verifica == Models.Enumerators.VerificaAcquisto.Ok)
                    {
                        OFFERTA offerta = db.OFFERTA.SingleOrDefault(m => m.ID == paypal.Id);
                        if (model.CompletaAcquistoOfferta(db, offerta, idPayPal))
                        {
                            transaction.Commit();
                            this.RefreshPunteggioUtente(db);
                            Models.ViewModels.Email.PagamentoOffertaViewModel pagamentoOfferta = new Models.ViewModels.Email.PagamentoOffertaViewModel();
                            pagamentoOfferta.NominativoDestinatario = offerta.ANNUNCIO.PERSONA.NOME + " " + offerta.ANNUNCIO.PERSONA.COGNOME;
                            pagamentoOfferta.NomeAnnuncio           = offerta.ANNUNCIO.NOME;
                            pagamentoOfferta.Moneta          = offerta.PUNTI;
                            pagamentoOfferta.SoldiSpedizione = offerta.SOLDI;
                            pagamentoOfferta.Baratti         = offerta.OFFERTA_BARATTO.Select(m => m.ANNUNCIO.NOME).ToList();
                            this.SendNotifica((Session["utente"] as PersonaModel).Persona, offerta.ANNUNCIO.PERSONA, TipoNotifica.OffertaPagata, ControllerContext, "pagamentoOfferta", pagamentoOfferta);
                            System.Web.Routing.RouteValueDictionary data = new System.Web.Routing.RouteValueDictionary(new { token = viewModel.Token });
                            _UrlFinePagamento = Url.Action("Index", "Annuncio", data, this.Request.Url.Scheme, this.Request.Url.Host);
                            return(true);
                        }
                        // altrimenti acquisto fallito
                    }
                }
            }
            return(false);
        }
コード例 #3
0
        public PayPalIndexViewModel(AcquistoViewModel viewModel, AnnuncioModel annuncio)
        {
            Token = viewModel.Token;

            if (viewModel.TipoScambio == TipoScambio.Spedizione && viewModel.TipoCarta != TipoCartaCredito.PayPal)
            {
                MetodoPagamento carta = new MetodoPagamento();
                carta.TipoCarta    = viewModel.TipoCarta.ToString();
                carta.Numero       = viewModel.NumeroCarta;
                carta.Cvv2         = ((int)viewModel.Cvv2).ToString();
                carta.Nome         = viewModel.NomeTitolareCarta;
                carta.Cognome      = viewModel.CognomeTitolareCarta;
                carta.MeseScadenza = (int)viewModel.MeseScadenzaCarta;
                carta.AnnoScadenza = (int)viewModel.AnnoScadenzaCarta;
            }
        }
コード例 #4
0
        private bool SaveAcquisto(PayPalIndexViewModel paypal, Payment payment)
        {
            AcquistoViewModel viewModel = Session["PayPalCompra"] as AcquistoViewModel;
            AnnuncioModel     model     = Session["PayPalAnnuncio"] as AnnuncioModel;

            using (DatabaseContext db = new DatabaseContext())
            {
                // AGGIUNGERE TRANSAZIONE NELLA TABELLA LOG_PAGAMENTO
                LOG_PAGAMENTO log      = new LOG_PAGAMENTO();
                ANNUNCIO      annuncio = db.ANNUNCIO.SingleOrDefault(m => m.TOKEN.ToString() == viewModel.Token &&
                                                                     m.SESSIONE_COMPRATORE == model.SESSIONE_COMPRATORE);
                log.ID_ANNUNCIO         = annuncio.ID;
                log.ID_COMPRATORE       = (Session["utente"] as PersonaModel).Persona.ID;
                log.SESSIONE_COMPRATORE = paypal.Guid;
                log.ID_PAGAMENTO        = payment.id;
                //log.ID_PAGAMENTO = "TEST";
                log.ISTITUTO_PAGAMENTO = "PAYPAL";
                log.NOME_ANNUNCIO      = annuncio.NOME;
                log.DATA_INSERIMENTO   = DateTime.Now;
                db.LOG_PAGAMENTO.Add(log);
                db.SaveChanges();
                int idPaypal = SavePayPal(db, payment);
                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    viewModel.PagamentoFatto = true;
                    AnnuncioModel annuncioModel = new AnnuncioModel(annuncio);
                    Models.Enumerators.VerificaAcquisto verifica = annuncioModel.Acquisto(db, viewModel);
                    if (verifica == Models.Enumerators.VerificaAcquisto.Ok)
                    {
                        if (model.CompletaAcquisto(db, viewModel, idPaypal))
                        {
                            transaction.Commit();
                            this.RefreshPunteggioUtente(db);
                            this.SendNotifica(annuncioModel.PERSONA, annuncioModel.PERSONA1, TipoNotifica.AnnuncioAcquistato, ControllerContext, "annuncioAcquistato", annuncioModel);
                            this.SendNotifica(annuncioModel.PERSONA1, annuncioModel.PERSONA, TipoNotifica.AnnuncioVenduto, ControllerContext, "annuncioVenduto", annuncioModel);
                            System.Web.Routing.RouteValueDictionary data = new System.Web.Routing.RouteValueDictionary(new { token = viewModel.Token });
                            _UrlFinePagamento = Url.Action("Index", "Annuncio", data, this.Request.Url.Scheme, this.Request.Url.Host);
                            return(true);
                        }
                        // altrimenti acquisto fallito
                    }
                }
            }
            return(false);
        }
コード例 #5
0
        private List <Transaction> GetListTransactionFromAcquisto(AcquistoViewModel viewModel, AnnuncioModel annuncio, string guid)
        {
            List <Transaction> lista = new List <Transaction>();
            //similar to credit card create itemlist and add item objects to it
            var itemList = new ItemList()
            {
                items = new List <Item>()
            };
            TIPO_VALUTA tipoValuta = (HttpContext.Application["tipoValuta"] as List <TIPO_VALUTA>).SingleOrDefault(m => m.SIMBOLO == NumberFormatInfo.CurrentInfo.CurrencySymbol);

            if (annuncio.TIPO_PAGAMENTO != (int)TipoPagamento.HAPPY)
            {
                if (annuncio.SOLDI != null && annuncio.SOLDI > 0)
                {
                    itemList.items.Add(new Item()
                    {
                        name     = annuncio.NOME,
                        currency = tipoValuta.CODICE,
                        price    = ConvertDecimalToString(annuncio.SOLDI),
                        quantity = "1",
                        sku      = "sku"
                    });
                    //decimal percentualeAnnuncio = Convert.ToDecimal(System.Configuration.ConfigurationManager.AppSettings["annuncioMonetaRealePercentuale"]);
                    //decimal commissioneAnnuncio = (((decimal)annuncio.SOLDI / 100) * percentualeAnnuncio);
                    decimal commissioneAnnuncio = (((decimal)annuncio.SOLDI / 100) * annuncio.COMMISSIONE.PERCENTUALE);
                    itemList.items.Add(new Item()
                    {
                        name     = App_GlobalResources.Language.PayPalAd,
                        currency = tipoValuta.CODICE,
                        price    = ConvertDecimalToString(commissioneAnnuncio),
                        quantity = "1",
                        sku      = "sku"
                    });
                }
            }

            // se presente spedizione
            ANNUNCIO_TIPO_SCAMBIO tipoScambio = annuncio.ANNUNCIO_TIPO_SCAMBIO.FirstOrDefault(m => m.TIPO_SCAMBIO == (int)TipoScambio.Spedizione);

            if (annuncio.ID_OGGETTO != null && tipoScambio != null && viewModel.TipoScambio != TipoScambio.AMano)
            {
                ANNUNCIO_TIPO_SCAMBIO_SPEDIZIONE spedizione = tipoScambio.ANNUNCIO_TIPO_SCAMBIO_SPEDIZIONE.FirstOrDefault();
                if (spedizione != null)
                {
                    itemList.items.Add(new Item()
                    {
                        name     = string.Concat(App_GlobalResources.Language.Shipment, " ", annuncio.NOME),
                        currency = tipoValuta.CODICE,
                        price    = ConvertDecimalToString(spedizione.SOLDI),
                        //price = ConvertDecimalToString(new Decimal(1006.5)), // prova fissa verifica conversione
                        quantity = "1",
                        sku      = "sku"
                    });
                    //decimal percentualeSpedizione = Convert.ToDecimal(System.Configuration.ConfigurationManager.AppSettings["spedizionePercentuale"]);
                    //decimal commissioneSpedizione = (((decimal)spedizione.SOLDI / 100) * percentualeSpedizione);
                    decimal commissioneSpedizione = (((decimal)spedizione.SOLDI / 100) * spedizione.COMMISSIONE.PERCENTUALE);
                    itemList.items.Add(new Item()
                    {
                        name     = App_GlobalResources.Language.PayPalShipment,
                        currency = tipoValuta.CODICE,
                        price    = ConvertDecimalToString(commissioneSpedizione),
                        quantity = "1",
                        sku      = "sku"
                    });
                }
            }

            decimal subtotal = itemList.items.Sum(m => ConvertStringToDecimal(m.price));

            // similar as we did for credit card, do here and create details object
            var details = new Details()
            {
                tax      = "0",
                shipping = "0",
                subtotal = ConvertDecimalToString(subtotal)
            };

            // similar as we did for credit card, do here and create amount object
            var amount = new Amount()
            {
                currency = tipoValuta.CODICE,
                total    = ConvertDecimalToString(subtotal), // Total must be equal to sum of shipping, tax and subtotal.
                details  = details
            };

            Transaction transazione = new Transaction();

            transazione.description    = annuncio.NOTE_AGGIUNTIVE;
            transazione.invoice_number = guid + "|&%" + annuncio.TOKEN.ToString();
            transazione.amount         = amount;
            transazione.item_list      = itemList;

            lista.Add(transazione);
            return(lista);
        }
コード例 #6
0
        public ActionResult Compra(AcquistoViewModel viewModel)
        {
            AnnuncioModel model = null;

            using (DatabaseContext db = new DatabaseContext())
            {
                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Guid token = getTokenDecodificato(viewModel.Token);
                        model = new AnnuncioModel(token, db);
                        if (model.TOKEN == null)
                        {
                            throw new System.Web.HttpException(404, ExceptionMessage.AdNotFound);
                        }

                        if (ModelState.IsValid)
                        {
                            if (!Utility.IsUtenteAttivo(1, TempData))
                            {
                                ModelState.AddModelError("", ErrorResource.UserEnabled);
                            }
                            else
                            {
                                Models.Enumerators.VerificaAcquisto verifica = model.Acquisto(db, viewModel);
                                if (verifica == Models.Enumerators.VerificaAcquisto.Ok)
                                {
                                    if (model.CompletaAcquisto(db, viewModel))
                                    {
                                        TempData["Esito"] = Language.JsonBuyAd;
                                        TempData["pagamentoEffettuato"] = true;
                                        transaction.Commit();
                                        this.RefreshPunteggioUtente(db);
                                        this.SendNotifica(model.PERSONA, model.PERSONA1, TipoNotifica.AnnuncioAcquistato, ControllerContext, "annuncioAcquistato", model);
                                        this.SendNotifica(model.PERSONA1, model.PERSONA, TipoNotifica.AnnuncioVenduto, ControllerContext, "annuncioVenduto", model);
                                        return(RedirectToAction("Index", "Annuncio", new { token = viewModel.Token }));
                                    }
                                    // altrimenti pagamento fallito!
                                }
                                else if (verifica == Models.Enumerators.VerificaAcquisto.VerificaCartaCredito)
                                {
                                    string actionPagamento = "Payment";
                                    if (viewModel.TipoCarta != TipoCartaCredito.PayPal)
                                    {
                                        actionPagamento = "PaymentWithCreditCard";
                                    }
                                    transaction.Commit();
                                    Session["PayPalCompra"]   = viewModel;
                                    Session["PayPalAnnuncio"] = model;
                                    return(RedirectToAction(actionPagamento, "PayPal", new { Id = model.ID, Token = viewModel.Token, Azione = AzionePayPal.Acquisto }));
                                }
                                else
                                {
                                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(string.Format("Messaggio {0} per l'errore {1}", ErrorResource.AdBuyFailed, verifica.ToString())));
                                    ModelState.AddModelError("", ErrorResource.AdBuyFailed);
                                }
                            }
                        }
                        //transaction.Rollback();
                    }
                    catch (System.Web.HttpException eccezione)
                    {
                        //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                        throw new System.Web.HttpException(404, eccezione.Message);
                    }
                    catch (Exception eccezione)
                    {
                        ModelState.AddModelError("", eccezione.Message);
                        //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                    }
                    finally
                    {
                        if (db.Database.CurrentTransaction != null)
                        {
                            transaction.Rollback();
                        }
                    }
                    viewModel.Annuncio        = model.GetViewModel(db);
                    viewModel.Annuncio.Azione = "compra";
                }
            }

            ViewData["acquistoViewModel"] = viewModel;
            return(View("Index", viewModel.Annuncio));
        }
コード例 #7
0
        public ActionResult Index(string token, int pagina = 1)
        {
            AnnuncioModel model = null;

            using (DatabaseContext db = new DatabaseContext())
            {
                using (System.Data.Entity.DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        int     id      = Utility.DecodeToInt(token);
                        OFFERTA offerta = db.OFFERTA.SingleOrDefault(m => m.ID == id);
                        if (offerta == null)
                        {
                            throw new HttpException(404, ExceptionMessage.AdNotFound);
                        }
                        model = new AnnuncioModel(offerta.ANNUNCIO);
                        if (model.TOKEN == null)
                        {
                            throw new HttpException(404, ExceptionMessage.AdNotFound);
                        }

                        AcquistoViewModel viewModel = new AcquistoViewModel(offerta);
                        if (ModelState.IsValid)
                        {
                            if (!Utility.IsUtenteAttivo(1, TempData))
                            {
                                ModelState.AddModelError("", ErrorResource.UserEnabled);
                            }
                            else
                            {
                                Models.Enumerators.VerificaAcquisto verifica = model.Acquisto(db, viewModel, true);
                                if (verifica == Models.Enumerators.VerificaAcquisto.Ok)
                                {
                                    // PENSO CHE QUESTA ACTION SIA USATA SOLO PER OFFERTA E QUINDI CAMBIO CHIAMATA
                                    //if (model.CompletaAcquisto(db, viewModel))
                                    if (model.CompletaAcquistoOfferta(db, offerta))
                                    {
                                        TempData["Esito"] = Language.JsonBuyAd;
                                        TempData["pagamentoEffettuato"] = true;
                                        transaction.Commit();
                                        this.RefreshPunteggioUtente(db);
                                        return(RedirectToAction("Index", "Annuncio", new { token = viewModel.Token }));
                                    }
                                    // altrimenti pagamento fallito!
                                }
                                else if (verifica == Models.Enumerators.VerificaAcquisto.VerificaCartaCredito)
                                {
                                    string actionPagamento = "Payment";
                                    if (viewModel.TipoCarta != TipoCartaCredito.PayPal)
                                    {
                                        actionPagamento = "PaymentWithCreditCard";
                                    }
                                    transaction.Commit();
                                    Session["PayPalCompra"]   = viewModel;
                                    Session["PayPalAnnuncio"] = model;
                                    return(RedirectToAction(actionPagamento, "PayPal", new { Id = offerta.ID, Token = viewModel.Token, Azione = AzionePayPal.OffertaOK }));
                                }
                                else
                                {
                                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(string.Format("Messaggio {0} per l'errore {1}", ErrorResource.AdBuyFailed, verifica.ToString())));
                                    ModelState.AddModelError("", ErrorResource.AdBuyFailed);
                                }
                            }
                        }
                        //transaction.Rollback();
                    }
                    catch (HttpException eccezione)
                    {
                        //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                        throw new HttpException(404, eccezione.Message);
                    }
                    catch (Exception eccezione)
                    {
                        ModelState.AddModelError("", eccezione.Message);
                        //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                    }
                    finally
                    {
                        if (db.Database.CurrentTransaction != null)
                        {
                            transaction.Rollback();
                        }
                    }
                }
                int utente = ((PersonaModel)Session["utente"]).Persona.ID;
                return(View(GetListaOfferte(db, utente, pagina)));
            }
        }