public ActionResult Create([Bind(Include = "Id,VehicleRegistration,VehicleMake,Email,ReferralCode,CardNumber,CvcSecurityCode,Expiry,IsAgree")] TaxInformationModel taxInformationModel) { if (ModelState.IsValid) { string retmsg = null; //int parameter = Convert.ToInt32(Session["Id"].ToString()); db.TaxInformationModels.Add(taxInformationModel); db.SaveChanges(); // payment section bool paymentSuccessful = PaypalPayment.PayWithCreditCard(taxInformationModel); if (!paymentSuccessful) { return(View(taxInformationModel)); } if (System.Web.HttpContext.Current.Session["token"] != null && System.Web.HttpContext.Current.Session["token"].ToString() != "") { return(RedirectToAction(retmsg)); } else { return(RedirectToAction("Details", new RouteValueDictionary( new { controller = "TaxInformation", action = "Details", Id = taxInformationModel.Id }))); } } return(View(taxInformationModel)); }
protected void checkout_Click(object sender, EventArgs e) { CartList = (List <Section>)Session["ScItms"]; var discount = Convert.ToDouble(Session["Discount"].ToString()); APIContext apiContext = PaypalConfiguration.GetAPIContext(); try { String baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/site/student/processPayment.aspx?"; var guid = Convert.ToString(new Random().Next(100000)); var createdPayment = PaypalPayment.CreatePayment(apiContext, baseURI + "guid=" + guid, CartList, discount); var links = createdPayment.links.GetEnumerator(); String paypalRedirectUrl = String.Empty; while (links.MoveNext()) { Links link = links.Current; if (link.rel.ToLower().Trim().Equals("approval_url")) { paypalRedirectUrl = link.href; } } Session.Add(guid, createdPayment.id); Session["cartList"] = CartList; Response.Redirect(paypalRedirectUrl, false); } catch (Exception ex) { PaypalLogger.Log("Error: " + ex.Message); Response.Redirect("~/site/failedPaypal.aspx"); } }
public void ShouldReturnSuccessWhenAddSubscription() { var paypalPayment = new PaypalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "Douglas Corp", _document, _address, _email); _subscription.AddPayments(paypalPayment); _student.AddSubscription(_subscription); Assert.IsTrue(_student.Valid); }
public void ShouldReturnErrorSuccessAddSubscription() { var payment = new PaypalPayment("123456789", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "Wayne Corp", _document, _address, _email); _subscription.AddPayment(payment); _student.AddSubcription(_subscription); Assert.IsTrue(_student.Invalid); }
public void ShoudReturnSuccessWhenHadAddSubscription() { var payment = new PaypalPayment("123789", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "WAYNE CORP", _document, _address, _email); _subscription.AddPayment(payment); _student.AddSubscription(_subscription); Assert.IsTrue(_student.Valid); }
public void ShouldReturnErroWhenHadActiveSubscription() { var payment = new PaypalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "ARX DEV", _document, null, _address); _subscription.AddPayment(payment); _student.AddSubscription(_subscription); _student.AddSubscription(_subscription); Assert.IsTrue(_student.Invalid); }
public void ShouldReturnErrorWhenHadActiveSubscription() { PaypalPayment paypalPayment = new PaypalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 250, this.doc, "Heitor", 250, this.address, this.email); this.subscription.AddPayment(paypalPayment); this.student.AddSubscriptions(this.subscription); this.student.AddSubscriptions(this.subscription); Assert.IsTrue(student.Invalid); }
public void SholdReturnErrorWhenHadActiveSubscription() { var payment = new PaypalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, _document, "WAYNE CORP", _address, _email); _subscription.AddPayment(payment); _student.AddSubscription(_subscription); _student.AddSubscription(_subscription); Assert.IsTrue(_student.Invalid); }
public void ShouldReturnSuccessWhenHadNoActiveSubscription() { var payment = new PaypalPayment(_email, "12345678", DateTime.Now, DateTime.Now.AddDays(10), 10, 10, "Wayner corp", _document, _address); _subscription.AddPayment(payment); _student.AddSubscription(_subscription); _student.AddSubscription(_subscription); Assert.IsTrue(_student.Valid); }
public void PaypalPaymentAcceptsSimplePaymentDetails() { var sut = new PaypalPayment(); var informationModifier = new SimplePaymentDetails(); sut.AcceptModificationsBy(informationModifier); Assert.That( informationModifier.GetModifiedData, Is.EqualTo("PaypalDescription"), "description"); }
public void ShouldReturnErrorWhenHadActiveSubscription() { // Deve retornar um erro quando tiver mais de uma assinatura ativa var payment = new PaypalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "WAYNE", _document, _address, _email); _subscription.AddPayment(payment); _student.AddSubscription(_subscription); _student.AddSubscription(_subscription); Assert.IsTrue(_student.Invalid); }
public void ShouldReturnErrorWhenHadActiveSubscription() { //passa duas inscrições var subscription = new Subscription(null); var payment = new PaypalPayment("12345678", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "WAYNE CORP", _document, _address, _email); subscription.AddPayment(payment); _student.AddSubscription(subscription); _student.AddSubscription(subscription); Assert.IsTrue(_student.Invalid); }
public ICommandResult Handle(CreatePayPalSubscriptionCommand command) { /*command.Validate(); * if(command.Invalid) * { * AddNotifications(command); * return new CommandResult(false, "Não foi possivel realizar sua assinatura"); * }*/ if (_studentRepository.DocumentExists(command.Document)) { AddNotification("Document", "Este CPF já está em uso"); } if (_studentRepository.DocumentExists(command.EnderecoEmail)) { AddNotification("Document", "Este CPF já está em uso"); } var _name = new Name(command.FirstName, command.LastName); var _document = new Document(command.Document, Domain.Enum.EDocumentType.CPF); var _email = new Email(command.EnderecoEmail); var _address = new Address(command.Rua, command.Bairro, command.Cidade, command.Estado, command.Pais, command.Complemento, command.Numero, command.CEP); var _student = new Student(_name, _document, _email); var _subscription = new Subscription(DateTime.Now.AddMonths(1)); var paypalPayment = new PaypalPayment( command.TransactionCode, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, command.Owner, new Document(command.PayerDocument.Number, command.PayerDocumentType), _address, _email ); _subscription.AddPayments(paypalPayment); _student.AddSubscription(_subscription); AddNotifications(_name, _document, _email, _address, _student, _subscription, paypalPayment); if (Invalid) { return(new CommandResult(false, "Não foi possivel realizar sua assinatura")); } _studentRepository.CreateSubscription(_student); _emailService.Send(_student.Name.ToString(), _student.Email.EnderecoEmail, "Bem vindo", "Sua assinatura foi criada"); AddNotifications(new Contract()); return(new CommandResult(true, "Assinatura realizada com sucesso")); }
public async Task <int> AddPayPalPaymentAsync(int orderId, string token, string payerID, string link) { var payPlPayment = new PaypalPayment() { OrderId = orderId, LinkDetail = link, PayerId = payerID, Token = token }; await _context.AddAsync(payPlPayment); return(await _context.SaveChangesAsync()); }
public StudentTests() { var name = new Name("Lucas", "Eschechola"); var document = new Document("12345678901", EDocumentType.CPF); var email = new Email("*****@*****.**"); var address = new Address("Rua 1", "12", "Bairro", "Sampa", "SP", "BR", "12356700"); _student = new Student(name, document, email); var payment = new PaypalPayment(email, "1224x", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, address, "Lucas", document); _payment = payment; _subscription = new Subscription(null); }
public void ShouldReturnErrorWhenHadActiveSubscription() { var name = new Name("Bruce", "Wayne"); var document = new Document("26162128032", EDocumentType.CPF); var email = new Email("*****@*****.**"); var address = new Address("Rua 1", "1234", "bairro legal", "gothan", "RJ", "BR", "1234567"); var student = new Student(name, document, email); var subscription = new Subscription(null); var payment = new PaypalPayment("1234567", DateTime.Now, DateTime.Now.AddDays(5), 10, 10, "WAYNE CORP", document, address, email); subscription.AddPayment(payment); student.AddSubscription(subscription); student.AddSubscription(subscription); Assert.Fail(); }
public ICommandResult Handler(CreatePayPalSubscriptionCommand command) { if (_repository.DocumentExist(command.Document)) { AddNotification("Document", "Este CPF já está em uso."); } if (_repository.DocumentExist(command.Email)) { AddNotification("Email", "Este Email já está em uso."); } var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Document, EDocumentType.CPF); var email = new Email(command.Email); var address = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode); var student = new Student(name, document, email); var subscription = new Subscription(DateTime.Now.AddMonths(1)); var payment = new PaypalPayment( command.TransactionCode, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, command.Payer, new Document(command.PayerDocument, command.PayerDocumentType), address, email ); subscription.AddPayment(payment); student.AddSubscription(subscription); AddNotifications(name, document, email, address, student, subscription, payment); if (Invalid) { return(new CommandResult(false, "Não foi possível realizar a sua assinatura.")); } _repository.CreateSubscription(student); _emailService.Send(student.Name.ToString(), student.Email.ToString(), "Bem vindo ao Site", "Sua Assinatura foi criada."); return(new CommandResult(true, "Assinatura realizada com sucesso.")); }
public ICommandResult Handle(CreatePayPalSubscriptionCommand command) { //Verify whether document is already registred if (_repository.DocumentExists(command.Document)) { AddNotification("Document", "Este CPF ja esta em uso"); } //Verify whether eamil is already registred if (_repository.EmailExists(command.Email)) { AddNotification("Email", "Este Email ja esta em uso"); } //Generate VOs var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Document, EDocumentType.CPF); var email = new Email(command.Email); var address = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode); //Generate Entities var student = new Student(name, document, email); var subscription = new Subscription(DateTime.Now.AddMonths(1)); var payment = new PaypalPayment(command.TransactionCode, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, command.Payer, new Document(command.PaymentNumber, command.PayerDocumentType), address, email); //Apply Relationship subscription.AddPayment(payment); student.AddSubcription(subscription); //Group Validation AddNotifications(name, document, email, address, student, subscription, payment); //Save information _repository.CreateSubscription(student); //Send Welcome E-mail _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao guilherme.io", "Sua assinatura foi criada"); //Return information return(new CommandResult(true, "Assinatura realizada com sucesso.")); }
protected void Page_Load(object sender, EventArgs e) { APIContext apiContext = PaypalConfiguration.GetAPIContext(); String transactionId = ""; try { var guid = Request.Params["guid"]; var payerId = Request.Params["payerId"]; var executedPayment = PaypalPayment.ExecutePayment(apiContext, payerId, Session[guid] as String); if (!executedPayment.state.ToLower().Equals("approved")) { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertmeErr()", true); //Response.Redirect("~/site/failedPaypal.aspx"); } transactionId = executedPayment.transactions[0].related_resources[0].sale.id; } catch (Exception ex) { String g = ex.Message; Response.Redirect("~/site/failedPaypal.aspx"); } List <Section> cartList = (List <Section>)Session["cartList"]; foreach (Section item in cartList) { string username = Session["Username"].ToString(); DateTime today = DateTime.Now; DateTime expirationDate = today.AddYears(1); //MOMENTANEAMENTE SE COLOCO QUE VENCE EN UN AÑO Double amount = item.Amount + (item.Amount * 0.21); Student student = new Student(username, ""); //OBTENER EL OBJETO DEL ESTUDIANTE QUE INICIO SESION int remainingClasses = 10; AraPayment payment = new AraPayment(today, expirationDate, transactionId, amount, remainingClasses, item, student); CreateAraPaymentCommand cmd = new CreateAraPaymentCommand(payment); cmd.Execute(); Session["ScItms"] = null; /*DESCOMENTAR CUANDO FUNCIONE TODO EL BACK Y SE PASE CORRECTAMENTE EL ESTUDIANTE Y LOS MODULOS*/ } ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true); //Response.Redirect("/site/student/successPaypal.aspx"); }
public ICommandResult Handle(CreatePaypalSuscriptionCommand command) { //Verificar se o dominio já está cadastrado if (_studentRepository.DocumentExists(command.Document)) { AddNotification("Document", "Este CPF já está em uso"); } //Verificar se E-mail já está cadastrado if (_studentRepository.DocumentExists(command.Email)) { AddNotification("Email", "Este Email já está em uso"); } //Gerar os VOs var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Document, EDocumentType.CPF); var email = new Email(command.Document); var address = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode); var student = new Student(name, document, email); var subscription = new Subscription(DateTime.Now.AddMonths(1)); var payment = new PaypalPayment(command.TransactionCode, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, new Document(command.Number, command.Type), command.Payer, address, email); //Relacionamentos subscription.AddPayment(payment); student.AddSubscription(subscription); //Agrupar as notificaçõs AddNotifications(name, document, email, address, student, subscription, payment); //Salvar as informações _studentRepository.CreateSubscription(student); //Enviar E-mail de boas vindas _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao Sistema", "Assinatura criada"); return(new CommandResult(true, "Assinatura realizada com sucesso")); }
public ServiceResponse <string> PaymentUrl(PayPalProduct product) { var serviceResponse = new ServiceResponse <string>(); try { double cartAmount = 0; var itemList = new ItemList(); var items = new List <Item>(); var apiContext = GetAPIContext(_applicationSettings.ClientId, _applicationSettings.ClientSecret); var payment = new PaypalPayment(); payment.SiteURL = product.ReturnUrl; payment.InvoiceNumber = $"{Guid.NewGuid()}"; payment.Currency = product.CurrencyCode; payment.Tax = $"{product.Tax}"; payment.ShippingFee = $"{product.ShippingFee}"; payment.OrderDescription = $"{product.Description}"; payment.ProductList.Add(product); foreach (var cartItem in payment.ProductList) { if (cartItem.OrderQty > 0) { var Item = new Item(); Item.name = cartItem.Description; Item.currency = payment.Currency; Item.price = Math.Round(cartItem.UnitPrice, 2).ToString(); Item.quantity = cartItem.OrderQty.ToString(); Item.sku = cartItem.SKU; items.Add(Item); cartAmount += Convert.ToDouble(Math.Round(cartItem.UnitPrice, 2)) * Convert.ToDouble(Item.quantity); } } itemList.items = items; cartAmount = Math.Round(cartAmount, 2); var payer = new Payer() { payment_method = "paypal" }; var redirUrls = new RedirectUrls() { cancel_url = payment.SiteURL + "?cancel=true", return_url = payment.SiteURL }; var details = new Details() { tax = payment.Tax.ToString(), shipping = payment.ShippingFee.ToString(), subtotal = cartAmount.ToString() }; var paypalAmount = new Amount() { currency = payment.Currency, total = cartAmount.ToString(), details = details }; var transactionList = new List <Transaction>(); Transaction transaction = new Transaction(); transaction.description = payment.OrderDescription; transaction.invoice_number = payment.InvoiceNumber; transaction.amount = paypalAmount; transaction.item_list = itemList; transactionList.Add(transaction); var processedPayment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; var createdPayment = processedPayment.Create(apiContext); var links = createdPayment.links.GetEnumerator(); while (links.MoveNext()) { var link = links.Current; if (link.rel.ToLower().Trim().Equals("approval_url")) { serviceResponse.Message = "Success"; serviceResponse.Success = true; serviceResponse.Response = link.href; } } } catch (Exception error) { serviceResponse.Message = $"Error while generating payment url, please retry."; serviceResponse.Error = error; serviceResponse.Success = false; } return(serviceResponse); }
public ICommandResult Handle(CreatePayPalSubscriptionCommand command) { // Fail fast validation command.Validate(); if (command.Invalid) { AddNotifications(command); return(new CommandResult(false, "Não foi possível realizar sua assinatura")); } // Verificar se Documento já está cadastrado if (_repository.DocumentExists(command.Document)) { AddNotification("Document", "Este CPF já está em uso"); } // Verificar se E-mail já está cadastrado if (_repository.EmailExists(command.Email)) { AddNotification("Email", "Este Email já está em uso"); } // Gerar VOs var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Document, EDocumentType.CPF); var email = new Email(command.Email); var address = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode); // Gerar entidades var student = new Student(name, document, email); var subscription = new Subscription(DateTime.Now.AddMonths(1)); var payment = new PaypalPayment( command.TransactionCode, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, command.Payer, new Document(command.PayerDocument, command.PayerDocumentType), address, email); // Relacionamentos subscription.AddPayment(payment); student.AddSubscription(subscription); // Agrupar as validações AddNotifications(name, document, email, address, student, subscription, payment); // Checar notificações if (Invalid) { return(new CommandResult(false, "Não foi possível realizar sua assinatura")); } // Salvar as infromações _repository.CreateSubscription(student); // Enviar e-mail de boas vindas _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao balta.io", "Sua assinatura foi criado com sucesso"); // Retornar informações return(new CommandResult(true, "Assinatura realizada com sucesso")); }
public ICommandResult Handle(CreatePayPalSubscriptionCommand command) { //Fail Fast Validations command.Validate(); if (command.Invalid) { AddNotifications(command); return(new CommandResult(false, "Não foi possível realizar o cadastro")); } //Check if document is already registered if (_repository.DocumentExists(command.Document)) { AddNotification("Document", "Este documento já está em uso"); } //Check if email is already registered if (_repository.EmailExists(command.Email)) { AddNotification("Email", "Este e-mail já está em uso"); } //Create VOs var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Document, EDocumentType.CPF); var email = new Email(command.Email); var address = new Address(command.Street, command.StreetNumber, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode); var payerDocument = new Document(command.PayerDocument, command.PayerDocumentType); //Create Entitites var student = new Student(name, document, email); var subscription = new Subscription(command.ExpireDate); var payment = new PaypalPayment( command.TransactionCode, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, address, payerDocument, command.Payer, email); //Relationships subscription.AddPayment(payment); student.AddSubscription(subscription); //Apply Validations AddNotifications(name, document, email, address, student, subscription, payment); if (Invalid) { return(new CommandResult(false, "Não foi possível realizar sua assinatura")); } //Save data _repository.CreateSubscription(student); //Sent Welcome email _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem-vindo!", "Sua assinatura foi criada"); //Return return(new CommandResult(true, "Assinatura realizada com sucesso")); }
public async Task <ActionResult> Index(FormCollection form) { if (form["selectedProducts"] == null) { return(View(products)); } var skuArray = form["selectedProducts"].Length > 0 ? form["selectedProducts"].Split(',') : new string[] { }; var selectedProducts = skuArray.Select(item => products.FirstOrDefault(x => x.Sku == item)).Where(product => product != null).ToList(); double shippingPrice = 10; double shippingDiscount = 10; //taking the quantities foreach (var item in selectedProducts) { var quantity = form[$"quantity_{item.Sku}"]; item.Quantity = Convert.ToInt32(quantity); } var shippingAddress = new PayPalShippingAddress() { RecipientName = form["RecipientName"], Line1 = form["Line1"], Line2 = form["Line2"], City = form["City"], CountryCode = form["CountryCode"], PostalCode = form["PostalCode"], Phone = form["Phone"], State = form["State"] }; var transaction = new PayPalTransaction( selectedProducts, shippingAddress, form["invoiceNumber"], "The payment transaction description.", AllowedPaymentMethod.INSTANT_FUNDING_SOURCE, PayPalCurrency.AUD, shippingPrice, shippingDiscount); var payment = new PaypalPayment( Intent.SALE, PaymentMethod.PAYPAL, "Contact us for any questions on your order.", transaction); var createPayment = await paypalCheckout.CreatePayment(payment); if (createPayment.Error == null) { var redirectUrl = createPayment.Links.FirstOrDefault(x => x.Method == PayPalLinkMethod.REDIRECT)?.Href; Response.Redirect(redirectUrl, true); } else { ViewBag.Error = createPayment.Error.Message; ViewBag.ErrorDetails = createPayment.Error.Details; ViewBag.Output = JsonConvert.SerializeObject(payment); } return(View(products)); }