Domanda

I'm trying to post some data to a payment service and render the response back through and HttpHandler. The response is a form the user fill out to make their payment. It's a web forms app, so I can't use multiple forms (I know you can in general, but the existing code I'm working on is making it hard. I just have a link to the handler with a order id in the querystring.

I'm not even sure that what I'm trying to do here is a good idea or will even work out. If you have a better idea please let me know. Here is the code I have so far:

using System.Net;
using System.Text;
using System.Web;

namespace Web
{
    public class Begin_invoice : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var orderNumber = context.Request.QueryString["invoice-numer"];

            //todo: get some extra data from local service here

            var URI = "https://somepaymetservice/start.action";

            var data = new StringBuilder();

            data.Append("merchant=" + HttpUtility.UrlEncode("666111") + "&");
            data.Append("amount=" + HttpUtility.UrlEncode("1") + "&");
            data.Append("lang=" + HttpUtility.UrlEncode("sv") + "&");
            data.Append("currency=" + HttpUtility.UrlEncode("752") + "&");
            data.Append("orderid=" + HttpUtility.UrlEncode(orderNumber) + "&");
            data.Append("accepturl=" + HttpUtility.UrlEncode("http://localhost:50113/Complete-invoice.ashx") + "&");
            data.Append("test=" + HttpUtility.UrlEncode("1") + "&");

            using (var client = new WebClient())
            {
                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                var response = client.UploadString(URI, data.ToString());

                context.Response.Write(response);
            }
        }

        public bool IsReusable
        {
            get { return false; }
        }
    }
}

The obvious first problem is all the resources for the payment page. Urls to resources are relative so they won't get downloaded. Is there some library or other feature that can take care of this proxy stuff, can I use some location header or something like that? All suggestions are appreciated?

È stato utile?

Soluzione

In the end I was forced to refactor my markup to allow multiple forms on a page. Once that was done the DIBS api was really easy to use.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top