///<summary>Throws exceptions. Will purposefully throw ODExceptions that are already translated and and formatted.</summary> public static ApiResponse VoidPayment(string paySimplePaymentId, long clinicNum = -1) { ValidateProgram(clinicNum); if (string.IsNullOrWhiteSpace(paySimplePaymentId)) { throw new Exception(Lans.g("PaySimple", "Invalid PaySimple Payment ID to void.")); } return(PaySimpleApi.PutPaymentVoided(GetAuthHeader(clinicNum), paySimplePaymentId)); }
///<summary>Throws exceptions. Will purposefully throw ODExceptions that are already translated and and formatted.</summary> public static ApiResponse AddCreditCard(long customerId, string ccNum, DateTime ccExpDate, string billingZipCode = "", long clinicNum = -1) { ValidateProgram(clinicNum); if (customerId == 0) { throw new ODException(Lans.g("PaySimple", "Invalid PaySimple Customer ID provided: ") + customerId.ToString()); } return(PaySimpleApi.PostAccountCreditCard(GetAuthHeader(clinicNum), PaySimpleApi.MakeNewAccountCreditCardData(customerId, ccNum, ccExpDate, PaySimpleApi.GetCardType(ccNum), billingZipCode))); }
///<summary>Throws exceptions. Will purposefully throw ODExceptions that are already translated and and formatted. ///Returns the PaymentId given by PaySimple.</summary> private static ApiResponse MakePaymentNoPat(decimal payAmt, string ccNum, DateTime ccExpDate, string billingZipCode = "", string cvv = "", long clinicNum = -1) { ValidateProgram(clinicNum); if (string.IsNullOrWhiteSpace(ccNum) || ccExpDate.Year < DateTime.Today.Year) { throw new ODException(Lans.g("PaySimple", "Error making payment")); } long psCustomerId = AddCustomer("UNKNOWN", "UNKNOWN", "", clinicNum); ApiResponse apiResponse = AddCreditCard(psCustomerId, ccNum, ccExpDate, billingZipCode); string accountId = apiResponse.PaySimpleToken; return(PaySimpleApi.PostPayment(GetAuthHeader(clinicNum), PaySimpleApi.MakeNewPaymentData(PIn.Long(accountId), payAmt, cvv))); }
///<summary>Returns the Authorization header for the api call, using the passed in clinicNum if provided, otherwise uses the currently selected clinic.</summary> private static string GetAuthHeader(long clinicNum = -1) { if (clinicNum == -1) { clinicNum = Clinics.ClinicNum; } string apiUserName = ProgramProperties.GetPropValForClinicOrDefault(Programs.GetCur(ProgramName.PaySimple).ProgramNum , PropertyDescs.PaySimpleApiUserName , clinicNum); string apiKey = ProgramProperties.GetPropValForClinicOrDefault(Programs.GetCur(ProgramName.PaySimple).ProgramNum , PropertyDescs.PaySimpleApiKey , clinicNum); #if DEBUG //string apiUserName="******"; //string apiKey="QkQRj8i0QDPOtUBhbTWx7irBrqospeY8RDC4HxW2LD3IDIfo1bcumTMomp7IJbYONjIna84QPwMwfFLMTtZcMJ2Bm4meQIfojgsDrZr5HxAnQkylHJgF7t2XUDoVy6I0"; #endif return(PaySimpleApi.GetAuthHeader(apiUserName, apiKey)); }
///<summary>Throws exceptions. Will purposefully throw ODExceptions that are already translated and and formatted. ///If PatNum is 0, we will make a one time payment for an UNKNOWN patient. This is currently only intended for prepaid insurance cards. ///Returns the PaymentId given by PaySimple.</summary> public static ApiResponse MakePayment(long patNum, CreditCard cc, decimal payAmt, string ccNum, DateTime ccExpDate, bool isOneTimePayment, string billingZipCode = "", string cvv = "", long clinicNum = -1) { ValidateProgram(clinicNum); if (patNum == 0) { //MakePaymentNoPat will validate its credentials. return(MakePaymentNoPat(payAmt, ccNum, ccExpDate, billingZipCode, cvv, clinicNum)); } if ((cc == null || string.IsNullOrWhiteSpace(cc.PaySimpleToken)) && (string.IsNullOrWhiteSpace(ccNum) || ccExpDate.Year < DateTime.Today.Year)) { throw new ODException(Lans.g("PaySimple", "Error making payment")); } if (cc == null) { cc = new CreditCard() { PatNum = patNum, PaySimpleToken = "", }; } if (string.IsNullOrWhiteSpace(cc.PaySimpleToken)) { Patient patCur = Patients.GetPat(cc.PatNum); if (patCur == null) { patCur = new Patient() { PatNum = patNum, FName = "", LName = "", }; } long psCustomerId = GetCustomerIdForPat(patCur.PatNum, patCur.FName, patCur.LName, clinicNum); ApiResponse apiResponse = AddCreditCard(psCustomerId, ccNum, ccExpDate, billingZipCode, clinicNum); cc.PaySimpleToken = apiResponse.PaySimpleToken; if (!isOneTimePayment && cc.CreditCardNum > 0) //If the user doesn't want Open Dental to store their account id, we will let them continue entering their CC info. { CreditCards.Update(cc); } } return(PaySimpleApi.PostPayment(GetAuthHeader(clinicNum), PaySimpleApi.MakeNewPaymentData(PIn.Long(cc.PaySimpleToken), payAmt, cvv))); }
///<summary>Throws exceptions. Will purposefully throw ODExceptions that are already translated and formatted.</summary> public static long AddCustomer(string fname, string lname, string idInDb = "", long clinicNum = -1) { ValidateProgram(clinicNum); return(PaySimpleApi.PostCustomer(GetAuthHeader(clinicNum), PaySimpleApi.MakeNewCustomerData(fname, lname, idInDb))); }