Пример #1
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");
        }
Пример #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 MD5secretKey)
        {
            if (CommonUtils.AreNullOrEmpty(MD5secretKey))
            {
                throw new ArgumentNullException();
            }

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

            var requestInputs = request.ToNameValueCollection();
            var postUrl       = "";

            if (request.testMode == 100)
            {
                postUrl = "https://secure-test.worldpay.com/wcc/purchase";
            }
            else
            {
                postUrl = "https://secure.worldpay.com/wcc/purchase";
            }

            // ready to post - just return the NameValue Collection
            var remotePost = new RemotePost(_context, postUrl, FormMethod.POST);

            var callbackhashInputs = new StringBuilder();

            callbackhashInputs.Append(MD5secretKey);
            callbackhashInputs.Append(":");
            callbackhashInputs.Append(request.currency);
            callbackhashInputs.Append(":");
            callbackhashInputs.Append(request.amount.ToString("#0.00"));
            callbackhashInputs.Append(":");
            callbackhashInputs.Append(request.testMode);
            callbackhashInputs.Append(":");
            callbackhashInputs.Append(request.instId);

            var signaturehashInputs = new StringBuilder();

            signaturehashInputs.Append(MD5secretKey);
            signaturehashInputs.Append(":");
            signaturehashInputs.Append(request.currency);
            signaturehashInputs.Append(":");
            signaturehashInputs.Append(request.amount);
            signaturehashInputs.Append(":");
            signaturehashInputs.Append(request.testMode);
            signaturehashInputs.Append(":");
            signaturehashInputs.Append(request.instId);

            byte[] callbackhashDigest = new MD5CryptoServiceProvider().ComputeHash(StringToByteArray(callbackhashInputs.ToString()));

            byte[] signaturehashDigest = new MD5CryptoServiceProvider().ComputeHash(StringToByteArray(signaturehashInputs.ToString()));

            remotePost.AddInput("signature", ByteArrayToHexString(signaturehashDigest));
            remotePost.AddInput("MC_callbacksignature", ByteArrayToHexString(callbackhashDigest));

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

            remotePost.Post("CardsavePaymentForm");
        }