private void processReturnToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!Security.IsAuthorized(Permissions.PaymentCreate))
     {
         return;
     }
     if (gridMain.SelectedIndices.Length < 1)
     {
         return;
     }
     if (IsXWebTransaction(gridMain.SelectedIndices[0]))
     {
         long              patNum    = PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PatNum"].ToString());
         string            alias     = _tableTrans.Rows[gridMain.SelectedIndices[0]]["Alias"].ToString();
         List <CreditCard> listCards = CreditCards.GetCardsByToken(alias,
                                                                   new List <CreditCardSource> {
             CreditCardSource.XWeb, CreditCardSource.XWebPortalLogin
         });
         if (listCards.Count == 0)
         {
             MsgBox.Show(this, "This credit card is no longer stored in the database. Return cannot be processed.");
             return;
         }
         if (listCards.Count > 1)
         {
             MsgBox.Show(this, "There is more than one card in the database with this token. Return cannot be processed due to the risk of charging the " +
                         "incorrect card.");
             return;
         }
         FormXWeb FormXW = new FormXWeb(patNum, listCards.FirstOrDefault(), XWebTransactionType.CreditReturnTransaction, createPayment: true);
         FormXW.LockCardInfo = true;
         if (FormXW.ShowDialog() == DialogResult.OK)
         {
             FillGrid();
         }
     }
     else
     {
         Payment payment = Payments.GetPayment(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PaymentNum"].ToString()));
         PayConnectResponseWeb pcResponseWeb = PayConnectResponseWebs.GetOne(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["ResponseNum"].ToString()));
         decimal amt    = PIn.Decimal(_tableTrans.Rows[gridMain.SelectedIndices[0]]["Amount"].ToString());
         string  refNum = _tableTrans.Rows[gridMain.SelectedIndices[0]]["TransactionID"].ToString();              //This is actually PayConnectResponseWeb.RefNumber, it's just stored in the TransactionID column
         if (!PayConnectL.VoidOrRefundPayConnectPortalTransaction(pcResponseWeb, payment, PayConnectService.transType.RETURN, refNum, amt))
         {
             return;
         }
         MsgBox.Show("Return successful.");
         FillGrid();
     }
 }
 private void voidPaymentToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!Security.IsAuthorized(Permissions.PaymentCreate))
     {
         return;
     }
     if (gridMain.SelectedIndices.Length < 1 ||
         !MsgBox.Show(this, MsgBoxButtons.YesNo, "Void this payment?"))
     {
         return;
     }
     try {
         Cursor = Cursors.WaitCursor;
         if (IsXWebTransaction(gridMain.SelectedIndices[0]))
         {
             long   patNum      = PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PatNum"].ToString());
             long   responseNum = PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["ResponseNum"].ToString());
             string payNote     = Lan.g(this, "Void XWeb payment made from within Open Dental") + "\r\n"
                                  + Lan.g(this, "Amount:") + " " + PIn.Double(_tableTrans.Rows[gridMain.SelectedIndices[0]]["Amount"].ToString()).ToString("f") + "\r\n"
                                  + Lan.g(this, "Transaction ID:") + " " + _tableTrans.Rows[gridMain.SelectedIndices[0]]["TransactionID"].ToString() + "\r\n"
                                  + Lan.g(this, "Card Number:") + " " + _tableTrans.Rows[gridMain.SelectedIndices[0]]["MaskedAcctNum"].ToString() + "\r\n"
                                  + Lan.g(this, "Processed:") + " " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
             XWebs.VoidPayment(patNum, payNote, responseNum);
         }
         else
         {
             Payment payment = Payments.GetPayment(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["PaymentNum"].ToString()));
             PayConnectResponseWeb pcResponseWeb = PayConnectResponseWebs.GetOne(PIn.Long(_tableTrans.Rows[gridMain.SelectedIndices[0]]["ResponseNum"].ToString()));
             decimal amt    = PIn.Decimal(_tableTrans.Rows[gridMain.SelectedIndices[0]]["Amount"].ToString());
             string  refNum = _tableTrans.Rows[gridMain.SelectedIndices[0]]["TransactionID"].ToString();                  //This is actually PayConnectResponseWeb.RefNumber, it's just stored in the TransactionID column
             if (!PayConnectL.VoidOrRefundPayConnectPortalTransaction(pcResponseWeb, payment, PayConnectService.transType.VOID, refNum, amt))
             {
                 Cursor = Cursors.Default;
                 return;
             }
         }
         Cursor = Cursors.Default;
         MsgBox.Show(this, "Void successful");
         FillGrid();
     }
     catch (ODException ex) {
         Cursor = Cursors.Default;
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #3
0
        /// <summary>Only used to void or refund transactions from PayConnectPortal. Creates new cloned payment and paysplits for the refund or void.
        /// Returns true if the transaction was successful, otherwise false.</summary
        public static bool VoidOrRefundPayConnectPortalTransaction(PayConnectResponseWeb pcResponseWeb, Payment payment, PayConnectService.transType transType, string refNum, decimal amount)
        {
            if (!transType.In(PayConnectService.transType.RETURN, PayConnectService.transType.VOID))
            {
                return(false);
            }
            List <PaySplit> listPaySplits = PaySplits.GetForPayment(payment.PayNum);

            PayConnectService.creditCardRequest _payConnectRequest = new PayConnectService.creditCardRequest();
            PayConnectResponse response   = null;
            string             receiptStr = "";

            _payConnectRequest.TransType = transType;
            _payConnectRequest.RefNumber = refNum;
            _payConnectRequest.Amount    = amount;
            PayConnectService.transResponse transResponse = PayConnect.ProcessCreditCard(_payConnectRequest, payment.ClinicNum, x => MsgBox.Show(x));
            response   = new PayConnectResponse(transResponse, _payConnectRequest);
            receiptStr = PayConnect.BuildReceiptString(_payConnectRequest, transResponse, null, payment.ClinicNum);
            if (response == null || response.StatusCode != "0")         //error in transaction
            {
                return(false);
            }
            //Record a new payment for the voided transaction
            Payment clonePayment = payment.Clone();

            clonePayment.PayAmt *= -1;           //The negated amount of the original payment
            clonePayment.PayDate = DateTime.Now;
            clonePayment.Receipt = receiptStr;
            clonePayment.PayNote = Lan.g("PayConnectL", "Transaction Type") + ": " + Enum.GetName(typeof(PayConnectService.transType), transType)
                                   + Environment.NewLine + Lan.g("PayConnectL", "Status") + ": " + response.Description + Environment.NewLine
                                   + Lan.g("PayConnectL", "Amount") + ": " + clonePayment.PayAmt + Environment.NewLine
                                   + Lan.g("PayConnectL", "Auth Code") + ": " + response.AuthCode + Environment.NewLine
                                   + Lan.g("PayConnectL", "Ref Number") + ": " + response.RefNumber;
            clonePayment.PaymentSource = pcResponseWeb.CCSource;
            clonePayment.ProcessStatus = ProcessStat.OfficeProcessed;
            clonePayment.PayNum        = Payments.Insert(clonePayment);
            List <PaySplit> listClonedPaySplits = new List <PaySplit>();

            foreach (PaySplit paySplit in listPaySplits)
            {
                PaySplit copy = paySplit.Copy();
                copy.SplitAmt *= -1;
                copy.PayNum    = clonePayment.PayNum;
                copy.DatePay   = clonePayment.PayDate;
                listClonedPaySplits.Add(copy);
            }
            PaySplits.InsertMany(listClonedPaySplits);
            PayConnectResponseWeb newPCResponseWeb = new PayConnectResponseWeb()
            {
                PatNum            = payment.PatNum,
                PayNum            = clonePayment.PayNum,
                CCSource          = pcResponseWeb.CCSource,
                Amount            = clonePayment.PayAmt,
                PayNote           = Lan.g("PayConnectL", clonePayment.PayNote + Environment.NewLine + "From within Open Dental Proper."),
                ProcessingStatus  = PayConnectWebStatus.Completed,
                DateTimeEntry     = DateTime.Now,
                DateTimeCompleted = DateTime.Now,
                IsTokenSaved      = false,
                RefNumber         = transResponse.RefNumber,
                TransType         = transType,
                PaymentToken      = pcResponseWeb.PaymentToken,
            };

            PayConnectResponseWebs.Insert(newPCResponseWeb);
            SecurityLogs.MakeLogEntry(Permissions.PaymentCreate, clonePayment.PatNum,
                                      Patients.GetLim(clonePayment.PatNum).GetNameLF() + ", " + clonePayment.PayAmt.ToString("c"));
            return(true);
        }