//This method is call from reentry with the receipt information sent by bank public long storePaymentBill(XMLReceiptInfo receipt) { try { using (conferenceadminContext context = new conferenceadminContext()) { var bill = (from s in context.paymentbills where s.transactionid == receipt.transactionID select s).FirstOrDefault(); if (bill != null) { bill.tandemID = receipt.tandemID; bill.methodOfPayment = receipt.transactionType; bill.batchID = receipt.batchId; bill.email = receipt.email; bill.firstName = receipt.firstName; bill.lastName = receipt.lastName; bill.deleted = false; bill.completed = true; bill.date = DateTime.Now; // bill.telephone = ; context.SaveChanges(); var sponsor1 = bill.payment.sponsors2.FirstOrDefault(); if (sponsor1 != null) { List<paymentbill> bills = sponsor1.payment.paymentbills.ToList(); if (bills.Count() > 0) { double total = 0; foreach (paymentbill b in bills) { if (b.completed) total += b.AmountPaid; } sponsor1.active = true; sponsor1.totalAmount = total; //this loop update sposorType after paymentIs completed var sponsorTypes = context.sponsortypes.ToArray(); if (sponsor1.totalAmount >= sponsorTypes[0].amount) { sponsor1.sponsorType = 1; } else if (sponsorTypes[4].amount >= sponsor1.totalAmount && sponsor1.totalAmount <= sponsorTypes[3].amount - 1) { sponsor1.sponsorType = 5; } else if (sponsor1.totalAmount >= sponsorTypes[3].amount && sponsor1.totalAmount <= sponsorTypes[4].amount - 1) { sponsor1.sponsorType = 4; } else if (sponsor1.totalAmount >= sponsorTypes[2].amount && sponsor1.totalAmount <= sponsorTypes[3].amount - 1) { sponsor1.sponsorType = 3; } else if (sponsor1.totalAmount >= sponsorTypes[1].amount && sponsor1.totalAmount <= sponsorTypes[2].amount - 1) { sponsor1.sponsorType = 2; } } else { sponsor1.active = true; sponsor1.totalAmount = bill.AmountPaid; } context.SaveChanges(); return bill.paymentBillID; } else {//user paymentRegistration var registration = bill.payment.registrations.FirstOrDefault(); user saveUser = context.users.Where(u => u.userID == registration.userID).FirstOrDefault(); saveUser.registrationStatus = "Accepted"; context.SaveChanges(); return bill.paymentBillID; }; } else { return -1; } } } catch (Exception ex) { Console.Write("paymentManger.StorePaymentBillInfo error " + ex); return -1; } }
//This method parse the receipt information received from UPRMSecure public XMLReceiptInfo parseReceiptInfo(string xml) { XMLReceiptInfo xmlObj = new XMLReceiptInfo(); xmlObj.transactionID = getProperty(xml, "TRANSACTIONID"); xmlObj.merchantName = getProperty(xml, "MERCHANT_NAME"); xmlObj.merchantURL = getProperty(xml, "MERCHANT_URL"); xmlObj.firstName = getProperty(xml, "NAME"); xmlObj.lastName = getProperty(xml, "LASTNAME"); xmlObj.tandemID = getProperty(xml, "TANDEMID"); xmlObj.batchId = getProperty(xml, "BATCHID"); xmlObj.transactionType = getProperty(xml, "TRANSACTION_TYPE"); xmlObj.email = getProperty(xml, "EMAIL"); xmlObj.error = getProperty(xml, "ERROR"); xmlObj.message = getProperty(xml, "MESSAGE"); return xmlObj; }