// GET: PayPal public ActionResult PaymentNotification() { var formVals = new Dictionary <string, string>(); formVals.Add("cmd", "_notify-validate"); string response = PayPalModel.GetPayPalResponse(formVals, false); if (response == "VERIFIED") { string transactionID = Request["txn_id"]; string sAmountPaid = Request["mc_gross"]; string orderID = Request["item_number"]; //int pagoId = 0; //Int32.TryParse(Request["item_number"].ToString(), out pagoId); //var order = StoreService.GetShoppingCartById(pagoId); //if (order != null) //{ // if (!StoreService.UpdatePaypalTokenOrder(transactionID, order.Token)) // { // SetMessage(StoreService.ServiceTempData); // return new EmptyResult(); // } //} } return(new EmptyResult()); }
public ActionResult ValidateCommand(string totalPrice) { bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(); var products = new List <string>(); products.Add("product1"); products.Add("product2"); products.Add("product3"); products.Add("product4"); paypal.cmd = "_xclick"; paypal.business = ConfigurationManager.AppSettings["business"]; if (useSandbox) { ViewBag.actionURL = ConfigurationManager.AppSettings["test_url"]; } else { ViewBag.actionURL = ConfigurationManager.AppSettings["Prod_url"]; } paypal.cancel_return = ConfigurationManager.AppSettings["cancel_return"]; paypal.returnURL = ConfigurationManager.AppSettings["returnURL"]; paypal.notify_url = ConfigurationManager.AppSettings["notify_url"]; paypal.currency_code = ConfigurationManager.AppSettings["currency_code"]; paypal.item_name = "Zamówienie ze strony SportStore"; paypal.amount = totalPrice; return(View(paypal)); }
public HttpResponseMessage ProcessIPN(PayPalModel data) { //logger.LogError(JsonConvert.SerializeObject(data)); if (data.payment_status == "Completed") { try { Guid id = Guid.Parse(data.custom); Ad ad = unitOfWork.AdRepository.GetByID(id); ad.IsPaid = true; ad.PaidDate = DateTime.Today; ad.ViewCount = 0; unitOfWork.AdRepository.Update(ad); unitOfWork.Save(); } catch (Exception ex) { InternalServerError(ex); } } else { //TODO } return(NoContent()); }
public static void Run() { // I am showing this in code, but you would normally // do this with your DI container in your composition // root, and the instance would be created by injecting // it somewhere. var paymentStrategy = new PaymentStrategy( new IPaymentService[] { new CreditCardPayment(), // <-- inject any dependencies here new PayPalPayment() // <-- inject any dependencies here }); // Then once it is injected, you simply do this... var cc = new CreditCardModel() { CardHolderName = "Bob" }; paymentStrategy.MakePayment(cc); // Or this... var pp = new PayPalModel() { UserName = "******" }; paymentStrategy.MakePayment(pp); }
public IHttpActionResult PostPayPalModel(PayPalModel payPalModel1) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PayPalModel p = new PayPalModel(); p.PayementId = payPalModel1.PayementId; p.PayerEmail = payPalModel1.PayerEmail; p.PayerName = payPalModel1.PayerName; p.PayerSurname = payPalModel1.PayerSurname; p.CurrencyCode = payPalModel1.CurrencyCode; p.Status = payPalModel1.Status; p.Value = payPalModel1.Value; p.CreateTime = DateTime.Parse(payPalModel1.CreateTime.ToString()); DateTime pom = p.CreateTime.Value.AddHours(2); p.CreateTime = pom; _unitOfWork.PayPalModels.Add(payPalModel1); _unitOfWork.Complete(); //db.PayPalModels.Add(payPalModel1); //db.SaveChanges(); return(Ok(payPalModel1.Id)); //return CreatedAtRoute("DefaultApi", new { id = payPalModel1.Id }, payPalModel1); }
public IHttpActionResult PutPayPalModel(int id, PayPalModel payPalModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != payPalModel.Id) { return(BadRequest()); } db.Entry(payPalModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PayPalModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public PaymentModel() { PayPalData = new PayPalModel(); StripeData = new StripeModel(); //StripeData.publicKey = StripeConstants.publicKey; StripeData.clientId = StripeConfig.clientId; appError = null; }
//[Authorize(Roles="Customers")] public ActionResult ValidateCommand(int id) { bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(useSandbox); paypal.item_name = ""; paypal.amount = id.ToString(); return(View(paypal)); }
public ActionResult ValidateCommand(string product, string totalPrice) { bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(useSandbox); paypal.item_name = product; paypal.amount = totalPrice; return(View(paypal)); }
//[Authorize(Roles="Customers")] public ActionResult ValidateCommand(string product) { string totalPrice = ConfigurationManager.AppSettings["transaction_amount"].ToString(); bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(useSandbox); paypal.item_name = product; paypal.amount = totalPrice; return(View("TransactionReview", paypal)); }
public IHttpActionResult GetPayPalModel(int id) { PayPalModel payPalModel = db.PayPalModels.Find(id); if (payPalModel == null) { return(NotFound()); } return(Ok(payPalModel)); }
public ActionResult ValidateCommand(string product, string totalPrice) { if (SessionTools.LogCli.IdClient < 1) { return(RedirectToAction("Index", "Login", new { area = "Member", backUrl = "~/Boutique/Panier/Index" })); } bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(useSandbox); paypal.item_name = product; paypal.amount = totalPrice; return(View(paypal)); }
public IHttpActionResult DeletePayPalModel(int id) { PayPalModel payPalModel = db.PayPalModels.Find(id); if (payPalModel == null) { return(NotFound()); } db.PayPalModels.Remove(payPalModel); db.SaveChanges(); return(Ok(payPalModel)); }
public ActionResult ValidateCommand() { string url = ConfigurationManager.AppSettings["redirect"]; string email = ConfigurationManager.AppSettings["business"]; string returnurl = ConfigurationManager.AppSettings["return"]; string cancel_return = ConfigurationManager.AppSettings["cancel_return"]; Models.HttpRequest hr = new Models.HttpRequest(); RechargeModel model = (RechargeModel)Session["recharge"]; string number = Guid.NewGuid().ToString().Substring(0, 6); TB_User user = (TB_User)Session["user"]; TB_Transaction tx = null; if (user != null) { tx = repo.createTransaction(number, model.amount, user.UserId, Convert.ToInt32(model.ProductId), model.phone); } else { tx = repo.createTransaction(number, model.amount, null, Convert.ToInt32(model.ProductId), model.phone); } //Dictionary<string, string> post = new Dictionary<string, string>(); //post.Add("version", "2.0"); //post.Add("action", "pay"); //post.Add("merchant", email); //post.Add("ref_id", tx.TransactionId.ToString()); //post.Add("item_name_1", model.phone+ " Mobile Recharge" ); //post.Add("item_description_1", "Mobile Recharge"); //post.Add("item_quantity_1", "1"); //post.Add("item_amount_1", model.amount); //post.Add("currency", "SGD"); //post.Add("total_amount", model.amount); //post.Add("success_url", returnurl); //post.Add("cancel_url", cancel_return); //hr.HttpPostRequest(url, post); bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(useSandbox, tx.TransactionId, false, Convert.ToInt32(model.amount)); paypal.item_name = model.phone; paypal.amount = model.amount; return(View(paypal)); }
public ActionResult ValidateCommand(string pack, string quantity, string coin, string cointotal, string totalPrice) { if (User.IsInRole("Merchant")) { bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); PayPalModel paypal = new PayPalModel(useSandbox); paypal.item_name = "CoinPack " + pack; paypal.coin = coin; paypal.cointotal = cointotal; paypal.price = pack; paypal.quantity = quantity; paypal.amount = totalPrice; string user_id = User.Identity.GetUserId(); paypal.merchant = db.Merchants.Include(a => a.AspNetUser).Where(a => a.UserID == user_id).FirstOrDefault(); //lưu data MerchantPayment mp = new MerchantPayment(); mp.MerchantID = paypal.merchant.MerchantID; mp.QuantityPack = Convert.ToInt32(quantity); mp.PriceTotal = Convert.ToDecimal(totalPrice); mp.Created = DateTime.Now; mp.StartusID = 0;//0: chưa thanh toán mp.CoinPackID = db.CoinPacks.Where(a => a.Coin.ToString() == coin).Select(a => a.CoinPackID).FirstOrDefault(); db.MerchantPayments.Add(mp); db.SaveChanges(); //lưu vào activitymerchant ActivityMerchant am = new ActivityMerchant(); am.MerchantID = mp.MerchantID; am.Object = "Order" + mp.PaymentID; am.Description = "Tạo đơn hàng mua Coin"; am.ActivityDate = mp.Created; db.ActivityMerchants.Add(am); paypal.paymentID = mp.PaymentID.ToString(); paypal.date = mp.Created.ToString(); db.SaveChanges(); return(View(paypal)); } else { return(RedirectToAction("Shop", "Home", new { area = "" })); } }
public ActionResult Success() { ViewBag.result = PDTHolder.Success(Request.QueryString.Get("tx")); PayPalModel newPayPal = new PayPalModel() { Date = DateTime.Now, PaymentAmount = ViewBag.result.GrossTotal, PayPalTransactionID = ViewBag.result.TransactionId }; db.PayPalModel.Add(newPayPal); db.SaveChanges(); return(View("Success")); }
public ActionResult Paypal() { const int tot = 150; var orderId = Guid.NewGuid().ToString(); if (!UserService.UpdateUserPaymentToken(orderId)) { SetMessage(UserService.ServiceTempData); return(RedirectToAction("PaymentDetails")); } Uri uri = Request.Url; string host = uri.Scheme + Uri.SchemeDelimiter + uri.Host; PayPalModel paypal = new PayPalModel(); paypal.cmd = "_xclick"; paypal.business = Configuration.BusinessAccountKey; paypal.currency_code = Configuration.CurrencyCode; if (!Configuration.UseSandBox) { ViewBag.actionUrl = "https://www.paypal.com/cgi-bin/websrc"; } else { ViewBag.actionUrl = "https://sandbox.paypal.com/cgi-bin/webscr"; } paypal.cancel_return = host + Configuration.CancelUrl + "?orderId=" + orderId; //host + ConfigurationManager.AppSettings["CancelUrl"]; paypal.@return = host + Configuration.ReturnUrl + "?orderId=" + orderId; paypal.notify_url = host + Configuration.NotifyUrl; //paypal.currency_code = payment.Currency; paypal.item_name = "Orde de compra de Noticias"; paypal.item_number = orderId.ToString(); paypal.image_url = "http://www.lacubiella.com/Content/images/lacubiella.png"; paypal.amount = tot.ToString(); return(View(paypal)); }
public ActionResult RechargeWallet(FormCollection forms) { TB_User user = (TB_User)Session["user"]; string txn = forms["txn"]; string number = Guid.NewGuid().ToString().Substring(0, 6); bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); TB_Paypal paypal = new TB_Paypal(); paypal.Amount = Convert.ToDecimal(txn); paypal.date = DateTime.Now; paypal.EWalletID = user.EWallets.FirstOrDefault().EWalletID; paypal.Type = "Wallet Recharge"; paypal.UserID = user.UserId; entities.TB_Paypal.Add(paypal); entities.SaveChanges(); var pay = new PayPalModel(useSandbox, paypal.PaypalId, true, Convert.ToInt32(txn)); pay.item_name = "Wallet Recharge"; pay.amount = txn; return(View("RechargeStatusSubmit", pay)); }
//[Authorize(Roles="Customers")] public ActionResult ValidateCommand(string product, string totalPrice) { bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(useSandbox); //var user = Session["LoggedInUser"] as User; //if (user != null) //{ // paypal.UserId = user.Id; //} paypal.item_name = product; paypal.amount = totalPrice; //dba.Paypaldatas.InsertOnSubmit(paypal); //dba.SubmitChanges(); return(View(paypal)); }
public ActionResult ValidateCommand(int orderId) { bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); var paypal = new PayPalModel(useSandbox); var order = db.Orders.Find(orderId); Session[CurrentOrder] = order; //var lstPaypal = new List<string>(); //foreach (var item in order.OrderDetails) //{ // var flowerName = FlowerUtility.GetFlowerName(item.FlowerCode); // lstPaypal.Add(flowerName); // //paypal.amount += "amount_" + itemCount.ToString() + cartItem.Product.Price; // //paypal.quantity += "quantity_" + itemCount.ToString() + cartItem.Quantity; // //paypal.shipping += "shipping_" + itemCount.ToString() + cartItem.Product.Price; // //paypal.handling += "handling_" + itemCount.ToString() + "0"; //} paypal.item_name = "Order of " + userService.GetCurrentUserName(); paypal.amount = order.TotalPrice.ToString(); var strParam = orderId + "," + userService.GetCurrentUserName() + "," + userService.GetCurrentUserId(); paypal.notify_url = paypal.notify_url + "?strParam=" + strParam; paypal.@return = paypal.@return + "?orderId=" + orderId; paypal.cancel_return = paypal.cancel_return + "?orderId=" + orderId; //paypal.notify_url = "https://*****:*****@return + "&cancel_return=" + paypal.cancel_return + "¬ify_url=" + paypal.notify_url + "¤cy_code" + paypal.currency_code + "&item_name=" + paypal.item_name + "&amount=" + paypal.amount)); }
public HttpResponseMessage PaymentWithPaypal(PayPalModel model) { string payerId = model.PayerID; //Request.Params["PayerID"]; string guid = model.guid; APIContext apiContext = PaypalHelper.Configuration.GetAPIContext(); try { if (string.IsNullOrEmpty(payerId)) { // this section will be executed first because PayerID doesn't exist // it is returned by the create function call of the payment class // baseURL is the url on which paypal sendsback the data. string baseURI = Request.RequestUri.GetLeftPart(UriPartial.Authority) + "/paypal/paymentwithpaypal"; // guid we are generating for storing the paymentID received in session // after calling the create function and it is used in the payment execution guid = Convert.ToString((new Random()).Next(100000)); // CreatePayment function gives us the payment approval url // on which payer is redirected for paypal acccount payment Payment createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid); // get links returned from paypal in response to Create function call IEnumerator <Links> links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext() == true) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { // saving the payapalredirect URL to which user will be redirected for payment paypalRedirectUrl = lnk.href; } } // saving the paymentID in the key guid // HttpContext.Current.Session["guid"] = createdPayment.id; // return Redirect(paypalRedirectUrl); service.InsertPaypalTransactionData(guid, createdPayment.id, model.ApplicationId); var response = Request.CreateResponse(HttpStatusCode.Moved); response.Headers.Location = new Uri(paypalRedirectUrl); return(response); } else { // This section is executed when we have received all the payments parameters // from the previous call to the function Create // Executing a payment // var guid = Request.Params["guid"]; string paymentid = service.GetPaymentIDByGuid(guid); var executedPayment = ExecutePayment(apiContext, payerId, paymentid); // transaction with system db if (executedPayment.state.ToLower() != "approved") { // return View("FailureView"); } } } catch (Exception ex) { // Logger.Log("Error" + ex.Message); // return View("FailureView"); } return(null); }
public Payment MakePaymetWithPaypal(PayPalModel model) { var planDetails = Context.MembershipPlans.Find(model.PlanID); if (planDetails != null) { var discount = planDetails.Discount ?? 0; var rate = Math.Round(planDetails.Rate - ((planDetails.Rate * discount) / 100), 2); var itemList = new ItemList() { items = new List <Item>() }; itemList.items.Add(new Item() { name = planDetails.Name + " membership plan", currency = model.Currency, price = rate.ToString(), quantity = "1" }); var payer = new Payer() { payment_method = "paypal" }; var redirUrls = new RedirectUrls() { cancel_url = model.CancelUrl, return_url = model.ReturenUrl }; var details = new Details() { subtotal = rate.ToString(), fee = "0", gift_wrap = "0", handling_fee = "0", insurance = "0", shipping = "0", shipping_discount = "0", tax = "0" }; var amount = new Amount() { currency = model.Currency, total = rate.ToString(), details = details }; var transactionList = new List <Transaction>(); transactionList.Add(new Transaction() { description = planDetails.Name + " membership subscription", invoice_number = Convert.ToString(model.Id), amount = amount, item_list = itemList, }); Payment payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; return(payment.Create(model.ApiContext)); } return(null); }
public ActionResult ValidateCommand() { string tgs = ""; double?totalPrice = 0; string product; string game = ""; int ticketCount = 0; // build tgId-tgName pairs foreach (string name in Request.Form.AllKeys) { try { int n = Convert.ToInt32(name); Ticket_Game tg = _context.Ticket_Game.Single(m => m.Id == n); if (tg.Sold == 1) { //already sold return(View("Error")); } totalPrice += tg.Price; ticketCount++; game = tg.Game.getFixture(); tgs += name + "-" + Request.Form[name] + ","; } catch (Exception e) { } } tgs = tgs.TrimEnd(','); product = ticketCount + " ticket(s) " + game; PayPalModel paypal = new PayPalModel(); paypal.cmd = "_xclick"; paypal.Tgs = tgs; paypal.business = "*****@*****.**"; paypal.currency_code = "EUR"; bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandbox"]); if (useSandbox) { ViewBag.actionUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr"; } else { ViewBag.actionUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr"; } paypal.cancel_return = ConfigurationManager.AppSettings["CancelUrl"]; paypal.@return = "https://localhost:44315/PayPal/RedirectFromPayPal?ids=" + paypal.id; paypal.notify_url = "https://localhost:44315/PayPal/NotifyFromPaypal"; paypal.item_name = product; paypal.amount = totalPrice.ToString(); Temp_PayPal tp = new Temp_PayPal { Id = paypal.id, Ticket_Game_Ids = paypal.Tgs }; _context.Temp_PayPal.Add(tp); _context.SaveChanges(); return(View(paypal)); }
public ActionResult PaymentWithPaypal(int?id) { APIContext apiContext = PayPalConfiguration.GetAPIContext(); try { string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { Session["PlanID"] = id; string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/User/Payment/PaymentWithPayPal?"; var guid = Convert.ToString((new Random()).Next(100000)); string curl = Request.Url.Scheme + "://" + Request.Url.Authority + "/" + Convert.ToString(ConfigurationManager.AppSettings["PayPalCancelAction"]); string rurl = baseURI + "guid=" + guid; PayPalModel model = new PayPalModel(); model.Id = Guid.NewGuid(); model.PlanID = id ?? 0; model.CancelUrl = curl; model.ReturenUrl = rurl; model.ApiContext = apiContext; model.Currency = "USD"; var createdPayment = _paymentManager.MakePaymetWithPaypal(model); if (createdPayment != null) { var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { paypalRedirectUrl = lnk.href; } } Session.Add(guid, createdPayment.id); return(Redirect(paypalRedirectUrl)); } else { ViewBag.Message = "Some Error Occured during payment. Please try again or contact Site Administrator"; return(View("FailureView")); } } else { var guid = Request.Params["guid"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); if (executedPayment.state.ToLower() != "approved") { TempData["TransactionResult"] = "Some Error Occured during payment. Please try again or contact Site Administrator"; return(RedirectToAction("PostPaymentFailure")); } else { var OriginalPrice = Convert.ToDecimal(Session["PayPalAmount"]); decimal amt = Convert.ToDecimal(executedPayment.transactions[0].related_resources[0].sale.amount.total); var rate = OriginalPrice > 0 ? OriginalPrice : amt; var planID = Convert.ToInt32(Session["PlanID"]); var message = _paymentManager.SavePaypalTransaction(executedPayment, planID, "Paypal", rate, LOGGEDIN_USER.UserID); TempData["PaymentID"] = executedPayment.id; TempData["Message"] = message.Message; TempData["AvailableTokens"] = message.AvailableTokens; return(RedirectToAction("PostPaymentSuccess", "Payment", new { area = "user" })); } } } catch (Exception ex) { TempData["TransactionResult"] = "Some Error Occured during payment. Please try again or contact Site Administrator"; return(RedirectToAction("PostPaymentFailure", "Payment", new { area = "user" })); } }