示例#1
0
 ///<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)));
 }
示例#2
0
        ///<summary>Only deletes the credit card from Open Dental.  We currently do not delete PayConnect tokens from PayConnect anywhere like we do with XCharge/XWeb/PaySimple.
        ///Throws exceptions.</summary>
        public static void DeleteCreditCard(Patient pat, CreditCard cc)
        {
            if (pat == null)
            {
                throw new ODException("No Patient Found", ODException.ErrorCodes.NoPatientFound);
            }
            if (cc == null)
            {
                throw new ODException("No Credit Card Found", ODException.ErrorCodes.OtkArgsInvalid);
            }
            if (string.IsNullOrEmpty(cc.PayConnectToken))
            {
                throw new ODException("Invalid CC Alias", ODException.ErrorCodes.OtkArgsInvalid);
            }
            CreditCards.Delete(cc.CreditCardNum);
            List <CreditCard> creditCards = CreditCards.Refresh(pat.PatNum);

            for (int i = 0; i < creditCards.Count; i++)
            {
                creditCards[i].ItemOrder = creditCards.Count - (i + 1);
                CreditCards.Update(creditCards[i]);                //Resets ItemOrder.
            }
        }