Esempio n. 1
0
        public TransactionResponse ProcessRespond(JccResponse jccResponse)
        {
            TransactionResponse transactionResponse = new TransactionResponse();

            try
            {
                string toEncrypt = $"{_jccSettings.Password}{_jccSettings.MerchantId}{_jccSettings.AcquirerId}{jccResponse.OrderId}{jccResponse.ResponseCode}{jccResponse.ReasonCode}";
                string hash      = JccHelper.CalculateSHA1Hash(toEncrypt);
                if (hash.Equals(jccResponse.Signature))
                {
                    if (jccResponse.ResponseCode.Trim().Equals("1"))
                    {
                        transactionResponse.Status = StatusCodedFiled.Success;
                    }
                    else
                    {
                        transactionResponse.Status  = StatusCodedFiled.Declined;
                        transactionResponse.Message = jccResponse.ReasonCodeDesc;
                    }
                }
                else
                {
                    transactionResponse.Status  = StatusCodedFiled.NotVerified;
                    transactionResponse.Message = "Transaction was not verified";
                }
            }
            catch (Exception ex)
            {
                transactionResponse.Status  = StatusCodedFiled.Error;
                transactionResponse.Message = ex.Message;
            }

            return(transactionResponse);
        }
Esempio n. 2
0
        public bool ProcessPayment(decimal purchaseAmount, CurrencyFields currencyCode, string orderId)
        {
            JccHelper.CheckOrderID(orderId);
            var roundedOrderTotal = Math.Round(purchaseAmount, CurrencyExp);

            JccHelper.CheckPurchaseAmt(roundedOrderTotal, CurrencyExp);

            return(PostData(purchaseAmount, currencyCode, orderId));
        }
Esempio n. 3
0
        private bool PostData(decimal purchaseAmount, CurrencyFields currencyCode, string orderId)
        {
            // encode form data
            StringBuilder postString = new StringBuilder();
            bool          first      = true;

            foreach (KeyValuePair <string, string> pair in CreateQueryParameters(purchaseAmount, currencyCode, orderId))
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    postString.Append("&");
                }
                postString.AppendFormat("{0}={1}", pair.Key, System.Web.HttpUtility.UrlEncode(pair.Value));
            }
            ASCIIEncoding ascii = new ASCIIEncoding();

            byte[] postBytes = ascii.GetBytes(postString.ToString());

            // set up request object
            HttpWebRequest request;

            try
            {
                request = WebRequest.Create(JccHelper.GetJccURL(_jccSettings.IsTestMode)) as HttpWebRequest;
            }
            catch (UriFormatException)
            {
                request = null;
            }
            if (request == null)
            {
                throw new ApplicationException("Invalid URL: " + JccHelper.GetJccURL(_jccSettings.IsTestMode));
            }
            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = postBytes.Length;

            // add post data to request
            System.IO.Stream postStream = request.GetRequestStream();
            postStream.Write(postBytes, 0, postBytes.Length);
            postStream.Close();

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            if (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        protected string CalculateRequestSignature(decimal purchaseAmount, CurrencyFields currencyCode, string orderId)
        {
            var roundedOrderTotal = Math.Round(purchaseAmount, CurrencyExp);

            string value =
                _jccSettings.Password +
                _jccSettings.MerchantId +
                _jccSettings.AcquirerId +
                orderId +
                JccHelper.GetPaddedAmount(roundedOrderTotal) +
                (int)currencyCode;

            return(JccHelper.CalculateSHA1Hash(value));
        }