///<summary>Builds a receipt string for a web service transaction.</summary> public static string BuildReceiptString(PayConnectService.creditCardRequest request, PayConnectService.transResponse response, PayConnectService.signatureResponse sigResponse, long clinicNum) { string result = ""; int xmin = 0; int xleft = xmin; int xright = 15; int xmax = 37; result += Environment.NewLine; result += CreditCardUtils.AddClinicToReceipt(clinicNum); //Print body result += "Date".PadRight(xright - xleft, '.') + DateTime.Now.ToString() + Environment.NewLine; result += Environment.NewLine; result += "Trans Type".PadRight(xright - xleft, '.') + request.TransType.ToString() + Environment.NewLine; result += Environment.NewLine; result += "Transaction #".PadRight(xright - xleft, '.') + response.RefNumber + Environment.NewLine; result += "Name".PadRight(xright - xleft, '.') + request.NameOnCard + Environment.NewLine; result += "Account".PadRight(xright - xleft, '.'); for (int i = 0; i < request.CardNumber.Length - 4; i++) { result += "*"; } result += request.CardNumber.Substring(request.CardNumber.Length - 4) + Environment.NewLine; //last 4 digits of card number only. result += "Exp Date".PadRight(xright - xleft, '.') + request.Expiration.month.ToString().PadLeft(2, '0') + (request.Expiration.year % 100) + Environment.NewLine; result += "Card Type".PadRight(xright - xleft, '.') + CreditCardUtils.GetCardType(request.CardNumber) + Environment.NewLine; result += "Entry".PadRight(xright - xleft, '.') + (String.IsNullOrEmpty(request.MagData) ? "Manual" : "Swiped") + Environment.NewLine; result += "Auth Code".PadRight(xright - xleft, '.') + response.AuthCode + Environment.NewLine; result += "Result".PadRight(xright - xleft, '.') + response.Status.description + Environment.NewLine; if (response.Messages != null) { string label = "Message"; foreach (string m in response.Messages) { result += label.PadRight(xright - xleft, '.') + m + Environment.NewLine; label = ""; } } result += Environment.NewLine + Environment.NewLine + Environment.NewLine; if (request.TransType.In(PayConnectService.transType.RETURN, PayConnectService.transType.VOID)) { result += "Total Amt".PadRight(xright - xleft, '.') + (request.Amount * -1) + Environment.NewLine; } else { result += "Total Amt".PadRight(xright - xleft, '.') + request.Amount + Environment.NewLine; } result += Environment.NewLine + Environment.NewLine + Environment.NewLine; result += "I agree to pay the above total amount according to my card issuer/bank agreement." + Environment.NewLine; result += Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine; if (sigResponse == null || sigResponse.Status == null || sigResponse.Status.code != 0) { result += "Signature X".PadRight(xmax - xleft, '_'); } else { result += "Electronically signed"; } return(result); }
public static PayConnectService.signatureResponse ProcessSignature(PayConnectService.signatureRequest sigRequest, long clinicNum, Action <string> showError) { try { Program prog = Programs.GetCur(ProgramName.PayConnect); PayConnectService.Credentials cred = GetCredentials(prog, clinicNum); PayConnectService.MerchantService ms = new PayConnectService.MerchantService(); #if DEBUG ms.Url = "https://prelive.dentalxchange.com/merchant/MerchantService?wsdl"; #else ms.Url = "https://webservices.dentalxchange.com/merchant/MerchantService?wsdl"; #endif PayConnectService.signatureResponse response = ms.processSignature(cred, sigRequest); ms.Dispose(); if (response.Status.code != 0) //Error { showError(Lans.g("PayConnect", "Signature capture failed") + ". \r\n" + Lans.g("PayConnect", "Error message from") + " Pay Connect: \"" + response.Status.description + "\""); } return(response); } catch (Exception ex) { showError(Lans.g("PayConnect", "Signature capture failed") + ". \r\n" + Lans.g("PayConnect", "Error message from") + " Open Dental: \"" + ex.Message + "\""); } return(null); }
///<summary>Builds a receipt string for a web service transaction.</summary> public static string BuildReceiptString(PayConnectService.creditCardRequest request, PayConnectService.transResponse response, PayConnectService.signatureResponse sigResponse, long clinicNum) { if (response == null) { return(""); } int sigResponseStatusCode = GetSigResponseStatusCode(sigResponse); return(BuildReceiptString(request.TransType, response.RefNumber, request.NameOnCard, request.CardNumber, request.MagData, response.AuthCode, response.Status.description, response.Messages == null ? null : response.Messages.ToList(), request.Amount, sigResponseStatusCode, clinicNum)); }
private static int GetSigResponseStatusCode(PayConnectService.signatureResponse sigResponse) { return((sigResponse != null && sigResponse.Status != null) ? sigResponse.Status.code : 0); }
///<summary>Builds a receipt string for a terminal transaction.</summary> public static string BuildReceiptString(PosRequest posRequest, PosResponse posResponse, PayConnectService.signatureResponse sigResponse, long clinicNum) { string result = ""; int xleft = 0; int xright = 15; int xmax = 37; result += Environment.NewLine; result += CreditCardUtils.AddClinicToReceipt(clinicNum); //Print body result += "Date".PadRight(xright - xleft, '.') + DateTime.Now.ToString() + Environment.NewLine; result += Environment.NewLine; result += AddReceiptField("Trans Type", posResponse.TransactionType.ToString()); result += Environment.NewLine; result += AddReceiptField("Transaction #", posResponse.ReferenceNumber.ToString()); result += AddReceiptField("Account", posResponse.CardNumber); result += AddReceiptField("Card Type", posResponse.CardBrand); result += AddReceiptField("Entry", posResponse.EntryMode); result += AddReceiptField("Auth Code", posResponse.AuthCode); result += AddReceiptField("Result", posResponse.ResponseDescription); result += AddReceiptField("MerchantId", posResponse.MerchantId); result += AddReceiptField("TerminalId", posResponse.TerminalId); result += AddReceiptField("Mode", posResponse.Mode); result += AddReceiptField("CardVerifyMthd", posResponse.CardVerificationMethod); if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.AppId)) { result += AddReceiptField("EMV AppId", posResponse.EMV.AppId); } if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.TermVerifResults)) { result += AddReceiptField("EMV TermResult", posResponse.EMV.TermVerifResults); } if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.IssuerAppData)) { result += AddReceiptField("EMV IssuerData", posResponse.EMV.IssuerAppData); } if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.TransStatusInfo)) { result += AddReceiptField("EMV TransInfo", posResponse.EMV.TransStatusInfo); } if (posResponse.EMV != null && !string.IsNullOrEmpty(posResponse.EMV.AuthResponseCode)) { result += AddReceiptField("EMV AuthResp", posResponse.EMV.AuthResponseCode); } result += Environment.NewLine + Environment.NewLine + Environment.NewLine; if (posResponse.TransactionType.In(TransactionType.Refund, TransactionType.Void)) { result += "Total Amt".PadRight(xright - xleft, '.') + (posResponse.Amount * -1) + Environment.NewLine; } else { result += "Total Amt".PadRight(xright - xleft, '.') + posResponse.Amount + Environment.NewLine; } result += Environment.NewLine + Environment.NewLine + Environment.NewLine; result += "I agree to pay the above total amount according to my card issuer/bank agreement." + Environment.NewLine; result += Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine; if (sigResponse == null || sigResponse.Status == null || sigResponse.Status.code != 0) { result += "Signature X".PadRight(xmax - xleft, '_'); } else { result += "Electronically signed"; } return(result); }
///<summary>Processes a PayConnect payment via a credit card terminal.</summary> private bool ProcessPaymentTerminal() { PosRequest posRequest = null; try { if (radioSale.Checked) { posRequest = PosRequest.CreateSale(PIn.Decimal(textAmount.Text)); } else if (radioAuthorization.Checked) { posRequest = PosRequest.CreateAuth(PIn.Decimal(textAmount.Text)); } else if (radioVoid.Checked) { posRequest = PosRequest.CreateVoidByReference(textRefNumber.Text); } else if (radioReturn.Checked) { if (textRefNumber.Text == "") { posRequest = PosRequest.CreateRefund(PIn.Decimal(textAmount.Text)); } else { posRequest = PosRequest.CreateRefund(PIn.Decimal(textAmount.Text), textRefNumber.Text); } } else //Shouldn't happen { MsgBox.Show(this, "Please select a transaction type"); return(false); } posRequest.ForceDuplicate = checkForceDuplicate.Checked; } catch (Exception ex) { MessageBox.Show(Lan.g(this, "Error creating request:") + " " + ex.Message); return(false); } Action actionCloseProgress = null; try { actionCloseProgress = ODProgressOld.ShowProgressStatus("PayConnectProcessing", this, Lan.g(this, "Processing payment on terminal")); _posResponse = DpsPos.ProcessCreditCard(posRequest); } catch (Exception ex) { actionCloseProgress?.Invoke(); MessageBox.Show(Lan.g(this, "Error processing card:") + " " + ex.Message); return(false); } actionCloseProgress?.Invoke(); if (_posResponse == null) { MessageBox.Show(Lan.g(this, "Error processing card")); return(false); } if (_posResponse.ResponseCode != "0") //"0" indicates success. May need to check the AuthCode field too to determine if this was a success. { MessageBox.Show(Lan.g(this, "Error message from Pay Connect:") + "\r\n" + _posResponse.ResponseDescription); return(false); } PayConnectService.signatureResponse sigResponse = null; try { Cursor = Cursors.WaitCursor; sigResponse = SendSignature(_posResponse.ReferenceNumber.ToString()); Cursor = Cursors.Default; } catch (Exception ex) { Cursor = Cursors.Default; MessageBox.Show(Lan.g(this, "Card successfully charged. Error processing signature:") + " " + ex.Message); } textCardNumber.Text = _posResponse.CardNumber; textAmount.Text = _posResponse.Amount.ToString("f"); _receiptStr = PayConnectUtils.BuildReceiptString(posRequest, _posResponse, sigResponse, _clinicNum); PrintReceipt(_receiptStr); return(true); }
///<summary>Processes a PayConnect payment via the PayConnect web service.</summary> private bool ProcessPaymentWebService(int expYear, int expMonth) { string refNumber = ""; if (_trantype == PayConnectService.transType.VOID || _trantype == PayConnectService.transType.RETURN) { refNumber = textRefNumber.Text; } string magData = null; if (_parser != null) { magData = _parser.Track2; } string cardNumber = textCardNumber.Text; //if using a stored CC and there is an X-Charge token saved for the CC and the user enters the whole card number to get a PayConnect token //and the number entered doesn't have the same last 4 digits and exp date, then assume it's not the same card and clear out the X-Charge token. if (_creditCardCur != null && //using a saved CC !string.IsNullOrEmpty(_creditCardCur.XChargeToken) && //there is an X-Charge token saved (cardNumber.Right(4) != _creditCardCur.CCNumberMasked.Right(4) || //the card number entered doesn't have the same last 4 digits expYear != _creditCardCur.CCExpiration.Year || //the card exp date entered doesn't have the same year expMonth != _creditCardCur.CCExpiration.Month)) //the card exp date entered doesn't have the same month { if (MsgBox.Show(this, MsgBoxButtons.YesNo, "The card number or expiration date entered does not match the X-Charge card on file. Do you wish " + "to replace the X-Charge card with this one?")) { _creditCardCur.XChargeToken = ""; } else { Cursor = Cursors.Default; return(false); } } //if the user has chosen to store CC tokens and the stored CC has a token and the token is not expired, //then use it instead of the CC number and CC expiration. if (checkSaveToken.Checked && _creditCardCur != null && //if the user selected a saved CC _creditCardCur.PayConnectToken != "" && //there is a stored token for this card _creditCardCur.PayConnectTokenExp.Date >= DateTime.Today.Date) //the token is not expired { cardNumber = _creditCardCur.PayConnectToken; expYear = _creditCardCur.PayConnectTokenExp.Year; expMonth = _creditCardCur.PayConnectTokenExp.Month; } string authCode = ""; if (_trantype == PayConnectService.transType.FORCE) { authCode = textRefNumber.Text; } _request = Bridges.PayConnect.BuildSaleRequest(PIn.Decimal(textAmount.Text), cardNumber, expYear, expMonth, textNameOnCard.Text, textSecurityCode.Text, textZipCode.Text, magData, _trantype, refNumber, checkSaveToken.Checked, authCode, checkForceDuplicate.Checked); _response = Bridges.PayConnect.ProcessCreditCard(_request, _clinicNum); if (_response == null || _response.Status.code != 0) //error in transaction { return(false); } PayConnectService.signatureResponse sigResponse = SendSignature(_response.RefNumber); if ((_trantype.In(PayConnectService.transType.SALE, PayConnectService.transType.RETURN, PayConnectService.transType.VOID)) && _response.Status.code == 0) //Only print a receipt if transaction is an approved SALE, RETURN, or VOID { _receiptStr = PayConnectUtils.BuildReceiptString(_request, _response, sigResponse, _clinicNum); PrintReceipt(_receiptStr); } if (!PrefC.GetBool(PrefName.StoreCCnumbers) && !checkSaveToken.Checked) //not storing the card number or the token { return(true); } //response must be non-null and the status code must be 0=Approved //also, the user must have the pref StoreCCnumbers enabled or they have the checkSaveTokens checked if (_creditCardCur == null) //user selected Add new card from the payment window, save it or its token depending on settings { _creditCardCur = new CreditCard(); _creditCardCur.IsNew = true; _creditCardCur.PatNum = _patCur.PatNum; List <CreditCard> itemOrderCount = CreditCards.Refresh(_patCur.PatNum); _creditCardCur.ItemOrder = itemOrderCount.Count; } _creditCardCur.CCExpiration = new DateTime(expYear, expMonth, DateTime.DaysInMonth(expYear, expMonth)); if (PrefC.GetBool(PrefName.StoreCCnumbers)) { _creditCardCur.CCNumberMasked = textCardNumber.Text; } else { _creditCardCur.CCNumberMasked = textCardNumber.Text.Right(4).PadLeft(textCardNumber.Text.Length, 'X'); } _creditCardCur.Zip = textZipCode.Text; _creditCardCur.PayConnectToken = ""; _creditCardCur.PayConnectTokenExp = DateTime.MinValue; //Store the token and the masked CC number (only last four digits). if (checkSaveToken.Checked && _response.PaymentToken != null) { _creditCardCur.PayConnectToken = _response.PaymentToken.TokenId; _creditCardCur.PayConnectTokenExp = new DateTime(_response.PaymentToken.Expiration.year, _response.PaymentToken.Expiration.month, DateTime.DaysInMonth(_response.PaymentToken.Expiration.year, _response.PaymentToken.Expiration.month)); } _creditCardCur.CCSource = CreditCardSource.PayConnect; if (_creditCardCur.IsNew) { _creditCardCur.ClinicNum = _clinicNum; _creditCardCur.Procedures = PrefC.GetString(PrefName.DefaultCCProcs); CreditCards.Insert(_creditCardCur); } else { if (_creditCardCur.CCSource == CreditCardSource.XServer) //This card has also been added for XCharge. { _creditCardCur.CCSource = CreditCardSource.XServerPayConnect; } CreditCards.Update(_creditCardCur); } return(true); }