public async Task <ActionResult <Models.CreditCard> > PostCreditCard(Models.CreditCard creditCard) { _context.CreditCards.Add(creditCard); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCreditCard", new { id = creditCard.Id }, creditCard)); }
public async Task <IActionResult> PutCreditCard(int id, Models.CreditCard creditCard) { if (id != creditCard.Id) { return(BadRequest()); } _context.Entry(creditCard).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CreditCardExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (data != null) { InfoShareHelper.Instance.CardInfo = data.GetParcelableExtra(CardIOActivity.ExtraScanResult).JavaCast <Card.IO.CreditCard>(); var card = InfoShareHelper.Instance.CardInfo; var creditCard = new Models.CreditCard( card.CardNumber, card.Cvv, card.ExpiryMonth, card.ExpiryYear, card.IsExpiryValid); Payment payment = await paymentService.CreatePayment(); await paymentService.AuthorizePayment(payment.id.ToString()); payment = await paymentService.GetPayment(payment.id.ToString()); if (payment != null && payment.accepted) { Order order = new Order(BasketService.CurrentBasket, payment); User user = await DependencyService.Get <UserService>().GetUserAsync(Helpers.DeviceHelper.GetMunchyId()); await DependencyService.Get <RecieptService>().AddRecieptAsync(order, user.Id); Page page = Xamarin.Forms.Application.Current.MainPage; await page.Navigation.PushAsync(new SuccesPage("Betalingen er nu gennemført", new SavedCardPage())); Xamarin.Forms.Application.Current.MainPage.Navigation.RemovePage(Xamarin.Forms.Application.Current.MainPage.Navigation.NavigationStack[1]); BasketService.CurrentBasket.ClearBasketItems(); } string cardNumber = InfoShareHelper.Instance.CardInfo.CardNumber; string cvv = InfoShareHelper.Instance.CardInfo.Cvv; string expiration = InfoShareHelper.Instance.CardInfo.ExpiryYear.ToString().Substring(0, 2) + InfoShareHelper.Instance.CardInfo.ExpiryMonth.ToString(); } else { Console.WriteLine("Scanning Canceled!"); } }
public async Task <dynamic> book(Models.CreditCard payData, int id, string checkIn, string checkOut, int guests) { var checkInSplitted = checkIn.Split('-'); var checkOutSplitted = checkOut.Split('-'); var checkInDate = new DateTime(int.Parse(checkInSplitted[0]), int.Parse(checkInSplitted[1]), int.Parse(checkInSplitted[2])); var checkOutDate = new DateTime(int.Parse(checkOutSplitted[0]), int.Parse(checkOutSplitted[1]), int.Parse(checkOutSplitted[2])); var diff = (checkOutDate - checkInDate).Days + 1; var property = propertyService.GetById(id); if (!propertyService.IsPropertyAvailable(id, checkInDate, checkOutDate)) { return(BadRequest()); } ViewBag.checkIn = checkInDate; ViewBag.checkOut = checkOutDate; ViewBag.days = diff; ViewBag.property = property; ViewBag.guests = guests; if (ModelState.IsValid) { dynamic result = await Services.Payment.MakePayment.PayAsync(payData.Number, payData.Month, payData.Year, payData.CVV, payData.Value, payData.Name, payData.Zipcode, payData.usercity); switch (result.state) { case "Success": Reservation reservation = new Reservation() { PropertyId = id, CheckIn = checkInDate, CheckOut = checkOutDate, UserId = _userManager.GetUserId(User), NOfGuests = guests, }; _db.Add(reservation); _db.SaveChanges(); Transaction transaction = new Transaction() { ReservationId = reservation.Id, Amount = result.amount, Id = result.transactionId, }; _db.Add(transaction); _db.SaveChanges(); foreach (var day in PropertySearchService.GetDays(checkInDate, checkOutDate)) { var unAvailable = new PropertyUnavailableDay() { PropertyId = id, UnavailableDay = day, }; _db.Add(unAvailable); } _db.SaveChanges(); return(View("SucceessfulPayment")); case "Your card number is incorrect.": ModelState.AddModelError("Number", "Your card number is incorrect"); return(View()); case "Your card's expiration year is invalid.": ModelState.AddModelError("Year", "Your card's expiration year is invalid"); return(View()); case "Your card's expiration month is invalid": ModelState.AddModelError("Month", "Your card's expiration month is invalid"); return(View()); case "Amount must be no more than $999,999.99": ModelState.AddModelError("Value", "Amount must be no more than $999,999.99"); return(View()); case "This value must be greater than or equal to 1.": ModelState.AddModelError("Value", "This value must be greater than or equal to 1"); return(View()); default: return(View()); } } else { return(View()); } }
public void MarkAsModified(Models.CreditCard creditCard) { }
public ActionResult PaymentWithPaypal(Models.CreditCard currentCard) { Database d = Database.CurrentInstance; AESCryptoStuff AES = AESCryptoStuff.CurrentInstance; int userID = Convert.ToInt32(Session["UserID"]); string price = string.Empty; price = Convert.ToString(Session["price"]); string beansName = string.Empty; beansName = Convert.ToString(Session["beansName"]); string beansAmount = string.Empty; beansAmount = Convert.ToString(Session["beansAmount"]); //getting the apiContext as earlier APIContext apiContext = Models.Configuration.GetAPIContext(); //generating sessionID Session["ShopSessionID1"] = KeyGenerator.GetUniqueKey(20); string sessionID1 = Session["ShopSessionID1"].ToString(); Session["ShopSessionID2"] = BCrypt.HashSession(sessionID1, BCrypt.GenerateSalt()); try { string payerId = Request.Params["PayerID"]; 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 // Creating a payment // baseURL is the url on which paypal sendsback the data. // So we have provided URL of this controller only string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Shop/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 var guid = Convert.ToString((new Random()).Next(100000)); //CreatePayment function gives us the payment approval url //on which payer is redirected for paypal account payment var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid); //get links returned from paypal in response to Create function call var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { 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 Session.Add(guid, createdPayment.id); return(Redirect(paypalRedirectUrl)); } 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"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); if (executedPayment.state.ToLower() != "approved") { string addItemTransQuery = "INSERT INTO beantransaction(transactionNo, transactionDesc, priceOfBeans, status, dateOfTransaction, userID) VALUES (@transactionNo, @transactionDesc, @price, @status, @dateOfTransaction, @userID)"; string transDesc = "Failed Purchase of " + beansName + " (" + beansAmount + " Beans) for $" + price; MySqlCommand c3 = new MySqlCommand(addItemTransQuery, d.conn); c3.Parameters.AddWithValue("@transactionNo", AES.AesEncrypt(KeyGenerator.GetUniqueKey(20))); c3.Parameters.AddWithValue("@transactionDesc", AES.AesEncrypt(transDesc)); c3.Parameters.AddWithValue("@price", Convert.ToDouble(price)); c3.Parameters.AddWithValue("@status", "Failure"); c3.Parameters.AddWithValue("@dateOfTransaction", DateTime.Now); c3.Parameters.AddWithValue("@userID", AES.AesEncrypt(userID.ToString())); return(RedirectToAction("FailureView")); } } } catch (Exception ex) { Debug.WriteLine(ex); string addItemTransQuery = "INSERT INTO beantransaction(transactionNo, transactionDesc, priceOfBeans, status, dateOfTransaction, userID) VALUES (@transactionNo, @transactionDesc, @price, @status, @dateOfTransaction, @userID)"; string transDesc = "Failed Purchase of " + beansName + " (" + beansAmount + " Beans) for $" + price; MySqlCommand c3 = new MySqlCommand(addItemTransQuery, d.conn); c3.Parameters.AddWithValue("@transactionNo", AES.AesEncrypt(KeyGenerator.GetUniqueKey(20))); c3.Parameters.AddWithValue("@transactionDesc", AES.AesEncrypt(transDesc)); c3.Parameters.AddWithValue("@price", Convert.ToDouble(price)); c3.Parameters.AddWithValue("@status", "Failure"); c3.Parameters.AddWithValue("@dateOfTransaction", DateTime.Now); c3.Parameters.AddWithValue("@userID", AES.AesEncrypt(userID.ToString())); return(View("FailureView")); } try { if (d.OpenConnection()) { string userQuery = "SELECT * FROM users WHERE userID = @userID"; MySqlCommand c = new MySqlCommand(userQuery, d.conn); c.Parameters.AddWithValue("@userID", userID); int beansBefore = 0; int beansAfter = 0; Debug.WriteLine("SCARY"); using (MySqlDataReader r = c.ExecuteReader()) { while (r.Read()) { if (Convert.ToInt32(r["userID"]) == userID) { beansBefore = Convert.ToInt32(r["beansAmount"].ToString()); beansAfter = beansBefore + Convert.ToInt32(beansAmount); } } r.Close(); string updateQuery = "UPDATE users SET beansAmount = @beansAfter WHERE userID = @userID"; MySqlCommand c2 = new MySqlCommand(updateQuery, d.conn); c2.Parameters.AddWithValue("@beansAfter", beansAfter); c2.Parameters.AddWithValue("@userID", userID); c2.ExecuteNonQuery(); Debug.WriteLine(beansBefore + " " + beansAfter); string addItemTransQuery = "INSERT INTO beantransaction VALUES (@transactionNo, @transactionDesc, @price, @beansBefore, @beansAfter, @status, @dateOfTransaction, @userID)"; string transDesc = "Purchase " + beansName + " (" + beansAmount + " Beans) for $" + price; MySqlCommand c3 = new MySqlCommand(addItemTransQuery, d.conn); c3.Parameters.AddWithValue("@transactionNo", AES.AesEncrypt(KeyGenerator.GetUniqueKey(20))); c3.Parameters.AddWithValue("@transactionDesc", AES.AesEncrypt(transDesc)); c3.Parameters.AddWithValue("@price", Convert.ToDouble(price)); c3.Parameters.AddWithValue("@beansBefore", beansBefore); c3.Parameters.AddWithValue("@beansAfter", beansAfter); c3.Parameters.AddWithValue("@status", "Successful"); c3.Parameters.AddWithValue("@dateOfTransaction", DateTime.Now); c3.Parameters.AddWithValue("@userID", AES.AesEncrypt(userID.ToString())); c3.ExecuteNonQuery(); } } } catch (MySqlException e) { Debug.WriteLine(e); string addItemTransQuery = "INSERT INTO beantransaction(transactionNo, transactionDesc, priceOfBeans, status, dateOfTransaction, userID) VALUES (@transactionNo, @transactionDesc, @price, @status, @dateOfTransaction, @userID)"; string transDesc = "Failed Purchase of " + beansName + " (" + beansAmount + " Beans) for $" + price; MySqlCommand c3 = new MySqlCommand(addItemTransQuery, d.conn); c3.Parameters.AddWithValue("@transactionNo", AES.AesEncrypt(KeyGenerator.GetUniqueKey(20))); c3.Parameters.AddWithValue("@transactionDesc", AES.AesEncrypt(transDesc)); c3.Parameters.AddWithValue("@price", Convert.ToDouble(price)); c3.Parameters.AddWithValue("@status", "Failure"); c3.Parameters.AddWithValue("@dateOfTransaction", DateTime.Now); c3.Parameters.AddWithValue("@userID", AES.AesEncrypt(userID.ToString())); return(RedirectToAction("FailureView")); } finally { d.CloseConnection(); } return(RedirectToAction("SuccessView")); }
public ActionResult CreditCardInfo(Models.CreditCard currentCard) { Session["ShopSessionID1"] = KeyGenerator.GetUniqueKey(20); string sessionID1 = Session["ShopSessionID1"].ToString(); Session["ShopSessionID2"] = BCrypt.HashSession(sessionID1, BCrypt.GenerateSalt()); if (string.IsNullOrEmpty(currentCard.creditCardNo)) { ModelState.AddModelError("creditCardNo", "Credit card number is required."); } if (string.IsNullOrEmpty(currentCard.cvv2)) { ModelState.AddModelError("creditCardNo", "CVV is required."); } if (string.IsNullOrEmpty(currentCard.first_name)) { ModelState.AddModelError("creditCardNo", "First Name is required."); } if (string.IsNullOrEmpty(currentCard.last_name)) { ModelState.AddModelError("creditCardNo", "Last Name is required."); } if (ModelState.IsValid) { //create and item for which you are taking payment //if you need to add more items in the list //Then you will need to create multiple item objects or use some loop to instantiate object string price = string.Empty; price = Convert.ToString(Session["price"]); string beansName = string.Empty; price = Convert.ToString(Session["beansName"]); string beansAmount = string.Empty; price = Convert.ToString(Session["beansAmount"]); PayPal.Api.Item item = new PayPal.Api.Item(); item.name = beansName + " (" + beansAmount + ") Beans"; item.currency = "SGD"; item.price = price; item.quantity = "1"; item.sku = KeyGenerator.GetUniqueKey(20); //Now make a List of Item and add the above item to it //you can create as many items as you want and add to this list List <PayPal.Api.Item> itms = new List <PayPal.Api.Item>(); itms.Add(item); ItemList itemList = new ItemList(); itemList.items = itms; //Address for the payment Address billingAddress = new Address { city = currentCard.billing_address.city, country_code = "SG", line1 = currentCard.billing_address.line1, line2 = currentCard.billing_address.line2, postal_code = currentCard.billing_address.postal_code, state = currentCard.billing_address.state }; //Now Create an object of credit card and add above details to it //Please replace your credit card details over here which you got from paypal PayPal.Api.CreditCard crdtCard = new PayPal.Api.CreditCard { billing_address = billingAddress, cvv2 = currentCard.cvv2, //card cvv2 number expire_month = currentCard.expire_month, //card expire date expire_year = currentCard.expire_year, //card expire year first_name = currentCard.first_name, last_name = currentCard.last_name, number = currentCard.creditCardNo //enter your credit card number here }; if (Regex.IsMatch(currentCard.creditCardNo, "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$")) { crdtCard.type = "mastercard"; } if (Regex.IsMatch(currentCard.creditCardNo, "^4[0-9]{12}(?:[0-9]{3})?$")) { crdtCard.type = "visa"; } // Specify details of your payment amount. Details details = new Details(); details.shipping = "0"; details.subtotal = price; details.tax = "0"; // Specify your total payment amount and assign the details object Amount amnt = new Amount(); amnt.currency = "SGD"; // Total = shipping tax + subtotal. amnt.total = price; amnt.details = details; // Now make a transaction object and assign the Amount object Transaction tran = new Transaction(); tran.amount = amnt; tran.description = "Purchase of " + beansAmount + " beans. Beans will be added after successful purchase."; tran.item_list = itemList; tran.invoice_number = KeyGenerator.GetUniqueKey(20); // Now, we have to make a list of transaction and add the transactions object // to this list. You can create one or more object as per your requirements List <Transaction> transactions = new List <Transaction>(); transactions.Add(tran); // Now we need to specify the FundingInstrument of the Payer // for credit card payments, set the CreditCard which we made above FundingInstrument fundInstrument = new FundingInstrument(); fundInstrument.credit_card = crdtCard; // The Payment creation API requires a list of FundingIntrument List <FundingInstrument> fundingInstrumentList = new List <FundingInstrument>(); fundingInstrumentList.Add(fundInstrument); // Now create Payer object and assign the fundinginstrument list to the object Payer payr = new Payer { funding_instruments = fundingInstrumentList, payment_method = "credit_card" }; // finally create the payment object and assign the payer object & transaction list to it Payment pymnt = new Payment { intent = "sale", payer = payr, transactions = transactions }; try { //getting context from the paypal //basically we are sending the clientID and clientSecret key in this function //to the get the context from the paypal API to make the payment //for which we have created the object above. //Basically, apiContext object has a accesstoken which is sent by the paypal //to authenticate the payment to facilitator account. //An access token could be an alphanumeric string APIContext apiContext = Models.Configuration.GetAPIContext(); //Create is a Payment class function which actually sends the payment details //to the paypal API for the payment. The function is passed with the ApiContext //which we received above. Payment createdPayment = pymnt.Create(apiContext); //if the createdPayment.state is "approved" it means the payment was successful if (createdPayment.state.ToLower() != "approved") { return(View("FailureView")); } } catch (PayPal.PayPalException ex) { Debug.WriteLine(ex); return(View("FailureView")); } return(View("SuccessView")); } else { return(View(currentCard)); } }