// GET: PaymentFailure public ActionResult PaymentFailure(string token, string orderId) { if (string.IsNullOrEmpty(token)) { return(RedirectToAction("index", "home")); } if (string.IsNullOrEmpty(orderId)) { return(RedirectToAction("index", "home")); } var orderModel = OrderStrCrypto.Decrypt(orderId); if (orderModel == null) { return(RedirectToAction("index", "home")); } var order = _db.Orders.FirstOrDefault(x => x.Id == orderModel.OrderId && x.UserId == orderModel.UserId); if (order == null) { return(RedirectToAction("index", "home")); } var result = PayPalService.GetPayment(token); order.Status = OrderStatus.Canceled; order.OrderDate = DateTimeOffset.UtcNow; _db.SaveChanges(); return(RedirectToAction("index", "Cart")); }
public IActionResult Pay() { PayPalConfig payPalConfig = PayPalService.GetPayPalConfig(); ViewBag.payPalConfig = payPalConfig; return(View()); }
public IActionResult Checkout(CheckoutViewModel checkoutViewModel) { checkoutViewModel.cartItem = SessionHelper.GetObjectFromJson <List <CartItem> >(HttpContext.Session, "cart"); checkoutViewModel.payPalConfig = PayPalService.GetPayPalConfig(); return(View(checkoutViewModel)); }
public ActionResult PatchShipping() { var store = Services.StoreContext.CurrentStore; var customer = Services.WorkContext.CurrentCustomer; var session = _httpContext.GetPayPalState(PayPalPlusProvider.SystemName, customer, store.Id, _genericAttributeService); if (session.AccessToken.IsEmpty() || session.PaymentId.IsEmpty()) { // Session expired. Reload payment wall and create new payment (we need the payment id). session.SessionExpired = true; return(new JsonResult { Data = new { success = false, error = string.Empty, reload = true } }); } var settings = Services.Settings.LoadSetting <PayPalPlusPaymentSettings>(store.Id); var cart = customer.GetCartItems(ShoppingCartType.ShoppingCart, store.Id); var result = PayPalService.PatchShipping(settings, session, cart); var errorMessage = result.ErrorMessage; if (!result.Success && result.IsValidationError) { errorMessage = string.Concat(T("Plugins.SmartStore.PayPal.PayPalValidationFailure"), "\r\n", errorMessage); } return(new JsonResult { Data = new { success = result.Success, error = errorMessage, reload = false } }); }
static void Main(string[] args) { //List<Installment> parcelas = new List<Installment>(); Console.WriteLine("Digite o número do contrato: "); int numero = int.Parse(Console.ReadLine()); Console.WriteLine("Digite a Data: "); DateTime data = DateTime.Parse(Console.ReadLine()); Console.WriteLine("Digite o valor do contrato"); float total = float.Parse(Console.ReadLine()); Console.WriteLine("Digite o total de parcelas: "); int par = int.Parse(Console.ReadLine()); Contract contrato = new Contract(numero, data, total); PayPalService p = new PayPalService(); ContractService a = new ContractService(p); a.ProcessContract(contrato, par); Console.WriteLine("--------------------Parcelas---------------------"); Console.WriteLine(contrato.Installments.Count); foreach (Installment x in contrato.Installments) { Console.WriteLine($"{x.DueDate} - {x.Amount:c}"); } }
public override VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest) { var result = new VoidPaymentResult { NewPaymentStatus = voidPaymentRequest.Order.PaymentStatus }; var settings = Services.Settings.LoadSetting <TSetting>(voidPaymentRequest.Order.StoreId); var session = new PayPalSessionData(); var apiResult = PayPalService.EnsureAccessToken(session, settings); if (apiResult.Success) { apiResult = PayPalService.Void(settings, session, voidPaymentRequest); if (apiResult.Success) { result.NewPaymentStatus = PaymentStatus.Voided; } } if (!apiResult.Success) { result.Errors.Add(apiResult.ErrorMessage); } return(result); }
public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest) { var result = new CapturePaymentResult { NewPaymentStatus = capturePaymentRequest.Order.PaymentStatus }; var settings = Services.Settings.LoadSetting <TSetting>(capturePaymentRequest.Order.StoreId); var session = new PayPalSessionData(); var apiResult = PayPalService.EnsureAccessToken(session, settings); if (apiResult.Success) { apiResult = PayPalService.Capture(settings, session, capturePaymentRequest); if (apiResult.Success) { result.NewPaymentStatus = PaymentStatus.Paid; } } if (!apiResult.Success) { result.Errors.Add(apiResult.ErrorMessage); } return(result); }
public ActionResult PatchShipping() { var session = HttpContext.GetPayPalSessionData(); if (session.AccessToken.IsEmpty() || session.PaymentId.IsEmpty()) { // Session expired. Reload payment wall and create new payment (we need the payment id). session.SessionExpired = true; return(new JsonResult { Data = new { success = false, error = string.Empty, reload = true } }); } var store = Services.StoreContext.CurrentStore; var customer = Services.WorkContext.CurrentCustomer; var settings = Services.Settings.LoadSetting <PayPalPlusPaymentSettings>(store.Id); var cart = customer.GetCartItems(ShoppingCartType.ShoppingCart, store.Id); var result = PayPalService.PatchShipping(settings, session, cart, PayPalPlusProvider.SystemName); return(new JsonResult { Data = new { success = result.Success, error = result.ErrorMessage, reload = false } }); }
public override RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest) { var result = new RefundPaymentResult { NewPaymentStatus = refundPaymentRequest.Order.PaymentStatus }; var settings = Services.Settings.LoadSetting <TSetting>(refundPaymentRequest.Order.StoreId); var session = new PayPalSessionData(); var apiResult = PayPalService.EnsureAccessToken(session, settings); if (apiResult.Success) { apiResult = PayPalService.Refund(settings, session, refundPaymentRequest); if (apiResult.Success) { if (refundPaymentRequest.IsPartialRefund) { result.NewPaymentStatus = PaymentStatus.PartiallyRefunded; } else { result.NewPaymentStatus = PaymentStatus.Refunded; } } } if (!apiResult.Success) { result.Errors.Add(apiResult.ErrorMessage); } return(result); }
public ActionResult Promotion(string origin, decimal amount) { try { var store = Services.StoreContext.CurrentStore; if (_pluginFinder.Value.IsPluginReady(Services.Settings, Plugin.SystemName, store.Id)) { if (_paymentService.Value.IsPaymentMethodActive(PayPalInstalmentsProvider.SystemName, store.Id)) { var settings = Services.Settings.LoadSetting<PayPalInstalmentsSettings>(store.Id); var session = _httpContext.GetPayPalState(PayPalInstalmentsProvider.SystemName); var model = PayPalService.GetFinancingOptions(settings, session, origin, amount); if (model != null) { return PartialView(model); } } } } catch (Exception ex) { Logger.Error(ex); } return new EmptyResult(); }
public CartController() { _paypalService = new PayPalService(); _cartService = new CartService(); _context = ApplicationDbContext.Create(); _emailService = new OrderEmailService(); }
// Ajax. public ActionResult PromotionPopup(string origin, decimal amount) { try { var store = Services.StoreContext.CurrentStore; if (!_pluginFinder.Value.IsPluginReady(Services.Settings, Plugin.SystemName, store.Id) || !_paymentService.Value.IsPaymentMethodActive(PayPalInstalmentsProvider.SystemName, store.Id)) { return HttpNotFound(); } var settings = Services.Settings.LoadSetting<PayPalInstalmentsSettings>(store.Id); var session = _httpContext.GetPayPalState(PayPalInstalmentsProvider.SystemName); var model = PayPalService.GetFinancingOptions(settings, session, origin, amount, PayPalPromotion.FinancingExample); if (model != null) { return PartialView(model); } else { return Content("<div class='alert alert-info'>{0}</div>".FormatInvariant(T("Plugins.Payments.PayPalInstalments.NoFinancingDetails"))); } } catch (Exception ex) { Logger.Error(ex); return Content("<div class='alert alert-error'>{0}</div>".FormatInvariant(ex.ToAllMessages().HtmlEncode())); } }
public IActionResult ShoppingCart() { List <OfferedLabourerService> serviceList = new List <OfferedLabourerService>(); //Check if we're logged in. bool loggedIn = SessionController.returnLoggedIn(this.HttpContext); if (!loggedIn) { //Not logged in, get products from cookies List <string> keyList = Request.Cookies.Keys.Where(k => k.StartsWith("SC")).ToList(); serviceList = Utility.CookieController.fetchItemsInCookies(keyList); } else { //Logged in, get products from database List <Object> offeredServiceIds = MollShopContext.GetShoppingCartItems((int)HttpContext.Session.GetInt32("UserId")); serviceList = new List <OfferedLabourerService>(); foreach (Object id in offeredServiceIds) { serviceList.Add(ElasticSearch.Queries.EsOLSQuery <object> .findByOfferedServiceId((int)id)); } } PayPalConfig payPalConfig = PayPalService.getPayPalConfig(); ViewBag.payPayConfig = payPalConfig; return(View(serviceList)); }
public ActionResult Checkout(FormCollection collection) { Service service = new Service(); PayPalIndexViewModel model = new PayPalIndexViewModel(); var PayPalService = new PayPalService(); var gateway = PayPalService.PayPalGateway(); var user = UserManager.FindByName(User.Identity.Name); var userInfo = service.GetProfileInfo(user.Id); var memberInfo = service.GetMembership(user.UserName); var subscriptionInfo = service.GetSubscription(memberInfo.MembershipId); var radioButton = collection["radioButton"]; string nonce = collection["payment_method_nonce"]; DateTime startDate = DateTime.Now; DateTime expireDate = DateTime.Now; // Use payment method nonce here if (radioButton == "Monthly") { expireDate.AddMonths(1); Result <Subscription> subResult = PayPalService.PayPalSubscription(nonce, ConstantStrings.annualPlanId); if (subResult.IsSuccess()) { Subscription transaction = subResult.Target; ViewData["TransactionId"] = transaction.Id; service.InactivateSubscription(subscriptionInfo.SubscriptionId); service.CreateSubscription(memberInfo.MembershipId, startDate, expireDate, ConstantStrings.monthlySubscription, subResult.Target.Id); } else { ViewData["Message"] = subResult.Message; } } else if (radioButton == "Annually") { expireDate.AddYears(1); Result <Subscription> subResult = PayPalService.PayPalSubscription(nonce, ConstantStrings.annualPlanId); if (subResult.IsSuccess()) { Subscription transaction = subResult.Target; ViewData["TransactionId"] = transaction.Id; service.InactivateSubscription(subscriptionInfo.SubscriptionId); service.CreateSubscription(memberInfo.MembershipId, startDate, expireDate, ConstantStrings.annualSubscription, subResult.Target.Id); } else { ViewData["Message"] = subResult.Message; } } UserManager.RemoveFromRole(user.Id, "Basic"); UserManager.AddToRole(user.Id, "Premium"); return(View()); }
public IActionResult Checkvalid(CheckoutViewModel checkoutViewModel) { checkoutViewModel.cartItem = SessionHelper.GetObjectFromJson <List <CartItem> >(HttpContext.Session, "cart"); checkoutViewModel.payPalConfig = PayPalService.GetPayPalConfig(); if (ModelState.IsValid) { return(RedirectPreserveMethod(checkoutViewModel.payPalConfig.PostUrl)); } return(View("checkout", checkoutViewModel)); }
private async Task TestAsync(string receiverEmail = AppSettings.OUR_PAYPAL_EMAIL, string paymentStatus = IPN.Payment.Status.COMPLETED) { PayPalService payPalService = CreatePayPalService(); string payPalRequestString = GetPayPalRequestString( receiverEmail, paymentStatus ); await payPalService.VerifyAndLogAsync(payPalRequestString).ConfigureAwait(false); }
public override void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { var instruction = PayPalService.CreatePaymentInstruction(HttpContext.GetPayPalSessionData().PaymentInstruction); if (instruction.HasValue()) { HttpContext.Session[CheckoutCompletedKey] = instruction; OrderService.AddOrderNote(postProcessPaymentRequest.Order, instruction, true); } }
public void TestInitialize() { var configuration = new PayPalRestConfiguration { ClientId = "AaRbKe2riATpDsXJy0x9ut3_qfE23e5ftPeGQmdl3j7HUFMaLnFArVe7QqC8chhvcVilQb9-QnXNzNWr", ClientSecret = "EAdr_JFKnrP-qdYehzOxfflmxCAvqgMcRrWgf4yOgFv-pNdmE49e92ETopqGNnjgiSJlFTe5cu5GehMh", Mode = "sandbox" }; _logger = new Mock <ILog>(); _payPalService = new PayPalService(configuration, _logger.Object); }
public IActionResult Checkvalid(CheckoutViewModel checkoutViewModel) { checkoutViewModel.cartItem = SessionHelper.GetObjectFromJson <List <CartItem> >(HttpContext.Session, "cart"); checkoutViewModel.payPalConfig = PayPalService.GetPayPalConfig(); var conf = PayPalService.GetPayPalConfig(); SessionHelper.SetObjectAsJson(HttpContext.Session, "billInfo", checkoutViewModel.BillCheckout); string uriSetting = "cmd=_cart" + $"&business={conf.Business}" + "&upload=1" + $"&return={conf.ReturnUrl}" + $"&cancel_return={Hosting.Name}/Checkout/Cancel" + "&no_shipping=1"; string uriCart = ""; int i = 1; double sum = 0; foreach (var item in checkoutViewModel.cartItem) { var priceConvert = item.product.DiscountPrice; uriCart += $"&item_number_{i}={i}" + $"&item_name_{i}={item.product.ProductName}" + $"&amount_{i}={priceConvert}" + $"&quantity_{i}={item.Quantity}"; sum += priceConvert * item.Quantity; i++; } ////Shipping uriCart += $"&item_number_{i}={i}" + $"&item_name_{i}=Shipping Fee" + $"&amount_{i}={2}" + $"&quantity_{i}=1"; //i++; //var discount = checkoutViewModel.cartItem.Sum(x => x.product.DiscountPrice * x.Quantity) * 0.00004; //discount = discount * 0.1; ////Discount //uriCart += $"&item_number_{i}={i}" + // $"&item_name_{i}=Discount" + // $"&amount_{i}={discount}" + // $"&quantity_{i}=1"; if (ModelState.IsValid) { return(Redirect($"{checkoutViewModel.payPalConfig.PostUrl}?{uriSetting}{uriCart}")); } return(View("checkout", checkoutViewModel)); }
public override void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { var storeId = postProcessPaymentRequest.Order.StoreId; var customer = Services.WorkContext.CurrentCustomer; var session = HttpContext.GetPayPalState(_providerSystemName, customer, storeId, GenericAttributeService); var instruction = PayPalService.CreatePaymentInstruction(session.PaymentInstruction); if (instruction.HasValue()) { HttpContext.Session[CheckoutCompletedKey] = instruction; OrderService.AddOrderNote(postProcessPaymentRequest.Order, instruction, true); } }
public ActionResult PatchShipping() { var store = Services.StoreContext.CurrentStore; var customer = Services.WorkContext.CurrentCustomer; var settings = Services.Settings.LoadSetting <PayPalPlusPaymentSettings>(store.Id); var cart = customer.GetCartItems(ShoppingCartType.ShoppingCart, store.Id); var session = HttpContext.GetPayPalSessionData(); var apiResult = PayPalService.PatchShipping(settings, session, cart, PayPalPlusProvider.SystemName); return(new JsonResult { Data = new { success = apiResult.Success, error = apiResult.ErrorMessage } }); }
public IActionResult Index() { var cart = SessionHelper.GetObjectFromJson <List <ItemViewModel> >(HttpContext.Session, "cart"); if (cart != null) { ViewBag.cart = cart; ViewBag.total = cart.Sum(i => i.Product.UnitPrice * i.Quantity); } PayPalConfig payPalConfig = PayPalService.GetPayPalConfig(); ViewBag.PayPalConfig = payPalConfig; return(View()); }
public PaymentsServiceTest() { var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); var configurationProvider = new PayPalConfigurationProvider(configuration); var payPalService = new PayPalService(configurationProvider); var options = new DbContextOptionsBuilder <PaymentsContext>() .UseInMemoryDatabase("payments_service_test") .Options; var context = new PaymentsContext(options); DataSeeder.Seed(options); _unitOfWork = new PaymentsUnitOfWork(context); _paymentsService = new PaymentsService(payPalService, _unitOfWork); }
public ActionResult PaymentInfo() { FinancingOptions model = null; try { var store = Services.StoreContext.CurrentStore; var settings = Services.Settings.LoadSetting<PayPalInstalmentsSettings>(store.Id); var session = _httpContext.GetPayPalState(PayPalInstalmentsProvider.SystemName); model = PayPalService.GetFinancingOptions(settings, session, "paymentinfo", decimal.Zero); } catch (Exception ex) { Logger.Error(ex); } return PartialView(model ?? new FinancingOptions("paymentinfo")); }
public IActionResult PaymentMethod(string fld_email, string fld_firstname, string fld_lastname, string fld_address, string fld_zipcode) { //The variables received from this form will be used to create the confirmation email later on HttpContext.Session.SetString("FORM", fld_firstname + ";" + fld_lastname + ";" + fld_address + ";" + fld_zipcode + ";" + fld_email); //This view will show the users their options for paying //In reality, the user would be able to choose between IDEAL, PayPal, etc. However, we only have PayPal List <OfferedLabourerService> olsList = ParseOrdersToOLS(); PayPalConfig payPalConfig = PayPalService.getPayPalConfig(); ViewBag.payPayConfig = payPalConfig; return(View(olsList)); }
// GET: PaymentGateway public ActionResult ExpressCheckoutSuccess(string token, string orderId) { if (string.IsNullOrEmpty(token)) { return(RedirectToAction("index", "home")); } if (string.IsNullOrEmpty(orderId)) { return(RedirectToAction("index", "home")); } var orderModel = OrderStrCrypto.Decrypt(orderId); if (orderModel == null) { return(RedirectToAction("index", "home")); } var order = _db.Orders.FirstOrDefault(x => x.Id == orderModel.OrderId && x.UserId == orderModel.UserId); if (order == null) { return(RedirectToAction("index", "home")); } var result = PayPalService.GetPayment(token); order.Status = result.Success ? OrderStatus.Success : OrderStatus.Fail; order.OrderDate = result.OrderDate; order.TotalCost = result.Success ? result.OrderTotal : (decimal?)null; _db.SaveChanges(); if (result.Success) { Session["cart"] = null; return(RedirectToAction("Thankyou", "Cart")); } else { Session["cart"] = null; return(RedirectToAction("Index", "Cart", new { message = result.ErrorMessage })); } }
public ActionResult Index() { if (Models.SessionExtensions.Get <List <Item> >(HttpContext.Session, "cart") == null) { return(View("error")); } else { var cart = Models.SessionExtensions.Get <List <Item> >(HttpContext.Session, "cart"); ViewBag.cart = cart; ViewBag.total = cart.Sum(item => item.Price * item.Quantity); } PayPalConfig payPalConfig = PayPalService.GetPayPalConfig(); ViewBag.payPalConfig = payPalConfig; return(View()); }
public ActionResult Index() { PayPalIndexViewModel model = new PayPalIndexViewModel(); Service service = new Service(); var user = UserManager.FindByName(User.Identity.Name); var customerId = service.GetCustomer(user.Id); var PayPalService = new PayPalService(); var gateway = PayPalService.PayPalGateway(); var clientToken = gateway.ClientToken.generate( new ClientTokenRequest { CustomerId = customerId } ); model.ClientToken = clientToken; TempData["ClientToken"] = clientToken; return(View(model)); }
public IActionResult Index() { string pay_status = HttpContext.Session.GetString("PayStatus"); if (pay_status == "paid" || HttpContext.Session.GetInt32("OrderId") == null) { return(RedirectToAction("Index", "Home")); } int orderid = (int)HttpContext.Session.GetInt32("OrderId"); List <OrderDetail> orderdetails = _context.OrderDetails.Where(o => o.Order_Id == orderid).ToList(); List <Product> products = new List <Product>(); foreach (var detail in orderdetails) { Product pro = _context.Products.Where(o => o.Id == detail.Product_Id).FirstOrDefault(); products.Add(pro); } CheckoutIndexViewModel vm = new CheckoutIndexViewModel() { OrderDetails = orderdetails, Products = products, ProductTypes = _context.ProductTypes.ToList(), productBrands = _context.ProductBrands.ToList() }; int sum = 0; foreach (var detail in vm.OrderDetails) { sum += detail.PriceTotal; } HttpContext.Session.SetString("TongTien", sum.ToString()); PayPalConfig payPalConfig = PayPalService.GetPayPalConfig(); ViewBag.payPalConfig = payPalConfig; return(View(vm)); }
public IActionResult Index() { CartItem a = new CartItem(); //test luôn đúng List <HangHoaViewModel> s = new List <HangHoaViewModel>() { new HangHoaViewModel { Id = 1, Name = "Gi do", Price = 10000, Quantity = 3 }, new HangHoaViewModel { Id = 2, Name = "Gi do 2", Price = 6000, Quantity = 3 } }; ViewBag.products = s; PayPalConfig payPalConfig = PayPalService.getPayPalConfig(); ViewBag.payPalConfig = payPalConfig; return(View(Carts)); }