public JsonResult AddUserCardInfo(tblStripe stripe) { StripeChargeModel sm = new StripeChargeModel(); int op = sm.AddUserCardInfo(stripe); return(Json(op, JsonRequestBehavior.AllowGet)); }
private static async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var myCharge2 = new StripeChargeCreateOptions(); myCharge2.Amount = (int)(model.Amount * 100); myCharge2.Currency = "sgd"; myCharge2.Description = "Description for test charge"; myCharge2.SourceTokenOrExistingSourceId = model.Token.ToString(); String msg = ""; var key = "sk_test_770dfGjXDPlIv7RakGofuTUt"; var chargeService = new StripeChargeService(key); try { var stripeCharge = chargeService.Create(myCharge2); msg = stripeCharge.Id; } catch (StripeException e) { msg = e.ToString(); } return msg; })); }
private async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var charge = new Stripe.StripeChargeCreateOptions { Amount = (int)(model.Amount), Currency = "usd", Description = "Purchase", Source = new Stripe.StripeSourceOptions { TokenId = model.Token } }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; var chargeService = new Stripe.StripeChargeService("sk_test_4lknJTkG0q14upuDDfpZO1Nl006QJSGsZF"); Stripe.StripeCharge chargeId = null; try { chargeId = chargeService.Create(charge); } catch (Exception e) { System.Diagnostics.Debug.Print(e.Message); } return chargeId.Id; })); }
private /*static*/ async Task <string> ProcessPayment(StripeChargeModel model) { decimal orderTotal = 0; if (TempData.ContainsKey("orderTotal")) { orderTotal = (decimal)TempData["orderTotal"]; } return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of orderTotal to pennies Amount = (int)orderTotal * 100, Currency = "gbp", Description = "Custom Computers Charge", SourceTokenOrExistingSourceId = model.Token }; var chargeService = new StripeChargeService("sk_test_d3aJplQiuJAzSj4AQJwPGIk7"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; //return RedirectToAction("Charge", stripeCharge.Id); })); }
private async Task <string> ProcessPayment(StripeChargeModel model) { //StripeConfiguration.SetApiKey("pk_test_ZwQQ3DpHRcIWDMKgVObfuSYl"); return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { Amount = (int)(model.Amount * 1), Currency = "gbp", Description = "Description for test charge", // SourceTokenOrExistingSourceId = model.Token }; try { var chargeService = new StripeChargeService("sk_test_sunSx6HuXZrAcIp2W8k7L4zk"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; } catch (Exception e) { Response.Write("<script>alert('Data Saved succesfully in Database but further transaction process you must provide Cutomer or merchant.')</script>"); return e.Message; } })); }
public async Task <ActionResult> Charge(StripeChargeModel model) { if (!ModelState.IsValid) { return(View(model)); } var chargeId = await ProcessPayment(model); //Get order using tempdata var order = new Order(); if (TempData.ContainsKey("orderData")) { order = (Order)TempData["orderData"]; } //Process the order ProcessOrder(order); //return View("Index"); if (User.IsInRole("Customer")) { return(View("Index")); } else { return(View("StaffCheckout")); } }
private async Task <string> ProcessPayment(StripeChargeModel model) { //TODO if (model.Amount == 0) { model.Amount = 1900; } model.Card.TokenId = model.Id; return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of £12.50 to pennies i.e. 1250 Amount = model.Amount, //in pence Currency = "gbp", Description = "Charged £19 one-off up to 1000", Card = model.Card, ReceiptEmail = model.Email // TokenId = model.Token }; var chargeService = new StripeChargeService(ConfigurationManager.AppSettings["StripeApiKey"]); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; })); }
private async Task <string> ProcessSubscription(StripeChargeModel model) { //TODO if (model.Amount == 0) { model.Amount = 399; } var planId = "Up100PerMo"; var secretKey = ConfigurationManager.AppSettings["StripeApiKey"]; model.Card.TokenId = model.Id; return(await Task.Run(() => { var stripeCustomerCreateOptions = new StripeCustomerCreateOptions { Email = model.Email, PlanId = planId, Card = model.Card, Description = "Charged £3.99 for monthly up to 100", }; var customerService = new StripeCustomerService(secretKey); var stripeCustomer = customerService.Create(stripeCustomerCreateOptions); return stripeCustomer.Id; })); }
public async Task<ActionResult> Charge(StripeChargeModel model) { if (!ModelState.IsValid) { return View(model); } var chargeId = await ProcessPayment(model); return View("Index"); }
public async Task <IActionResult> Charge(StripeChargeModel model) { if (!ModelState.IsValid) { return(View(model)); } var chargeId = await ProcessPayment(model); return(View("Index")); }
public async Task <ActionResult> Charge(StripeChargeModel model) { if (!ModelState.IsValid) { return(View(model)); } var chargeId = await ProcessPayment(model); // You should do something with the chargeId --> Persist it maybe? return(View("Index")); }
public async Task <JsonResult> StripeCharge([FromBody] StripeChargeModel model) { if (!ModelState.IsValid) { return(Json(BadRequest())); } var chargeId = await ProcessPayment(model); // TODO: You should do something with the chargeId --> Persist it maybe? return(Json(Ok(chargeId))); }
private async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var myCharge = new ChargeCreateOptions { Amount = (int)(model.Amount * 100), Currency = "gbp", Description = "Description for test charge", Source = model.Token }; //Not required to specify secret key since set globally var chargeService = new ChargeService(); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; })); }
private static async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of £12.50 to pennies i.e. 1250 Amount = (int)(model.Amount * 100), Currency = "usd", Description = "Description for test charge", SourceTokenOrExistingSourceId = model.Token }; var chargeService = new StripeChargeService(); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; })); }
private static async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { StripeConfiguration.ApiKey = "pk_test_qOc7BjT6S3JesC6i5RlNevq700ptlnoJmt"; var myCharge = new Stripe.ChargeCreateOptions() { // convert the amount of £12.50 to pennies i.e. 1250 Amount = (int)(model.Amount * 100), Currency = "gbp", Description = "Description for test charge", Source = model.Token }; var service = new ChargeService(); var stripeCharge = service.Create(myCharge); return stripeCharge.Id; })); }
private async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { Amount = (int)(model.Amount * 100), Currency = model.Currency, Description = model.Description, SourceTokenOrExistingSourceId = model.Token, ReceiptEmail = model.Email, Capture = true, }; var chargeService = new StripeChargeService(_appSettings.StripePrivateKey); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; })); }
public async Task <HttpResponseMessage> SaveCustomer(StripeChargeModel model) { string chargeId = null; if (IsOneoffPay(model.Amount)) { chargeId = await ProcessPayment(model); } else if (IsSubscriptionPay(model.Amount)) { chargeId = await ProcessSubscription(model); } else { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "Amount not accepted.")); } // You should do something with the chargeId --> Persist it maybe? return(Request.CreateResponse <object>(HttpStatusCode.OK, new { chargeId = chargeId, validPay = true })); }
private async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of £12.50 to pennies i.e. 1250 Amount = (int)(model.Amount * 100), Currency = "gbp", Description = "Description for test charge", Card = new StripeCreditCardOptions { TokenId = model.Token } }; var chargeService = new StripeChargeService("private key goes here"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; })); }
private async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of £12.50 to pennies i.e. 1250 Amount = (int)(model.Amount * 100), Currency = "gbp", Description = "Description for test charge", Source = new StripeSourceOptions { TokenId = model.Token } }; ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072; var chargeService = new StripeChargeService("key"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; })); }
private async Task<string> ProcessPayment(StripeChargeModel model) { return await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of £12.50 to pennies i.e. 1250 Amount = (int)(model.Amount * 100), Currency = "gbp", Description = "Description for test charge", Source = new StripeSourceOptions{ TokenId = model.Token } }; var chargeService = new StripeChargeService("your private key here"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; }); }
private static async Task <string> ProcessPayment(StripeChargeModel model) { return(await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of £12.50 to pennies i.e. 1250 Amount = (int)(model.Amount * 100), Currency = "gbp", Description = "Description for test charge", Source = new StripeSourceOptions { TokenId = model.Token } }; var chargeService = new StripeChargeService("sk_test_3Kfe4HUs5Pl7ZtRVZWPfkfQM00k8wYUiaO"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; })); }
/// <summary> /// helper method to deal with processing payment. /// creates stripe payment token and processes the payment /// </summary> /// <param name="model">payment details</param> /// <returns>chargeId</returns> public static async Task<string> ProcessPayment(StripeChargeModel model) { return await Task.Run(() => { var myCharge = new StripeChargeCreateOptions { // convert the amount of £12.50 to pennies i.e. 1250 Amount = (int)(model.Amount * 100), Currency = "gbp", Description = "Description for test charge", Source = new StripeSourceOptions { TokenId = model.Token//create token } }; var chargeService = new StripeChargeService("sk_test_6sQFkxBnUVABC6P0Q2G0PK3H"); var stripeCharge = chargeService.Create(myCharge); return stripeCharge.Id; }); }
/**********************************CARD PAYMENT SECTION*********************************/ /// <summary> /// Method which returns a view to retrieve payment details /// </summary> /// <param name="error">if there is an error with the payment details entered this is true and message is displayed</param> /// <returns>StripeChargeModel to the view</returns> public ActionResult ChargeView(bool? error) { //redirect if no shippinng details if (Session["ShippingDetails"] == null) { return RedirectToAction("ConfirmAddress"); } else { if (error == true) { ViewBag.Error = "Whoops, something went wrong please try again. Ensure all fields are filled in and postcode is in the format XXX XXX"; } //add order amount to model. StripeChargeModel scm = new StripeChargeModel(); scm.Amount = Convert.ToDouble(TempData["Amount"]); ShippingDetails sd = (ShippingDetails)Session["ShippingDetails"]; //add shipping amount to total if (sd.fastShipping == true) { scm.Amount += 3.50; } scm.Amount += Convert.ToDouble(Session["OrderAmount"]); scm.Address = sd.Address; scm.AddressCity = sd.City; scm.AddressPostcode = sd.PostCode; return View(scm); } }
public async Task <ActionResult> Charge(StripeChargeModel model) { if (!ModelState.IsValid) { return(View(model)); } string chargeId = await ProcessPayment(model); ApplicationUserManager _userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var user = _userManager.FindByName(User.Identity.GetUserName()); Guid userId; Guid.TryParse(user.Id, out userId); Customer customer = _dbContext.Customers.Where(x => x.Uid == userId).FirstOrDefault(); Cart cart = _dbContext.Carts.OrderBy(x => x.Id).FirstOrDefault(); customer.Orders.Add(new Order { CompletedOn = DateTime.Now, Uid = Guid.NewGuid(), Customer = customer, Cart = cart, }); customer.Carts.Add(new Models.Cart { Products = new List <Product>(), TotalPrice = 0m, Uid = Guid.NewGuid() }); _dbContext.SaveChanges(); return(RedirectToAction("Index", "Orders")); }
/// <summary> /// Displays view where user can enter payment details /// </summary> /// <param name="error">if user has entered incorrect details this is true and message is displayed, else this is false</param> /// <returns>View for obtaining payment details</returns> public ActionResult ChargeView(bool?error) { if (error == true) { ViewBag.Error = "Whoops, something went wrong please try again. Ensure all fields are filled in and postcode is in the format XXX XXX"; } //populate viewmodel StripeChargeModel scm = new StripeChargeModel(); string id = GetCurrentUser().Id; var fine = uow.FineRepository.Get(m => m.User.Id.Equals(id) && m.payment == null); scm.Amount = Convert.ToDouble(fine.Amount); //show users registered address //allow them to edit this for billing details scm.Address = GetCurrentUser().Address; scm.AddressCity = GetCurrentUser().City; scm.AddressPostcode = GetCurrentUser().PostalCode; return(View(scm)); }
public async Task <ActionResult> Charge(StripeChargeModel model) { //if model state is not valid return view if (!ModelState.IsValid) { return(RedirectToAction("ChargeView", new { error = true })); } var chargeId = await ProcessPayment(model); //current user string id = GetCurrentUser().Id; ApplicationUser user = uow.UserRepository.Get(m => m.Id.Equals(id)); var fine = uow.FineRepository.Get(m => m.User.Id.Equals(id) && m.payment == null);//get unpaid fine //if process payment is successful create payment if (chargeId != null) { string cardNum = model.CardNumber.ToString(); string exM = model.ExpiryMonth.ToString(); string exY = model.ExpiryYear.ToString(); string Name = model.CardHolderName.ToString(); string billingAddress = model.Address.ToString(); string billingCity = model.AddressCity.ToString(); string billingPostcode = model.AddressPostcode.ToString(); //create payment object Payment payment = new Payment { CardAddress = billingAddress, CardCity = billingCity, CardPostCode = billingPostcode, CardNumber = cardNum, ExpiryMonth = exM, ExpiryYear = exY, Name = Name, DatePaid = DateTime.Now, PaymentMethod = (Models.PaymentMethod) 0, }; //add information to fine object //update user access rights fine.payment = payment; fine.Paid = payment.DatePaid; user.Fines.Add(fine); fine.User = user; fine.order = uow.OrderRepository.Get(m => m.OrderStatus == 2 && m.UserOrderId.Equals(fine.User.Id)); user.AccountRestricted = false; uow.SaveChanges(); return(RedirectToAction("FinePaymentConfirmation", new { id = fine.FineId })); } //if charge fails return(View(model)); }
public async Task<ActionResult> Charge(StripeChargeModel model) { //if model state is not valid return view if (!ModelState.IsValid) { ViewBag.Error = "Whoops, something went wrong please try again."; return RedirectToAction("ChargeView", new { error = true}); } ViewBag.Error = ""; //redirect if no shippinng details if (Session["ShippingDetails"] == null) { RedirectToAction("ConfirmAddress"); } else { var chargeId = await ProcessPayment(model); var cart = ShoppingCart.GetCart(this.HttpContext); //if process payment is successful create payment if (chargeId != null) { string cardNum = model.CardNumber.ToString(); string exM = model.ExpiryMonth.ToString(); string exY = model.ExpiryYear.ToString(); string Name = model.CardHolderName.ToString(); string billingAddress = model.Address.ToString(); string billingCity = model.AddressCity.ToString(); string billingPostcode = model.AddressPostcode.ToString(); Payment payment = new Payment { CardAddress = billingAddress, CardCity = billingCity, CardPostCode = billingPostcode, CardNumber = cardNum, ExpiryMonth = exM, ExpiryYear = exY, Name = Name, DatePaid = DateTime.Now }; Session["PaymentConfirmed"] = payment; // add payment to session object decimal amount = Convert.ToDecimal(model.Amount); var order = CreateFinalOrder(amount); //create the corresponding order for the payment int orderid = order.OrderId; if (order == null) { return RedirectToAction("Index", "Home", null); } return RedirectToAction("OrderConfirmation", new { id = orderid }); } } //if charge fails return View(model); }
public ActionResult Charge(StripeChargeModel model) { // 4242424242424242 string errormessage = ""; bool isvalidemail = false; bool isvalidamount = false; HttpResponseMessage responseMessage = new HttpResponseMessage(); try { var addr = new System.Net.Mail.MailAddress(model.Email); bool emailvalid = (addr.Address == model.Email); isvalidemail = true; } catch { errormessage += "invalid email\r\n"; isvalidemail = false; } if (model.Amount == 0) { isvalidamount = false; errormessage += "invalid amount\r\n"; } else { isvalidamount = true; } if (isvalidamount == true && isvalidemail == true) { try { string Name = model.CardHolderName; string CardNumber = model.CardNum; long ExpirationYear = long.Parse(model.Expyear); long ExpirationMonth = long.Parse(model.ExpMonth); string CVV2 = model.CVV; string Buyer_Email = model.Email; int amount = (int)model.Amount; Stripe.StripeConfiguration.SetApiKey("sk_test_KVelkjylnQQPOkrHSSu8gCft00dODAP1ie"); Stripe.CreditCardOptions card = new Stripe.CreditCardOptions(); card.Name = Name; card.Number = CardNumber; card.ExpYear = ExpirationYear; card.ExpMonth = ExpirationMonth; card.AddressLine1 = model.AddressLine1; card.AddressLine2 = model.AddressLine2; card.AddressState = model.AddressCity; card.AddressCountry = model.AddressCountry; card.AddressZip = model.AddressPostcode; card.Cvc = CVV2; // set card to token object and create token Stripe.TokenCreateOptions tokenCreateOption = new Stripe.TokenCreateOptions(); tokenCreateOption.Card = card; Stripe.TokenService tokenService = new Stripe.TokenService(); Stripe.Token token = tokenService.Create(tokenCreateOption); //create customer object then register customer on Stripe Stripe.CustomerCreateOptions customer = new Stripe.CustomerCreateOptions(); customer.Email = Buyer_Email; var custService = new Stripe.CustomerService(); Stripe.Customer stpCustomer = custService.Create(customer); //create credit card charge object with details of charge var options = new Stripe.ChargeCreateOptions { Amount = (int)(amount * 100), // Amount = (int)(model.Amount * 100), // Currency = "gbp", // Description = "Description for test charge", // Source = model.Token Currency = "gbp", ReceiptEmail = Buyer_Email, Source = model.Token, Description = "Description for test charge" }; //and Create Method of this object is doing the payment execution. var service = new Stripe.ChargeService(); Stripe.Charge charge = service.Create(options); // This will do the Payment } return(new HttpStatusCodeResult(HttpStatusCode.OK, "Success")); } catch { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "error : " + errormessage)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "error : " + errormessage)); } }