protected void btn_Command(object sender, CommandEventArgs e) { if (e.CommandArgument == "Add Voucher") { try { decimal amount; if (!decimal.TryParse(txtAddAmount.Text, out amount)) { throw new CustomMessageException("Not a valid amount"); } CreditDB.Insert_AddVoucher(224413, amount, txtAddDescr.Text, DateTime.MinValue, Convert.ToInt32(Session["StaffID"])); FillCreditGrid(); FillPayments(); } catch (Exception ex) { lblErrorMessage.Text = ex.Message; } } if (e.CommandArgument == "Tyro Cashout") { try { decimal amount; if (!decimal.TryParse(txtCashAmount.Text, out amount)) { throw new CustomMessageException("Not a valid amount"); } int tyro_payment_pending_id = 6; CreditDB.Insert_Cashout(amount, tyro_payment_pending_id, Convert.ToInt32(Session["StaffID"])); FillCreditGrid(); FillPayments(); } catch (Exception ex) { lblErrorMessage.Text = ex.Message; } } }
protected void Update() { string tyro_transaction_id = UrlTyroTransactionID; string out_result = UrlOutResult; string out_cardType = UrlOutCardType; string out_transactionReference = UrlOutTransactionReference; string out_authorisationCode = UrlOutAuthorisationCode; string out_issuerActionCode = UrlOutIssuerActionCode; if (tyro_transaction_id == null) { throw new Exception("Invalid url field tyro_transaction_id"); } if (out_result == null) { throw new Exception("Invalid url field out_result"); } if (out_cardType == null) { throw new Exception("Invalid url field out_cardType"); } if (out_transactionReference == null) { throw new Exception("Invalid url field out_transactionReference"); } if (out_authorisationCode == null) { throw new Exception("Invalid url field out_authorisationCode"); } if (out_issuerActionCode == null) { throw new Exception("Invalid url field out_issuerActionCode"); } TyroPaymentPendingDB.UpdateByTyroTransactionID(null, tyro_transaction_id, out_result, out_cardType, out_transactionReference, out_authorisationCode, out_issuerActionCode, DateTime.Now); if (out_result == "APPROVED") { TyroPaymentPending tyroPaymentPending = TyroPaymentPendingDB.GetByByTyroTransactionID(null, tyro_transaction_id); Invoice invoice = InvoiceDB.GetByID(tyroPaymentPending.InvoiceID); int staffID = Session == null || Session["StaffID"] == null ? -8 : Convert.ToInt32(Session["StaffID"]); if (tyroPaymentPending.TyroPaymentTypeID == 1) // payment { decimal totalOwed = invoice.TotalDue - tyroPaymentPending.Amount; bool isOverPaid = totalOwed < 0; bool isPaid = totalOwed <= 0; ReceiptDB.Insert(null, 364, tyroPaymentPending.InvoiceID, tyroPaymentPending.Amount, 0, false, isOverPaid, DateTime.MaxValue, staffID); if (tyroPaymentPending.Cashout > 0) { CreditDB.Insert_Cashout(tyroPaymentPending.Cashout, tyroPaymentPending.TyroPaymentPendingID, staffID); } if (isPaid) { InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true); } if (isOverPaid) { // send email to someone .. to fix up the overpayment.... Emailer.SimpleAlertEmail( "Invoice tyro payment added and is overpaid.<br />tyro_payment_pending_id: " + tyroPaymentPending.TyroPaymentPendingID + "<br />Invoice: " + invoice.InvoiceID + "<br />DB: " + (Session == null || Session["DB"] == null ? "" : Session["DB"]), "Tyro Invoice OverPaid: " + invoice.InvoiceID, true); } } if (tyroPaymentPending.TyroPaymentTypeID == 2) // refund { decimal totalOwed = invoice.TotalDue + tyroPaymentPending.Amount; bool isPaid = totalOwed <= 0; RefundDB.Insert(tyroPaymentPending.InvoiceID, tyroPaymentPending.Amount, 308, "", staffID); if (totalOwed > 0) { InvoiceDB.UpdateIsPaid(null, tyroPaymentPending.InvoiceID, false); } } } Response.Write("1"); // to indicate it was successful }