예제 #1
0
        ///<summary>Creates and returns the HPF URL and validation OTK which can be used to make a payment for an unspecified credit card.  Throws exceptions.</summary>
        public static string GetHpfUrlForPayment(Patient pat, string accountToken, string payNote, bool isMobile, double amount, bool saveToken, CreditCardSource ccSource)
        {
            if (pat == null)
            {
                throw new ODException("No Patient Found", ODException.ErrorCodes.NoPatientFound);
            }
            if (string.IsNullOrWhiteSpace(accountToken))
            {
                throw new ODException("Invalid Account Token", ODException.ErrorCodes.OtkArgsInvalid);
            }
            if (amount < 0.00 || amount > 99999.99)
            {
                throw new ODException("Invalid Amount", ODException.ErrorCodes.OtkArgsInvalid);
            }
            if (string.IsNullOrEmpty(payNote))
            {
                throw new ODException("Invalid PayNote", ODException.ErrorCodes.OtkArgsInvalid);
            }
            PayConnectResponseWeb responseWeb = new PayConnectResponseWeb()
            {
                Amount           = amount,
                AccountToken     = accountToken,
                PatNum           = pat.PatNum,
                ProcessingStatus = PayConnectWebStatus.Created,
                PayNote          = payNote,
                CCSource         = ccSource,
                IsTokenSaved     = saveToken,
            };

            PayConnectResponseWebs.Insert(responseWeb);
            try {
                string url;
                PayConnectREST.PostPaymentRequest(responseWeb, out url);
                PayConnectResponseWebs.Update(responseWeb);
                WakeupWebPaymentsMonitor?.Invoke(url, new EventArgs());
                return(url);
            }
            catch (Exception e) {
                PayConnectResponseWebs.HandleResponseError(responseWeb, "Error calling PostPaymentRequest: " + e.Message);
                PayConnectResponseWebs.Update(responseWeb);
                throw;
            }
        }
예제 #2
0
 ///<summary>Make a payment using HPF directly.  Throws exceptions.</summary>
 public static void MakePaymentWithAlias(Patient pat, string payNote, double amount, CreditCard cc)
 {
     if (pat == null)
     {
         throw new ODException("No Patient Found", ODException.ErrorCodes.NoPatientFound);
     }
     if (amount < 0.00 || amount > 99999.99)
     {
         throw new ODException("Invalid Amount", ODException.ErrorCodes.OtkArgsInvalid);
     }
     if (string.IsNullOrEmpty(payNote))
     {
         throw new ODException("Invalid PayNote", ODException.ErrorCodes.OtkArgsInvalid);
     }
     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);
     }
     //request a PayConnect token, if a token was already saved PayConnect will return the same token,
     //otherwise replace CCNumberMasked with the returned token if the sale successful
     PayConnectService.creditCardRequest payConnectRequest = PayConnect.BuildSaleRequest(
         (decimal)amount, cc.PayConnectToken, cc.CCExpiration.Year, cc.CCExpiration.Month,
         pat.GetNameFLnoPref(), "", cc.Zip, null,
         PayConnectService.transType.SALE, "", true);
     //clinicNumCur could be 0, and the practice level or 'Headquarters' PayConnect credentials would be used for this charge
     PayConnectService.transResponse payConnectResponse = PayConnect.ProcessCreditCard(payConnectRequest, pat.ClinicNum,
                                                                                       x => throw new ODException(x));
     if (payConnectRequest != null && payConnectResponse.Status.code == 0)         //Success
     {
         string receipt = BuildReceiptString(payConnectRequest.TransType, payConnectResponse.RefNumber, payConnectRequest.NameOnCard, payConnectRequest.CardNumber,
                                             payConnectRequest.MagData, payConnectResponse.AuthCode, payConnectResponse.Status.description, payConnectResponse.Messages.ToList(), payConnectRequest.Amount,
                                             0, pat.ClinicNum);
         DateTime dateTimeProcessed = DateTime.Now;
         string   formattedNote     = Lans.g("PayConnect", "Amount:") + " " + amount.ToString("f") + "\r\n"
                                      + Lans.g("PayConnect", "Card Number:") + " " + cc.CCNumberMasked + "\r\n"
                                      + Lans.g("PayConnect", "Transaction ID:") + " " + payConnectRequest.RefNumber + "\r\n"
                                      + Lans.g("PayConnect", "Processed:") + " " + dateTimeProcessed.ToShortDateString() + " " + dateTimeProcessed.ToShortTimeString() + "\r\n"
                                      + Lans.g("PayConnect", "Note:") + " " + payNote;
         long payNum = Payments.InsertFromPayConnect(pat.PatNum, pat.PriProv, pat.ClinicNum, amount, formattedNote, receipt, CreditCardSource.PayConnectPortal);
         PayConnectResponseWeb responseWeb = new PayConnectResponseWeb()
         {
             Amount            = amount,
             PatNum            = pat.PatNum,
             ProcessingStatus  = PayConnectWebStatus.Completed,
             PayNote           = payNote,
             CCSource          = cc.CCSource,
             IsTokenSaved      = true,
             PayNum            = payNum,
             DateTimeCompleted = MiscData.GetNowDateTime(),
             RefNumber         = payConnectResponse.RefNumber,
             TransType         = PayConnectService.transType.SALE,
             PaymentToken      = cc.PayConnectToken,
         };
         //Insert a new payconnectresponse row for historical record in the transaction window.
         PayConnectResponseWebs.Insert(responseWeb);
     }
     else              //Failed
     {
         throw new ODException("Unable to process payment for this credit card: " + (payConnectResponse == null ? "Unknown error" : payConnectResponse.Status.description));
     }
 }