Esempio n. 1
0
 public static List<CreditCardWS> GetCreditCards() {
     List<CreditCardWS> ret = new List<CreditCardWS>();
     using (PaymentEntities context = new PaymentEntities()) {
         foreach (CreditCard ccard in context.CreditCard.ToList()) {
             ret.Add(new CreditCardWS(ccard.number, ccard.user, ccard.validThrough));
         }
     }
     return ret;
 }
Esempio n. 2
0
 private static IDictionary<string, PaymentWS> GetPayments(List<string> bookingIds) {
     IDictionary<string, PaymentWS> ret = new Dictionary<string, PaymentWS>();
     using (PaymentEntities context = new PaymentEntities()) {
         foreach (Payment pay in context.Payment.Where(LinqUtil.BuildContainsExpression<Payment, string>(p => p.bookingId, bookingIds))) {
             if (!pay.CreditCardReference.IsLoaded) {
                 pay.CreditCardReference.Load();
             }
             CreditCard cc = pay.CreditCard;
             CreditCardWS ccws = new CreditCardWS(cc.number, cc.user, cc.validThrough);
             ret.Add(pay.bookingId, new PaymentWS(pay.bookingId, ccws, pay.amount, pay.date));
         }
     }
     return ret;
 }
Esempio n. 3
0
        /*
         * 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;
        }
Esempio n. 4
0
        private static void createTenantReport(string tenantName) {
            BookingSummary summary;
            try {
                using (BookingServicePortTypeClient client = getBookingWSClient()) {
                    summary = client.getBookingSummaryByTenant(tenantName, 25);
                }
            } catch (Exception e) {
                log.Error("cannot create booking report for " + tenantName, e);
                return;
            }
            if (summary == null || summary.NBookings == 0) {
                log.Info("no bookings found: " + tenantName);
            } else {
                using (PaymentEntities context = new PaymentEntities()) {
                    Dictionary<string, int> departures = new Dictionary<string, int>();
                    Dictionary<string, int> destinations = new Dictionary<string, int>();
                    for (int i = 0; i < summary.departures.Length; i++) {
                        departures.Add(summary.departures[i].name, (int)summary.departureCounts[i]);
                    }
                    for (int i = 0; i < summary.destinations.Length; i++) {
                        destinations.Add(summary.destinations[i].name, (int)summary.destinationCounts[i]);
                    }

                    DateTime date = DateTime.Now;
                    PaymentReportData prd = new PaymentReportData(date, summary.NBookings, decimal.Round((decimal)summary.totalSales, 2), destinations, departures);
                    string prdXml = prd.ToXMLString();
                    if (log.IsDebugEnabled) {
                        log.Debug("report as xml : " + prdXml);
                    }
                    AppData.Report report = AppData.Report.CreateReport(tenantName, date);
                    report.xmlData = prdXml;
                    context.AddToReport(report);
                    int changes = context.SaveChanges();
                    if (log.IsDebugEnabled) {
                        log.Debug("saved report: " + report + " changes: " + changes);
                    }
                }
            }

        }
Esempio n. 5
0
 /*
  * 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;
 }