コード例 #1
0
        private static Tuple<string, string> PostRequest(PaymentForm form)
        {
            CreateOrderBuilder order = WebpayConnection.CreateOrder(SveaConfig.GetDefaultConfig());

            form.SetMacSha512(
                HashUtil.CreateHash(form.GetXmlMessageBase64() +
                                    order.GetConfig().GetSecretWord(PaymentType.HOSTED, order.GetCountryCode())));

            string data = "mac=" + HttpUtility.UrlEncode(form.GetMacSha512()) +
                          "&message=" + HttpUtility.UrlEncode(form.GetXmlMessageBase64()) +
                          "&merchantid=" + HttpUtility.UrlEncode(form.GetMerchantId());
            byte[] formData = Encoding.UTF8.GetBytes(data);

            var request = WebRequest.Create(order.GetConfig().GetEndPoint(PaymentType.HOSTED)) as HttpWebRequest;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = formData.Length;

            using (Stream post = request.GetRequestStream())
            {
                post.Write(formData, 0, formData.Length);
            }

            string result;
            string statusCode;
            using (var response = request.GetResponse() as HttpWebResponse)
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    result = reader.ReadToEnd();
                }

                statusCode = response.StatusCode.ToString();
            }

            return new Tuple<string, string>(statusCode, result);
        }
コード例 #2
0
        /// <summary>
        /// GetPaymentForm
        /// </summary>
        /// <returns>PaymentForm</returns>
        public PaymentForm GetPaymentForm()
        {
            CalculateRequestValues();
            var xmlBuilder = new HostedXmlBuilder();
            string xml = xmlBuilder.GetXml(this);

            var form = new PaymentForm();
            form.SetXmlMessage(xml);

            form.SetMerchantId(CrOrderBuilder.GetConfig()
                                             .GetMerchantId(PaymentType.HOSTED, CrOrderBuilder.GetCountryCode()));
            form.SetSecretWord(CrOrderBuilder.GetConfig().GetSecretWord(PaymentType.HOSTED, CrOrderBuilder.GetCountryCode()));

            form.SetSubmitMessage(CrOrderBuilder.GetCountryCode() != CountryCode.NONE
                                      ? CrOrderBuilder.GetCountryCode()
                                      : CountryCode.SE);

            form.SetPayPageUrl(CrOrderBuilder.GetConfig().GetEndPoint(PaymentType.HOSTED));

            form.SetForm();
            form.SetHtmlFields();

            return form;
        }