///<summary></summary> public static long Insert(CreditCard creditCard){ if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){ creditCard.CreditCardNum=Meth.GetLong(MethodBase.GetCurrentMethod(),creditCard); return creditCard.CreditCardNum; } return Crud.CreditCardCrud.Insert(creditCard); }
///<summary></summary> public static void Update(CreditCard creditCard){ if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){ Meth.GetVoid(MethodBase.GetCurrentMethod(),creditCard); return; } Crud.CreditCardCrud.Update(creditCard); }
public FormCreditRecurringDateChoose(CreditCard creditCard) { InitializeComponent(); CreditCardCur=creditCard; lastMonth=GetValidPayDate(DateTime.Now.AddMonths(-1)); thisMonth=GetValidPayDate(DateTime.Now); Lan.F(this); }
///<summary>Can handle CreditCard being null.</summary> public FormPayConnect(Payment payment,Patient pat,string amount,CreditCard creditCard) { InitializeComponent(); Lan.F(this); PaymentCur=payment; PatCur=pat; amountInit=amount; receiptStr=""; CreditCardCur=creditCard; }
private void FormCreditCardEdit_Load(object sender,EventArgs e) { CreditCardOld=CreditCardCur.Clone(); FillData(); if(IsXCharge) {//Get recurring payment plan information if using X-Charge. List<PayPlanCharge> chargeList=PayPlanCharges.Refresh(PatCur.PatNum); PayPlanList=PayPlans.GetValidPlansNoIns(PatCur.PatNum); comboPaymentPlans.Items.Add("None"); comboPaymentPlans.SelectedIndex=0; for(int i=0;i<PayPlanList.Count;i++) { comboPaymentPlans.Items.Add(PayPlans.GetTotalPrinc(PayPlanList[i].PayPlanNum,chargeList).ToString("F") +" "+Patients.GetPat(PayPlanList[i].PatNum).GetNameFL()); if(PayPlanList[i].PayPlanNum==CreditCardCur.PayPlanNum) { comboPaymentPlans.SelectedIndex=i+1; } } } else {//This will hide the recurring section and change the window size. groupRecurringCharges.Visible=false; this.ClientSize=new System.Drawing.Size(this.ClientSize.Width,this.ClientSize.Height-215); } }
private void butOK_Click(object sender,EventArgs e) { if(!VerifyData()) { return; } CreditCardCur.Address=textAddress.Text; CreditCardCur.CCNumberMasked=textCardNumber.Text; CreditCardCur.PatNum=PatCur.PatNum; CreditCardCur.Zip=textZip.Text; if(IsXCharge) {//Only update recurring if using X-Charge. CreditCardCur.ChargeAmt=PIn.Double(textChargeAmt.Text); CreditCardCur.DateStart=PIn.Date(textDateStart.Text); CreditCardCur.DateStop=PIn.Date(textDateStop.Text); CreditCardCur.Note=textNote.Text; if(comboPaymentPlans.SelectedIndex>0) { CreditCardCur.PayPlanNum=PayPlanList[comboPaymentPlans.SelectedIndex-1].PayPlanNum; } else { CreditCardCur.PayPlanNum=0;//Allows users to change from a recurring payplan charge to a normal one. } } if(CreditCardCur.IsNew) { List<CreditCard> itemOrderCount=CreditCards.Refresh(PatCur.PatNum); CreditCardCur.ItemOrder=itemOrderCount.Count; CreditCards.Insert(CreditCardCur); } else { #region X-Charge //Special logic for had a token and changed number or expiration date if(CreditCardCur.XChargeToken!="" && IsXCharge && (CreditCardOld.CCNumberMasked!=CreditCardCur.CCNumberMasked || CreditCardOld.CCExpiration!=CreditCardCur.CCExpiration)) { Program prog=Programs.GetCur(ProgramName.Xcharge); string path=Programs.GetProgramPath(prog); if(prog==null){ MsgBox.Show(this,"X-Charge entry is missing from the database.");//should never happen return; } if(!prog.Enabled){ if(Security.IsAuthorized(Permissions.Setup)){ FormXchargeSetup FormX=new FormXchargeSetup(); FormX.ShowDialog(); } return; } if(!File.Exists(path)){ MsgBox.Show(this,"Path is not valid."); if(Security.IsAuthorized(Permissions.Setup)){ FormXchargeSetup FormX=new FormXchargeSetup(); FormX.ShowDialog(); } return; } //Either update the exp date or update credit card number by deleting archive so new token can be created next time it's used. ProgramProperty prop=(ProgramProperty)ProgramProperties.GetForProgram(prog.ProgramNum)[0]; ProcessStartInfo info=new ProcessStartInfo(path); string resultfile=Path.Combine(Path.GetDirectoryName(path),"XResult.txt"); try { File.Delete(resultfile);//delete the old result file. } catch { MsgBox.Show(this,"Could not delete XResult.txt file. It may be in use by another program, flagged as read-only, or you might not have sufficient permissions."); return; } if(CreditCardOld.CCNumberMasked!=CreditCardCur.CCNumberMasked) {//They changed card number which we have to delete archived token which will create a new one next time card is charged. info.Arguments+="/TRANSACTIONTYPE:ARCHIVEVAULTDELETE "; info.Arguments+="/XCACCOUNTID:"+CreditCardCur.XChargeToken+" "; info.Arguments+="/RESULTFILE:\""+resultfile+"\" "; info.Arguments+="/USERID:"+ProgramProperties.GetPropVal(prog.ProgramNum,"Username")+" "; info.Arguments+="/PASSWORD:"******"Password"))+" "; info.Arguments+="/AUTOPROCESS "; info.Arguments+="/AUTOCLOSE "; CreditCardCur.XChargeToken="";//Clear the XChargeToken in our db. } else {//We can only change exp date for X-Charge via ARCHIVEAULTUPDATE. info.Arguments+="/TRANSACTIONTYPE:ARCHIVEVAULTUPDATE "; info.Arguments+="/XCACCOUNTID:"+CreditCardCur.XChargeToken+" "; if(CreditCardCur.CCExpiration!=null && CreditCardCur.CCExpiration.Year>2005) { info.Arguments+="/EXP:"+CreditCardCur.CCExpiration.ToString("MMyy")+" "; } info.Arguments+="/RESULTFILE:\""+resultfile+"\" "; info.Arguments+="/USERID:"+ProgramProperties.GetPropVal(prog.ProgramNum,"Username")+" "; info.Arguments+="/PASSWORD:"******"Password"))+" "; info.Arguments+="/AUTOPROCESS "; info.Arguments+="/AUTOCLOSE "; } Cursor=Cursors.WaitCursor; Process process=new Process(); process.StartInfo=info; process.EnableRaisingEvents=true; process.Start(); while(!process.HasExited) { Application.DoEvents(); } Thread.Sleep(200);//Wait 2/10 second to give time for file to be created. Cursor=Cursors.Default; string resulttext=""; string line=""; try { using(TextReader reader=new StreamReader(resultfile)) { line=reader.ReadLine(); while(line!=null) { if(resulttext!="") { resulttext+="\r\n"; } resulttext+=line; if(line.StartsWith("RESULT=")) { if(line!="RESULT=SUCCESS") { CreditCardCur=CreditCards.GetOne(CreditCardCur.CreditCardNum); FillData(); return; } } line=reader.ReadLine(); } } } catch { MsgBox.Show(this,"There was a problem creating or editing this card with X-Charge. Please try again."); return; } }//End of special token logic #endregion CreditCards.Update(CreditCardCur); } DialogResult=DialogResult.OK; }
private string GetXChargeTransactionTypeCommands(int tranType,bool hasXToken,bool notRecurring,CreditCard CCard,string cashBack) { string tranText=""; switch(tranType) { case 0: tranText+="/TRANSACTIONTYPE:PURCHASE /LOCKTRANTYPE "; if(hasXToken) { tranText+="/XCACCOUNTID:"+CCard.XChargeToken+" "; tranText+="/AUTOPROCESS "; } if(notRecurring) { tranText+="/ACCOUNT:"+CCard.CCNumberMasked+" "; tranText+="/AUTOPROCESS "; } break; case 1: tranText+="/TRANSACTIONTYPE:RETURN /LOCKTRANTYPE "; if(hasXToken) { tranText+="/XCACCOUNTID:"+CCard.XChargeToken+" "; tranText+="/AUTOPROCESS "; } if(notRecurring) { tranText+="/ACCOUNT:"+CCard.CCNumberMasked+" "; tranText+="/AUTOPROCESS "; } break; case 2: tranText+="/TRANSACTIONTYPE:DEBITPURCHASE /LOCKTRANTYPE "; tranText+="/CASHBACK:"+cashBack+" "; break; case 3: tranText+="/TRANSACTIONTYPE:DEBITRETURN /LOCKTRANTYPE "; break; case 4: tranText+="/TRANSACTIONTYPE:FORCE /LOCKTRANTYPE "; break; case 5: tranText+="/TRANSACTIONTYPE:PREAUTH /LOCKTRANTYPE "; if(hasXToken) { tranText+="/XCACCOUNTID:"+CCard.XChargeToken+" "; tranText+="/AUTOPROCESS "; } if(notRecurring) { tranText+="/ACCOUNT:"+CCard.CCNumberMasked+" "; tranText+="/AUTOPROCESS "; } break; case 6: tranText+="/TRANSACTIONTYPE:ADJUSTMENT /LOCKTRANTYPE "; string adjustTransactionID=""; string[] noteSplit=Regex.Split(textNote.Text,"\r\n"); foreach(string XCTrans in noteSplit) { if(XCTrans.StartsWith("XCTRANSACTIONID=")) { adjustTransactionID=XCTrans.Substring(16); } } if(adjustTransactionID!="") { tranText+="/XCTRANSACTIONID:"+adjustTransactionID+" "; tranText+="/AUTOPROCESS "; } break; case 7: tranText+="/TRANSACTIONTYPE:VOID /LOCKTRANTYPE "; break; } return tranText; }
private void panelXcharge_MouseClick(object sender,MouseEventArgs e) { if(e.Button != MouseButtons.Left) { return; } if(textAmount.Text=="") { MsgBox.Show(this,"Please enter an amount first."); return; } if(!HasXCharge()) { return; } bool needToken=false; bool newCard=false; bool hasXToken=false; bool notRecurring=false; prop=(ProgramProperty)ProgramProperties.GetForProgram(prog.ProgramNum)[0]; //still need to add functionality for accountingAutoPay listPayType.SelectedIndex=DefC.GetOrder(DefCat.PaymentTypes,PIn.Long(prop.PropertyValue)); SetComboDepositAccounts(); /*XCharge.exe [/TRANSACTIONTYPE:type] [/AMOUNT:amount] [/ACCOUNT:account] [/EXP:exp] [“/TRACK:track”] [/ZIP:zip] [/ADDRESS:address] [/RECEIPT:receipt] [/CLERK:clerk] [/APPROVALCODE:approval] [/AUTOPROCESS] [/AUTOCLOSE] [/STAYONTOP] [/MID] [/RESULTFILE:”C:\Program Files\X-Charge\LocalTran\XCResult.txt”*/ ProcessStartInfo info=new ProcessStartInfo(prog.Path); Patient pat=Patients.GetPat(PaymentCur.PatNum); PatientNote patnote=PatientNotes.Refresh(pat.PatNum,pat.Guarantor); string resultfile=Path.Combine(Path.GetDirectoryName(prog.Path),"XResult.txt"); File.Delete(resultfile);//delete the old result file. info.Arguments=""; double amt=PIn.Double(textAmount.Text); if(amt>0) { info.Arguments+="/AMOUNT:"+amt.ToString("F2")+" /LOCKAMOUNT "; } CreditCard CCard=null; List<CreditCard> creditCards=CreditCards.Refresh(PatCur.PatNum); for(int i=0;i<creditCards.Count;i++) { if(i==comboCreditCards.SelectedIndex) { CCard=creditCards[i]; } } //Show window to lock in the transaction type. FormXchargeTrans FormXT=new FormXchargeTrans(); FormXT.ShowDialog(); if(FormXT.DialogResult!=DialogResult.OK) { return; } int tranType=FormXT.TransactionType; string cashBack=FormXT.CashBackAmount.ToString("F2"); if(CCard!=null) { //Have credit card on file if(CCard.XChargeToken!="") {//Recurring charge hasXToken=true; /* ***** An example of how recurring charges work***** C:\Program Files\X-Charge\XCharge.exe /TRANSACTIONTYPE:Purchase /LOCKTRANTYPE /AMOUNT:10.00 /LOCKAMOUNT /XCACCOUNTID:XAW0JWtx5kjG8 /RECEIPT:RC001 /LOCKRECEIPT /CLERK:Clerk /LOCKCLERK /RESULTFILE:C:\ResultFile.txt /USERID:system /PASSWORD:system /STAYONTOP /AUTOPROCESS /AUTOCLOSE /HIDEMAINWINDOW /RECURRING /SMALLWINDOW /NORESULTDIALOG */ } else {//Not recurring charge, on file and might need a token. notRecurring=true; if(!PrefC.GetBool(PrefName.StoreCCnumbers)) {//Use token only if user has has pref unchecked in module setup (allow store credit card nums). needToken=true;//Will create a token from result file so credit card info isn't saved in our db. } } } else {//Add card option was selected in credit card drop down. No other possibility. newCard=true; } info.Arguments+=GetXChargeTransactionTypeCommands(tranType,hasXToken,notRecurring,CCard,cashBack); if(newCard) { info.Arguments+="\"/ZIP:"+pat.Zip+"\" "; info.Arguments+="\"/ADDRESS:"+pat.Address+"\" "; } else { if(CCard.CCExpiration!=null && CCard.CCExpiration.Year>2005) { info.Arguments+="/EXP:"+CCard.CCExpiration.ToString("MMyy")+" "; } if(CCard.Zip!="") { info.Arguments+="\"/ZIP:"+CCard.Zip+"\" "; } else { info.Arguments+="\"/ZIP:"+pat.Zip+"\" "; } if(CCard.Address!="") { info.Arguments+="\"/ADDRESS:"+CCard.Address+"\" "; } else { info.Arguments+="\"/ADDRESS:"+pat.Address+"\" "; } if(hasXToken) {//Special parameter for tokens. info.Arguments+="/RECURRING "; } } info.Arguments+="/RECEIPT:Pat"+PaymentCur.PatNum.ToString()+" ";//aka invoice# info.Arguments+="\"/CLERK:"+Security.CurUser.UserName+"\" /LOCKCLERK "; info.Arguments+="/RESULTFILE:\""+resultfile+"\" "; info.Arguments+="/USERID:"+ProgramProperties.GetPropVal(prog.ProgramNum,"Username")+" "; info.Arguments+="/PASSWORD:"******"Password")+" "; info.Arguments+="/PARTIALAPPROVALSUPPORT:T "; info.Arguments+="/AUTOCLOSE "; info.Arguments+="/HIDEMAINWINDOW "; info.Arguments+="/SMALLWINDOW "; info.Arguments+="/GETXCACCOUNTID "; info.Arguments+="/NORESULTDIALOG "; Cursor=Cursors.WaitCursor; Process process=new Process(); process.StartInfo=info; process.EnableRaisingEvents=true; process.Start(); while(!process.HasExited) { Application.DoEvents(); } Thread.Sleep(200);//Wait 2/10 second to give time for file to be created. Cursor=Cursors.Default; string resulttext=""; string line=""; bool showApprovedAmtNotice=false; bool xAdjust=false; bool xVoid=false; double approvedAmt=0; double additionalFunds=0; string xChargeToken=""; string accountMasked=""; string expiration=""; using(TextReader reader=new StreamReader(resultfile)) { line=reader.ReadLine(); /*Example of successful transaction: RESULT=SUCCESS TYPE=Purchase APPROVALCODE=000064 ACCOUNT=XXXXXXXXXXXX6781 ACCOUNTTYPE=VISA* AMOUNT=1.77 AVSRESULT=Y CVRESULT=M */ while(line!=null) { if(resulttext!="") { resulttext+="\r\n"; } resulttext+=line; if(line.StartsWith("RESULT=")) { if(line!="RESULT=SUCCESS") { //Charge was a failure and there might be a description as to why it failed. Continue to loop through line. while(line!=null) { line=reader.ReadLine(); resulttext+="\r\n"+line; } needToken=false;//Don't update CCard due to failure newCard=false;//Don't insert CCard due to failure break; } if(tranType==6) { xAdjust=true; } if(tranType==7) { xVoid=true; } } if(line.StartsWith("APPROVEDAMOUNT=")) { approvedAmt=PIn.Double(line.Substring(15)); if(approvedAmt != amt) { showApprovedAmtNotice=true; } } if(line.StartsWith("XCACCOUNTID=")) { xChargeToken=PIn.String(line.Substring(12)); } if(line.StartsWith("ACCOUNT=")) { accountMasked=PIn.String(line.Substring(8)); } if(line.StartsWith("EXPIRATION=")) { expiration=PIn.String(line.Substring(11)); } if(line.StartsWith("ADDITIONALFUNDSREQUIRED=")) { additionalFunds=PIn.Double(line.Substring(24)); } line=reader.ReadLine(); } if(needToken && xChargeToken!="") { //Only way this code can be hit is if they have set up a credit card and it does not have a token. //So we'll use the created token from result file and assign it to the coresponding account. //Also will delete the credit card number and replace it with secure masked number. CCard.XChargeToken=xChargeToken; CCard.CCNumberMasked=accountMasked; CCard.CCExpiration=new DateTime(Convert.ToInt32("20"+expiration.Substring(2,2)),Convert.ToInt32(expiration.Substring(0,2)),1); CreditCards.Update(CCard); } if(newCard) { if(xChargeToken=="") {//Shouldn't happen again but leaving just in case. MsgBox.Show(this,"X-Charge didn't return a token so credit card information couldn't be saved."); } else { if(FormXT.SaveToken) { CCard=new CreditCard(); List<CreditCard> itemOrderCount=CreditCards.Refresh(PatCur.PatNum); CCard.ItemOrder=itemOrderCount.Count; CCard.PatNum=PatCur.PatNum; CCard.CCExpiration=new DateTime(Convert.ToInt32("20"+expiration.Substring(2,2)),Convert.ToInt32(expiration.Substring(0,2)),1); CCard.XChargeToken=xChargeToken; CCard.CCNumberMasked=accountMasked; CreditCards.Insert(CCard); } } } } if(showApprovedAmtNotice && !xVoid && !xAdjust) { if(MessageBox.Show(Lan.g(this,"The amount you typed in: ")+amt.ToString("C")+" \r\n"+Lan.g(this,"does not match the approved amount returned: ")+approvedAmt.ToString("C") +"\r\n"+Lan.g(this,"Change the amount to match?"),"Alert",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation)==DialogResult.OK) { textAmount.Text=approvedAmt.ToString("F"); } } if(xAdjust) { MessageBox.Show(Lan.g(this,"The amount will be changed to the X-Charge approved amount: ")+approvedAmt.ToString("C")); textNote.Text=""; textAmount.Text=approvedAmt.ToString("F"); } if(xVoid) { if(IsNew) { textAmount.Text="-"+approvedAmt.ToString("F"); } } if(additionalFunds>0) { MessageBox.Show(Lan.g(this,"Additional funds required: ")+additionalFunds.ToString("C")); } if(textNote.Text!="") { textNote.Text+="\r\n"; } textNote.Text+=resulttext; }
private void butAdd_Click(object sender,EventArgs e) { if(!PrefC.GetBool(PrefName.StoreCCnumbers)) { if(Programs.IsEnabled(ProgramName.Xcharge)) { Program prog=Programs.GetCur(ProgramName.Xcharge); string path=Programs.GetProgramPath(prog); if(!File.Exists(path)){ MsgBox.Show(this,"Path is not valid."); if(Security.IsAuthorized(Permissions.Setup)) { FormXchargeSetup FormX=new FormXchargeSetup(); FormX.ShowDialog(); if(FormX.DialogResult!=DialogResult.OK) { return; } } } string user=ProgramProperties.GetPropVal(prog.ProgramNum,"Username"); string password=ProgramProperties.GetPropVal(prog.ProgramNum,"Password"); ProcessStartInfo info=new ProcessStartInfo(path); string resultfile=Path.Combine(Path.GetDirectoryName(path),"XResult.txt"); File.Delete(resultfile);//delete the old result file. info.Arguments=""; info.Arguments+="/TRANSACTIONTYPE:ArchiveVaultAdd /LOCKTRANTYPE "; info.Arguments+="/RESULTFILE:\""+resultfile+"\" "; info.Arguments+="/USERID:"+user+" "; info.Arguments+="/PASSWORD:"******" "; info.Arguments+="/VALIDATEARCHIVEVAULTACCOUNT "; info.Arguments+="/STAYONTOP "; info.Arguments+="/SMARTAUTOPROCESS "; info.Arguments+="/AUTOCLOSE "; info.Arguments+="/HIDEMAINWINDOW "; info.Arguments+="/SMALLWINDOW "; info.Arguments+="/NORESULTDIALOG "; info.Arguments+="/TOOLBAREXITBUTTON "; Cursor=Cursors.WaitCursor; Process process=new Process(); process.StartInfo=info; process.EnableRaisingEvents=true; process.Start(); while(!process.HasExited) { Application.DoEvents(); } Thread.Sleep(200);//Wait 2/10 second to give time for file to be created. Cursor=Cursors.Default; string resulttext=""; string line=""; string xChargeToken=""; string accountMasked=""; string exp="";; bool insertCard=false; using(TextReader reader=new StreamReader(resultfile)) { line=reader.ReadLine(); while(line!=null) { if(resulttext!="") { resulttext+="\r\n"; } resulttext+=line; if(line.StartsWith("RESULT=")) { if(line!="RESULT=SUCCESS") { break; } insertCard=true; } if(line.StartsWith("XCACCOUNTID=")) { xChargeToken=PIn.String(line.Substring(12)); } if(line.StartsWith("ACCOUNT=")) { accountMasked=PIn.String(line.Substring(8)); } if(line.StartsWith("EXPIRATION=")) { exp=PIn.String(line.Substring(11)); } line=reader.ReadLine(); } if(insertCard && xChargeToken!="") {//Might not be necessary but we've had successful charges with no tokens returned before. CreditCard creditCardCur=new CreditCard(); List<CreditCard> itemOrderCount=CreditCards.Refresh(PatCur.PatNum); creditCardCur.PatNum=PatCur.PatNum; creditCardCur.ItemOrder=itemOrderCount.Count; creditCardCur.CCNumberMasked=accountMasked; creditCardCur.XChargeToken=xChargeToken; creditCardCur.CCExpiration=new DateTime(Convert.ToInt32("20"+PIn.String(exp.Substring(2,2))),Convert.ToInt32(PIn.String(exp.Substring(0,2))),1); CreditCards.Insert(creditCardCur); } } RefreshCardList(); return; } else { MsgBox.Show(this,"Not allowed to store credit cards."); return; } } bool remember=false; int placement=listCreditCards.SelectedIndex; if(placement!=-1) { remember=true; } FormCreditCardEdit FormCCE=new FormCreditCardEdit(PatCur); FormCCE.CreditCardCur=new CreditCard(); FormCCE.CreditCardCur.IsNew=true; FormCCE.ShowDialog(); RefreshCardList(); if(remember) {//in case they canceled and had one selected listCreditCards.SelectedIndex=placement; } if(FormCCE.DialogResult==DialogResult.OK && creditCards.Count>0) { listCreditCards.SelectedIndex=0; } }