protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            HideErrorMessage();

            if (GetFormIsPopup())
            {
                Utilities.UpdatePageHeaderV2(Page.Master, true);
            }
            btnClose.Visible = GetFormIsPopup();

            if (!IsPostBack)
            {
                FillInvoicesList();
            }

            if (Session["UpdateFromWebPay"] != null)
            {
                PaymentPendingDB.UpdateAllPaymentsPending(null, DateTime.Now.AddDays(-15), DateTime.Now.AddDays(1), Convert.ToInt32(Session["StaffID"]));
                Session.Remove("UpdateFromWebPay");
            }
        }
        catch (CustomMessageException ex)
        {
            if (IsPostBack)
            {
                SetErrorMessage(ex.Message);
            }
            else
            {
                HideTableAndSetErrorMessage(ex.Message);
            }
        }
        catch (Exception ex)
        {
            if (IsPostBack)
            {
                SetErrorMessage("", ex.ToString());
            }
            else
            {
                HideTableAndSetErrorMessage("", ex.ToString());
            }
        }
    }
Exemple #2
0
    protected void Run()
    {
        if (!CheckIsValidStartEndDates())
        {
            return;
        }

        try
        {
            string output = PaymentPendingDB.UpdateAllPaymentsPending(null, GetFromDate(), GetToDate(), Convert.ToInt32(Session["StaffID"]), true);
            lblOutput.Text = output;
        }
        catch (System.ServiceModel.CommunicationException ex)
        {
            if (ex.Message == "The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.")
            {
                SetErrorMessage("Ezidebit can not return this much data in a single request. Please narrow the date range and try again.");
                return;
            }
            throw;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string InvoiceID        = Request.QueryString["InvoiceID"];
        string PT_CustomerName  = Request.QueryString["PT_CustomerName"];
        string PT_PaymentAmount = Request.QueryString["PT_PaymentAmount"];
        string PT_ReturnUrl     = Request.QueryString["PT_ReturnUrl"];

        string DB = null;

        if (Request.QueryString["id"] != null)
        {
            Tuple <string, int> formParams = GetFormParams(false);

            Invoice invoice = InvoiceDB.GetByID(formParams.Item2, formParams.Item1);
            if (invoice == null)
            {
                HideTableAndSetErrorMessage("Invalid invoice ID");
                return;
            }
            InvoiceID = invoice.InvoiceID.ToString();
            DB        = formParams.Item1;
        }
        else
        {
            DB = Session["DB"].ToString();
        }


        int paymentPendingID = PaymentPendingDB.Insert(DB, Convert.ToInt32(InvoiceID), Convert.ToDecimal(PT_PaymentAmount), PT_CustomerName);

        string url = ConfigurationManager.AppSettings["EziDebit_URL"] + "/Payment.aspx" +
                     "?PT_DigitalKey=" + SystemVariableDB.GetAll(DB)["EziDebit_DigitalKey"].Value +
                     "&PT_PaymentReference=" + paymentPendingID +
                     "&PT_CustomerName=" + PT_CustomerName +
                     "&PT_PaymentAmount=" + PT_PaymentAmount +
                     "&PT_ReturnURL=" + PT_ReturnUrl;

        Response.Redirect(url);
    }
Exemple #4
0
    public static string UpdateAllPaymentsPending(string DB, DateTime from, DateTime to, int staffID, bool incOutput = false)
    {
        bool isStakeholder = HttpContext.Current.Session != null && HttpContext.Current.Session["IsStakeholder"] != null && Convert.ToBoolean(HttpContext.Current.Session["IsStakeholder"]);

        NonPCIServiceClient client = new NonPCIServiceClient();

        px.ezidebit.com.au.EziResponseOfArrayOfPaymentTHgMB7oL result = client.GetPayments(
            ((SystemVariables)HttpContext.Current.Session["SystemVariables"])["EziDebit_DigitalKey"].Value,
            "ALL",
            "ALL",
            "ALL",
            "",
            from.ToString("yyyy-MM-dd"),
            to.ToString("yyyy-MM-dd"),
            "PAYMENT",
            "",
            ""
            );


        string output = string.Empty;

        output += "Error: " + result.Error + "<br /><br />";

        if (result.Data != null)
        {
            // some erroneous payment references have gotten in and then there is an erorr converting it to an int to sort it.
            bool   containsOnlyInts = true;
            string allPaymentRefs   = string.Empty;
            foreach (px.ezidebit.com.au.Payment payment in result.Data)
            {
                if (!Regex.IsMatch(payment.PaymentReference, @"^\d+$"))
                {
                    allPaymentRefs  += "<tr><td><font color=\"red\">" + payment.PaymentReference + "</font></td><td style=\"min-width:10px;\"></td><td>$" + payment.ScheduledAmount + "</td><td style=\"min-width:10px;\"></td><td>" + (payment.SettlementDate == null ? "" : payment.SettlementDate.Value.ToString("d MMM yyyy  mm:ss")) + "</td></tr>";
                    containsOnlyInts = false;
                }
                else
                {
                    allPaymentRefs += "<tr><td>" + payment.PaymentReference + "</td><td style=\"min-width:10px;\"></td><td>$" + payment.ScheduledAmount + "</td><td style=\"min-width:10px;\"></td><td>" + (payment.SettlementDate == null ? "" : payment.SettlementDate.Value.ToString("d MMM yyyy  mm:ss")) + "</td></tr>";
                }
            }

            if (containsOnlyInts)
            {
                Array.Sort(result.Data, delegate(px.ezidebit.com.au.Payment p1, px.ezidebit.com.au.Payment p2)
                {
                    return(Convert.ToInt32(p1.PaymentReference).CompareTo(Convert.ToInt32(p2.PaymentReference)));
                });
            }


            for (int i = 0; i < result.Data.Length; i++)
            {
                if (!Regex.IsMatch(result.Data[i].PaymentReference, @"^\d+$"))
                {
                    continue;
                }

                PaymentPending paymentPending = PaymentPendingDB.GetByID(DB, Convert.ToInt32(result.Data[i].PaymentReference));

                if (paymentPending == null)
                {
                    continue;
                }

                if (paymentPending.OutDateProcessed != DateTime.MinValue &&
                    paymentPending.OutPaymentResult == "A" &&
                    (result.Data[i].PaymentStatus.ToUpper() != "S" && result.Data[i].PaymentStatus.ToUpper() != "P"))
                {
                    Emailer.SimpleAlertEmail(
                        "Ezidebit invoice payment added and set to \"A\" but payment status not in (\"S\",\"P\"): " + result.Data[i].PaymentStatus.ToUpper() + ".<br />payment_pending_id: " + paymentPending.PaymentPendingID + "<br />DB: " + (DB == null ? System.Web.HttpContext.Current.Session["DB"] : DB),
                        "Ezidebit Reconcilliation - Payment Status Mismatch",
                        true);
                }

                if (paymentPending.OutDateProcessed != DateTime.MinValue)
                {
                    continue;
                }


                //
                // During real time transactions, results can be
                //
                // A = Approved
                // U = Unable to process at that time (Failed)
                // F = Failed                         (Failed)
                //
                // On the instant payment screen, we set in our DB as Approved (& generate receipt), or else we do not enter the result
                // There is no option (A/U/F) for Pending to update later
                //
                //
                // During this reconcilliation, results can be
                //
                // S   = Successful
                // P   = Pending (just means waiting for money to physically be sent to our bank)
                // F/D = (Dishonour/Fatal Dishonour)
                //
                //
                // Their instant payment page will always know if it was successful or failed at the time of transaction.
                //
                // So in the reconciliation web service, since 'Pending' is not a fail code, it means any payment
                // set to Pending is definitely successful and just waiting for the money to be actually sent.
                //
                // Ezidebit support confirmed this.
                //

                if (result.Data[i].PaymentStatus.ToUpper() == "S" || result.Data[i].PaymentStatus.ToUpper() == "P")
                {
                    PaymentPendingDB.Update(DB, result.Data[i].TransactionTime.Value, paymentPending.PaymentPendingID, "A", "00", "APPROVED", result.Data[i].BankReceiptID, result.Data[i].PaymentID);

                    // update this invoice as paid!
                    if (!Convert.ToBoolean(ConfigurationManager.AppSettings["EziDebit_Debugging"]))
                    {
                        Invoice invoice = InvoiceDB.GetByID(paymentPending.InvoiceID);

                        if (result.Data[i].ScheduledAmount != (double)paymentPending.PaymentAmount)
                        {
                            Emailer.SimpleAlertEmail(
                                "Ezidebit invoice late payment added but initial payment amount and reconcilliation ammount differ (" + paymentPending.PaymentAmount + ", " + result.Data[i].ScheduledAmount + ")<br />payment_pending_id: " + paymentPending.PaymentPendingID + "<br />Invoice: " + invoice.InvoiceID + "<br />DB: " + (DB == null ? System.Web.HttpContext.Current.Session["DB"] : DB) + "<br />Original Amount: " + paymentPending.PaymentAmount + "<br />Ezidebit Sync Amount: " + result.Data[i].ScheduledAmount + "<br />Staff: " + StaffDB.GetByID(staffID).Person.FullnameWithoutMiddlename,
                                "Ezidebit Reconcilliation Amounts Differ. Invoice " + paymentPending.InvoiceID,
                                true);
                        }

                        decimal totalOwed  = invoice.TotalDue - paymentPending.PaymentAmount;
                        bool    isOverPaid = totalOwed < 0;
                        bool    isPaid     = totalOwed <= 0;

                        int receiptID = ReceiptDB.Insert(DB, 363, paymentPending.InvoiceID, paymentPending.PaymentAmount, 0, false, isOverPaid, DateTime.MinValue, staffID);

                        if (isPaid)
                        {
                            InvoiceDB.UpdateIsPaid(DB, invoice.InvoiceID, true);
                        }

                        if (isOverPaid)
                        {
                            // send email to someone .. to fix up the overpayment
                            Emailer.SimpleAlertEmail(
                                "Ezidebit invoice late web payment added and is overpaid.<br />payment_pending_id: " + paymentPending.PaymentPendingID + "<br />Invoice: " + invoice.InvoiceID + "<br />DB: " + (DB == null ? System.Web.HttpContext.Current.Session["DB"] : DB),
                                "Ezidebit Invoice OverPaid. Invoice: " + invoice.InvoiceID,
                                true);
                        }
                    }
                }
                if (result.Data[i].PaymentStatus.ToUpper() == "F" || result.Data[i].PaymentStatus.ToUpper() == "D")
                {
                    PaymentPendingDB.Update(DB, result.Data[i].TransactionTime.Value, paymentPending.PaymentPendingID, "F", result.Data[i].BankReturnCode, result.Data[i].BankFailedReason, result.Data[i].BankReceiptID, result.Data[i].PaymentID);
                }
            }


            System.Collections.Hashtable ppHash = new System.Collections.Hashtable();
            if (incOutput)
            {
                DataTable dt = PaymentPendingDB.GetDataTable(DB);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    PaymentPending pp = PaymentPendingDB.Load(dt.Rows[i]);
                    ppHash[pp.PaymentPendingID] = pp;
                }
            }


            output += "<table id=\"tbl_output\" class=\"table table-bordered table-striped table-grid table-grid-top-bottum-padding-normal auto_width block_center\" border=\"1\">";

            output += @"<tr><th style=""vertical-align:top !important;"">" +
                      @"<br />Date                      </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Payment Reference         </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Payment Status
                    <table class=""text_left"">
                    <tr style=""white-space:nowrap;""><td>(<b>S</b> = Successful)</td></tr>
                    <tr style=""white-space:nowrap;""><td>(<b>F</b> = Failed)</td></tr>
                    <tr style=""white-space:nowrap;""><td>(<b>P</b> = Pending)</td></tr>
                    </table>                   </th><th style=""vertical-align:top !important;"">" +

                      @"<b>[Internal]<br/></b>Invoice ID           </th><th style=""vertical-align:top !important;"">" +
                      @"<b>[Internal]<br/></b>Customer Name        </th><th style=""vertical-align:top !important;"">" +
                      @"<b>[Internal]<br/></b>Payment Amount       </th><th style=""vertical-align:top !important;"">" +
                      @"<b>[Internal]<br/></b>OutPayment Result    
                        <table class=""text_left"">
                        <tr style=""white-space:nowrap;""><td>(<b>A</b> = Accepted)</td></tr>
                        <tr style=""white-space:nowrap;""><td>(<b>F</b> = Failed)</td></tr>
                        </table>                   </th><th style=""background-color:grey !important;"">" +

                      @"                          </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Bank Failed Reason        </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Bank Receipt ID           </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Bank Return Code          </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Customer Name             </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Debit Date                </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Settlement Date           </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Ezidebit Customer ID      </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Payment ID                </th><th style=""vertical-align:top !important;"">" +
                      (isStakeholder ? @"<br />Payment Amount            </th><th style=""vertical-align:top !important;"">" : "") +
                      @"<br />Payment Method            </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Payment Source            </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Scheduled Amount          </th><th style=""vertical-align:top !important;"">" +
                      (isStakeholder ? @"<br />Transaction Fee Client    </th><th style=""vertical-align:top !important;"">" : "") +
                      (isStakeholder ? @"<br />Transaction Fee Customer  </th><th style=""vertical-align:top !important;"">" : "") +
                      @"<br />Transaction Time          </th><th style=""vertical-align:top !important;"">" +
                      @"<br />Ezidebit Invoice ID       </th>";

            output += "</tr>";


            for (int i = result.Data.Length - 1; i >= 0; i--)
            {
                PaymentPending pp = null;
                if (Regex.IsMatch(result.Data[i].PaymentReference, @"^\d+$"))
                {
                    pp = ppHash[Convert.ToInt32(result.Data[i].PaymentReference)] as PaymentPending;
                }

                bool failed = result.Data[i].PaymentStatus != "S" && result.Data[i].PaymentStatus != "P";

                string invLink = pp == null ? null : String.Format("Invoice_ViewV2.aspx?invoice_id={0}", pp.InvoiceID);
                string onClick = pp == null ? null : "javascript:window.showModalDialog('" + invLink + "', '', 'dialogWidth:775px;dialogHeight:900px;center:yes;resizable:no; scroll:no');return false;";

                output += "<tr" + (!failed ? "" : " style='color:red;' ") + "><td>" +

                          (pp == null ? "" : (pp.DateAdded.ToString("d MMM, yyyy") + " &nbsp;&nbsp;&nbsp; " + pp.DateAdded.ToString("HH:mm"))) + "&nbsp;</td><td>&nbsp;" +

                          (failed ? "<b>" : "") + result.Data[i].PaymentReference + (failed ? "</b>" : "") + "&nbsp;</td><td>&nbsp;" +
                          (failed ? "<b>" : "") + result.Data[i].PaymentStatus + (failed ? "</b>" : "") + "&nbsp;</td><td>&nbsp;" +

                          (pp == null ? "" : "<a href=\"" + invLink + "\"" + (onClick == null ? "" : " onclick=\"" + onClick + "\"") + ">" + pp.InvoiceID + "</a>") + "&nbsp;</td><td>&nbsp;" +
                          (pp == null ? "" : pp.CustomerName.ToString()) + "&nbsp;</td><td>&nbsp;" +
                          (pp == null ? "" : pp.PaymentAmount.ToString()) + "&nbsp;</td><td>&nbsp;" +
                          (pp == null ? "" : pp.OutPaymentResult.ToString()) + "&nbsp;</td><td style=\"background-color:grey;\">&nbsp;" +

                          "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].BankFailedReason + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].BankReceiptID + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].BankReturnCode + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].CustomerName + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].DebitDate + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].SettlementDate + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].EzidebitCustomerID + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].PaymentID + "&nbsp;</td><td>&nbsp;" +
                          (isStakeholder ? result.Data[i].PaymentAmount + "&nbsp;</td><td>&nbsp;" : "") +
                          result.Data[i].PaymentMethod + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].PaymentSource + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].ScheduledAmount + "&nbsp;</td><td>&nbsp;" +
                          (isStakeholder ? result.Data[i].TransactionFeeClient + "&nbsp;</td><td>&nbsp;" : "") +
                          (isStakeholder ? result.Data[i].TransactionFeeCustomer + "&nbsp;</td><td>&nbsp;" : "") +
                          result.Data[i].TransactionTime.Value + "&nbsp;</td><td>&nbsp;" +
                          result.Data[i].InvoiceID + "&nbsp;</td>" +
                          "</tr>";
            }
            output += "</table>";
        }
        else if (result.ErrorMessage != null && result.ErrorMessage.Length > 0)
        {
            for (int i = 0; i < result.ErrorMessage.Length; i++)
            {
                output += "EziDebit Error: " + result.ErrorMessage[i] + "<br />" + Environment.NewLine;
            }

            Emailer.SimpleAlertEmail(
                output,
                "EziDebit Web Service Error",
                true);
            Logger.LogQuery(output, false, true, false);
        }

        client.Close();  // Always close the client.

        return(output);
    }
Exemple #5
0
    protected void CheckReturnFromOnlinePayment()
    {
        string PT_PaymentReference  = Request.Form["PT_PaymentReference"] != null ? Request.Form["PT_PaymentReference"]  : Request.QueryString["PT_PaymentReference"];
        string PT_PaymentResult     = Request.Form["PT_PaymentResult"] != null ? Request.Form["PT_PaymentResult"]     : Request.QueryString["PT_PaymentResult"];
        string PT_PaymentResultCode = Request.Form["PT_PaymentResultCode"] != null ? Request.Form["PT_PaymentResultCode"] : Request.QueryString["PT_PaymentResultCode"];
        string PT_PaymentResultText = Request.Form["PT_PaymentResultText"] != null ? Request.Form["PT_PaymentResultText"] : Request.QueryString["PT_PaymentResultText"];
        string PT_BankReceiptID     = Request.Form["PT_BankReceiptID"] != null ? Request.Form["PT_BankReceiptID"]     : Request.QueryString["PT_BankReceiptID"];
        string PT_PayTechPaymentID  = Request.Form["PT_PayTechPaymentID"] != null ? Request.Form["PT_PayTechPaymentID"]  : Request.QueryString["PT_PayTechPaymentID"];


        if (PT_PaymentReference != null &&
            PT_PaymentResult != null &&
            PT_PaymentResultCode != null &&
            PT_PaymentResultText != null &&
            PT_BankReceiptID != null &&
            PT_PayTechPaymentID != null)
        {
            PaymentPending paymentPending = PaymentPendingDB.GetByID(null, Convert.ToInt32(Request.QueryString["PT_PaymentReference"]));
            Invoice        invoice        = InvoiceDB.GetByID(paymentPending.InvoiceID);

            PaymentPendingDB.Update(
                null,
                DateTime.Now,
                Convert.ToInt32(Request.QueryString["PT_PaymentReference"]),
                PT_PaymentResult,
                PT_PaymentResultCode,
                PT_PaymentResultText,
                PT_BankReceiptID,
                PT_PayTechPaymentID
                );

            if (PT_PaymentResult == "A" && !Convert.ToBoolean(ConfigurationManager.AppSettings["EziDebit_Debugging"]))
            {
                decimal totalOwed  = invoice.TotalDue - paymentPending.PaymentAmount;
                bool    isOverPaid = totalOwed < 0;
                bool    isPaid     = totalOwed <= 0;

                int receiptID = ReceiptDB.Insert(null, 363, paymentPending.InvoiceID, paymentPending.PaymentAmount, 0, false, isOverPaid, DateTime.MinValue, Convert.ToInt32(Session["StaffID"]));

                if (isPaid)
                {
                    InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
                }

                if (isPaid)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "close_form", @"<script language=javascript>self.close();</script>");
                }
            }


            string url = Request.RawUrl;
            //url = UrlParamModifier.Remove(url, "PT_PaymentReference");
            url = UrlParamModifier.Remove(url, "PT_PaymentResult");
            url = UrlParamModifier.Remove(url, "PT_PaymentResultCode");
            url = UrlParamModifier.Remove(url, "PT_PaymentResultText");
            url = UrlParamModifier.Remove(url, "PT_BankReceiptID");
            url = UrlParamModifier.Remove(url, "PT_PayTechPaymentID");
            Response.Redirect(url);
        }
        else if (PT_PaymentReference != null)
        {
            PaymentPending paymentPending = PaymentPendingDB.GetByID(null, Convert.ToInt32(Request.QueryString["PT_PaymentReference"]));
            if (paymentPending.OutPaymentResult == "A")
            {
                SetErrorMessage("Online Payment Approved: $" + paymentPending.PaymentAmount + ".<br />Adjusted Amount Owed Remaining Showing Above.");
            }
            if (paymentPending.OutPaymentResult == "U")
            {
                SetErrorMessage("Online Payment was not able to be processed at this time");
            }
            if (paymentPending.OutPaymentResult == "F")
            {
                SetErrorMessage("<div style=\"height:15px;\"></div><span style=\"font-size: 150%;\">Online Payment Failed: <b>" + paymentPending.OutPaymentResultText + "</b></span><div style=\"height:2px;\"></div>");
            }
        }
    }