// // GET: /Payment/Test // string user, string ccNumber, string bookingId, decimal amount public string Pay(string user, string ccNumber, string bookingId, decimal amount) { PaymentModel pm = new PaymentModel(); UpdateModel(pm); pm.Date = DateTime.Now; return PaymentLogic.DoPay(pm).ToString(); //return View(new PayViewModel(PaymentLogic.DoPay(pm), pm)); }
public PaymentResult Pay(string user, string ccNumber, string bookingId, decimal amount) { PaymentModel pm = new PaymentModel(); pm.User = user; pm.CCNumber = ccNumber; pm.BookingId = bookingId; pm.Amount = amount; pm.Date = DateTime.Now; return PaymentLogic.DoPay(pm); }
/* * stores the payment in the database. The returned PaymentError object contains information about what went wrong when the payment * was not successful. */ public static PaymentResult DoPay(PaymentModel pm) { string ccNum = decryptCCNumber(pm.CCNumber); if (ccNum.Length > 16) { ccNum = ccNum.Substring(0, 16); log.Warn("truncating too long ccNumber: " + pm.CCNumber + " => " + ccNum); } pm.CCNumber = ccNum; bool retry = false; PaymentResult ret = PaymentResult.NULL; for (int i = 0; i <= (retry ? N_RETRIES : 0); i++) { using(PaymentEntities context = new PaymentEntities()) { try { if (!IsCreditCardValid(pm.CCNumber)) { ret = PaymentResult.CC_INVALID; } else { CreditCard cc = context.CreditCard.FirstOrDefault(a => a.number == pm.CCNumber); if (cc == null) { cc = CreateCreditCard(pm, context); } if (!cc.user.Equals(pm.User)) { ret = PaymentResult.CC_WRONG_USER; } else if (cc.validThrough.CompareTo(pm.Date) < 0) { ret = PaymentResult.CC_EXPIRED; } else if (context.Payment.FirstOrDefault(a => a.bookingId == pm.BookingId) != null) { ret = PaymentResult.ALREADY_PAID; } else { Payment payment = Payment.CreatePayment(pm.BookingId, pm.Amount, pm.Date); payment.CreditCard = cc; int changes = context.SaveChanges(); if (log.IsDebugEnabled) { log.Debug(changes + " changes saved"); } ret = PaymentResult.PAYMENT_ACCEPTED; } } doPaymentPluginAction(pm, ret); } catch (UpdateException ue) { retry = true; log.Error(pm.ToString(), ue); ret = PaymentResult.UPDATE_ERROR; } catch (Exception e) { log.Error("exception in DoPay", e); ret = PaymentResult.OTHER_ERROR; } } } return ret; }
public PayViewModel(PaymentResult PaymentResult, PaymentModel Payment) { this.paymentResult = PaymentResult; this.payment = Payment; }
/* * TODO: validThrough is set to now + 2 years. */ private static CreditCard CreateCreditCard(PaymentModel pm, PaymentEntities context) { CreditCard cc = CreditCard.CreateCreditCard(pm.CCNumber, pm.User, DateTime.Now.AddYears(2)); context.AddObject("CreditCard", cc); return cc; }
private static void doPaymentPluginAction(PaymentModel pm, PaymentResult pr) { List<IPaymentActionPlugin> plugins = PluginLoader.GetPluginSingletons<IPaymentActionPlugin>(); foreach (var plugin in plugins) { plugin.Action(pr.ToString(), pm); } }