Exemplo n.º 1
0
 /// <summary>
 /// necessary initializations for smoothness and such
 /// </summary>
 private void Initialize()
 {
     UpdateConversions = new ButtonCommand(ConvertAll, () => _convertAmount > 0); //only invoke if amount is positive
     SelectedCurrency  = new CurrencyFields {                                     //default
         Code  = "USD",
         Value = 1
     };
 }
Exemplo 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));
        }
Exemplo 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);
        }
Exemplo 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));
        }
Exemplo n.º 5
0
 private IDictionary <string, string> CreateQueryParameters(decimal purchaseAmount, CurrencyFields currencyCode, string orderId)
 {
     //create query parameters
     return(new Dictionary <string, string>
     {
         ["Version"] = Version,
         ["MerID"] = _jccSettings.MerchantId,
         ["AcqID"] = _jccSettings.AcquirerId,
         ["MerRespURL"] = _jccSettings.ResponseURL,
         ["PurchaseAmt"] = ProcessPruchaseAmount(purchaseAmount),
         ["PurchaseCurrency"] = ((int)currencyCode).ToString(),
         ["PurchaseCurrencyExponent"] = CurrencyExp.ToString(),
         ["OrderID"] = orderId,
         ["CaptureFlag"] = CaptureFlag,
         ["Signature"] = CalculateRequestSignature(purchaseAmount, currencyCode, orderId),
         ["SignatureMethod"] = SignatureMethod
     });
 }