예제 #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            decimal amount = 0M;
            Decimal.TryParse(txtAmount.Text, out amount);
            if (amount == 0) {
                return;
            }

            // create transaction

            // get settings from web.config
            string merchantId = WebConfigurationManager.AppSettings["MerchantID"];
            string merchantPassword = WebConfigurationManager.AppSettings["MerchantPassword"];
            string preSharedKey = WebConfigurationManager.AppSettings["PreSharedKey"];
            string serverCallBack = WebConfigurationManager.AppSettings["ServerCallBackUrl"];
            string callBackUrl = WebConfigurationManager.AppSettings["CallbackUrl"];
            string postUrl = "https://mms.cardsaveonlinepayments.com/Pages/PublicPages/PaymentForm.aspx";

            var request = new HostedTransactionRequest {
                Amount = Convert.ToInt32(amount * 100),
                OrderID = "123456",
                OrderDescription = "Test Order",
                TransactionType = TransactionType.SALE,
                CallbackURL = callBackUrl,
                ServerResultURL = serverCallBack
            };

            var processor = new HostedPaymentProcessor(merchantId, new HttpContextWrapper(HttpContext.Current));

            processor.SubmitTransaction(request, merchantPassword, preSharedKey, postUrl);
        }
예제 #2
0
        /// <summary>
        /// Submits a payment request to the hosted payment page
        /// </summary>
        /// <param name="request">The request to submit</param>
        /// <param name="merchantPassword">The merchant password that corresponds to the gateway account the transaction will be run through.</param>
        /// <param name="preSharedKey">The merchant gateway account pre shared key</param>
        /// <param name="postUrl">The url of the hosted payment page</param>
        public void SubmitTransaction(HostedTransactionRequest request, string merchantPassword, string preSharedKey, string postUrl)
        {
            if (CommonUtils.AreNullOrEmpty(merchantPassword, preSharedKey, postUrl))
            {
                throw new ArgumentNullException();
            }

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var hashInputs = new NameValueCollection();

            var hashMethod = HashMethod.SHA1;

            if (hashMethod == HashMethod.SHA1 || hashMethod == HashMethod.MD5)
            {
                // only add if using standard hash method (MD5 or SHA1)
                hashInputs.Add("PreSharedKey", preSharedKey);
            }

            hashInputs.Add("MerchantID", _merchantId);
            hashInputs.Add("Password", merchantPassword);

            var requestInputs = request.ToNameValueCollection();

            foreach (var k in requestInputs.AllKeys)
            {
                hashInputs.Add(k, requestInputs.GetValues(k)[0]);
            }

            var hashString = hashInputs.ToQueryString(encode: false);
            var hash       = HashUtil.ComputeHashDigest(hashString, preSharedKey, hashMethod);

            // ready to post - just return the NameValue Collection

            var remotePost = new RemotePost(_context, postUrl, FormMethod.POST);

            remotePost.AddInput("HashDigest", hash);
            remotePost.AddInput("MerchantID", _merchantId);

            // add the rest of the form variables
            foreach (var k in requestInputs.AllKeys)
            {
                remotePost.AddInput(k, requestInputs.GetValues(k)[0]);
            }

            remotePost.Post("CardsavePaymentForm");
        }
        /// <summary>
        /// Submits a payment request to the hosted payment page
        /// </summary>
        /// <param name="request">The request to submit</param>
        /// <param name="merchantPassword">The merchant password that corresponds to the gateway account the transaction will be run through.</param>
        /// <param name="preSharedKey">The merchant gateway account pre shared key</param>
        /// <param name="postUrl">The url of the hosted payment page</param>
        public void SubmitTransaction(HostedTransactionRequest request, string merchantPassword, string preSharedKey, string postUrl)
        {
            if (CommonUtils.AreNullOrEmpty(merchantPassword, preSharedKey, postUrl))
                throw new ArgumentNullException();

            if (request == null)
                throw new ArgumentNullException("request");

            var hashInputs = new NameValueCollection();

            var hashMethod = HashMethod.SHA1;

            if (hashMethod == HashMethod.SHA1 || hashMethod == HashMethod.MD5)
            {
                // only add if using standard hash method (MD5 or SHA1)
                hashInputs.Add("PreSharedKey", preSharedKey);
            }

            hashInputs.Add("MerchantID", _merchantId);
            hashInputs.Add("Password", merchantPassword);

            var requestInputs = request.ToNameValueCollection();
            foreach (var k in requestInputs.AllKeys)
                hashInputs.Add(k, requestInputs.GetValues(k)[0]);

            var hashString = hashInputs.ToQueryString(encode: false);
            var hash = HashUtil.ComputeHashDigest(hashString, preSharedKey, hashMethod);

            // ready to post - just return the NameValue Collection

            var remotePost = new RemotePost(_context, postUrl, FormMethod.POST);
            remotePost.AddInput("HashDigest", hash);
            remotePost.AddInput("MerchantID", _merchantId);

            // add the rest of the form variables
            foreach (var k in requestInputs.AllKeys)
                remotePost.AddInput(k, requestInputs.GetValues(k)[0]);

            remotePost.Post("CardsavePaymentForm");
        }