Ejemplo n.º 1
0
        public virtual Tuple <bool, string> refund(int transactionId)
        {
            if (transactionId < 0)
            {
                return(new Tuple <bool, string>(false, "Invalid TransactionId"));
            }


            Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod());
            if (mock)
            {
                if (work)
                {
                    if (PaymentSystemMock.CancelPayment(8, 8) > 0)
                    {
                        return(new Tuple <bool, string>(true, "Works"));
                    }
                    return(new Tuple <bool, string>(false, "not"));
                }
                if (PaymentSystemMock.CancelPayment(8, -1) > 0)
                {
                    return(new Tuple <bool, string>(false, "not"));
                }
                return(new Tuple <bool, string>(true, "Works"));
            }
            int cancel_res = PaymentSystem.CancelPayment(transactionId);

            if (cancel_res < 0)
            {
                return(new Tuple <bool, string>(false, "refund failed"));
            }

            return(new Tuple <bool, string>(true, "OK"));
        }
Ejemplo n.º 2
0
        public virtual int pay(string paymentDetails, bool Failed = false)
        {
            if (paymentDetails is null)
            {
                return(-1);
            }
            if (mock && !work)
            {
                return(-1);
            }
            if (!PaymentSystem.IsAlive(Failed))
            {
                return(-1);
            }

            string[] parsedDetails = paymentDetails.Split('&');
            if (parsedDetails.Length < 6)
            {
                return(-1);
            }
            try
            {
                string cardNum = parsedDetails[0];
                if (cardNum.Length == 0)
                {
                    return(-1);
                }
                int month = parsedDetails[1].ToInt32();
                if (month < 1 || month > 12)
                {
                    return(-1);
                }
                int    year = parsedDetails[2].ToInt32();
                string name = parsedDetails[3];
                if (name.Length == 0)
                {
                    return(-1);
                }
                string cvv = parsedDetails[4];
                if (cvv.Length == 0)
                {
                    return(-1);
                }
                string sid = parsedDetails[5];
                if (sid.Length == 0)
                {
                    return(-1);
                }
                if (mock)
                {
                    if (work)
                    {
                        return(PaymentSystemMock.Pay(cardNum, month, year, name, cvv, sid, 8));
                    }
                    return(PaymentSystemMock.Pay(cardNum, month, year, name, cvv, sid, -1));
                }
                int transaction_num = PaymentSystem.Pay(cardNum, month, year, name, cvv, sid);
                if (transaction_num < 0)
                {
                    return(-1);
                }

                Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod());
                return(transaction_num);
            }
            catch (Exception ex)
            {
                Logger.logError("ParseFailed" + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod());
                return(-1);
            }
        }
Ejemplo n.º 3
0
 public void PaymentSystemHandshaketest()
 {
     Assert.IsTrue(PaymentSystemMock.IsAlive(true));
     Assert.IsFalse(PaymentSystemMock.IsAlive(false));
 }