Пример #1
0
        /**
         *  Factory
         *  @param mpp payment processor model
         *  @param mp payment model
         *  @return initialized PaymentProcessor or null
         */
        public static PaymentProcessor Create(MPaymentProcessor mpp, MPayment mp)
        {
            _log.Info("create for " + mpp);
            String className = mpp.GetPayProcessorClass();

            if (className == null || className.Length == 0)
            {
                _log.Log(Level.SEVERE, "No PaymentProcessor class name in " + mpp);
                return(null);
            }
            //
            PaymentProcessor myProcessor = null;

            try
            {
                //Class ppClass = Class.forName(className);
                //if (ppClass != null)
                //    myProcessor = (PaymentProcessor)ppClass.newInstance();

                Type ppClass = Type.GetType(className);
                if (ppClass != null)
                {
                    myProcessor = (PaymentProcessor)Activator.CreateInstance(ppClass);
                }
            }
            //catch (Error e1)    //  NoClassDefFound
            //{
            //    _log.Log(Level.SEVERE, className + " - Error=" + e1.Message);
            //    return null;
            //}
            catch (Exception e2)
            {
                _log.Log(Level.SEVERE, className, e2);
                return(null);
            }
            if (myProcessor == null)
            {
                _log.Log(Level.SEVERE, "no class");
                return(null);
            }

            //  Initialize
            myProcessor._mpp = mpp;
            myProcessor._mp  = mp;
            //
            return(myProcessor);
        }
Пример #2
0
        /// <summary>
        /// Get BankAccount & PaymentProcessor
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="tender">optional Tender see TENDER_</param>
        /// <param name="CCType">optional CC Type see CC_</param>
        /// <param name="AD_Client_ID">client</param>
        /// <param name="C_Currency_ID">Currency (ignored)</param>
        /// <param name="amt">Amount (ignored)</param>
        /// <param name="trxName">transaction</param>
        /// <returns>Array of BankAccount[0] & PaymentProcessor[1] or null</returns>
        public static MPaymentProcessor[] Find(Ctx ctx, String tender, String CCType,
                                               int AD_Client_ID, int C_Currency_ID, Decimal amt, Trx trxName)
        {
            List <MPaymentProcessor> list = new List <MPaymentProcessor>();
            StringBuilder            sql  = new StringBuilder("SELECT * "
                                                              + "FROM C_PaymentProcessor "
                                                              + "WHERE AD_Client_ID=@clid AND IsActive='Y'"                            //	#1
                                                              + " AND (C_Currency_ID IS NULL OR C_Currency_ID=@curid)"                 //	#2
                                                              + " AND (MinimumAmt IS NULL OR MinimumAmt = 0 OR MinimumAmt <= @amot)"); //	#3

            if (MPayment.TENDERTYPE_DirectDeposit.Equals(tender))
            {
                sql.Append(" AND AcceptDirectDeposit='Y'");
            }
            else if (MPayment.TENDERTYPE_DirectDebit.Equals(tender))
            {
                sql.Append(" AND AcceptDirectDebit='Y'");
            }
            else if (MPayment.TENDERTYPE_Check.Equals(tender))
            {
                sql.Append(" AND AcceptCheck='Y'");
            }
            //  CreditCards
            else if (MPayment.CREDITCARDTYPE_ATM.Equals(CCType))
            {
                sql.Append(" AND AcceptATM='Y'");
            }
            else if (MPayment.CREDITCARDTYPE_Amex.Equals(CCType))
            {
                sql.Append(" AND AcceptAMEX='Y'");
            }
            else if (MPayment.CREDITCARDTYPE_Visa.Equals(CCType))
            {
                sql.Append(" AND AcceptVISA='Y'");
            }
            else if (MPayment.CREDITCARDTYPE_MasterCard.Equals(CCType))
            {
                sql.Append(" AND AcceptMC='Y'");
            }
            else if (MPayment.CREDITCARDTYPE_Diners.Equals(CCType))
            {
                sql.Append(" AND AcceptDiners='Y'");
            }
            else if (MPayment.CREDITCARDTYPE_Discover.Equals(CCType))
            {
                sql.Append(" AND AcceptDiscover='Y'");
            }
            else if (MPayment.CREDITCARDTYPE_PurchaseCard.Equals(CCType))
            {
                sql.Append(" AND AcceptCORPORATE='Y'");
            }
            //
            try
            {
                SqlParameter[] param = new SqlParameter[3];
                param[0] = new SqlParameter("@clid", AD_Client_ID);
                param[1] = new SqlParameter("@curid", C_Currency_ID);
                param[2] = new SqlParameter("@amot", amt);
                DataSet ds = DataBase.DB.ExecuteDataset(sql.ToString(), param);
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        list.Add(new MPaymentProcessor(ctx, dr, trxName));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "find - " + sql, e);
                return(null);
            }
            //
            if (list.Count == 0)
            {
                _log.Warning("find - not found - AD_Client_ID=" + AD_Client_ID
                             + ", C_Currency_ID=" + C_Currency_ID + ", Amt=" + amt);
            }
            else
            {
                _log.Fine("find - #" + list.Count + " - AD_Client_ID=" + AD_Client_ID
                          + ", C_Currency_ID=" + C_Currency_ID + ", Amt=" + amt);
            }
            MPaymentProcessor[] retValue = new MPaymentProcessor[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }