Developer forum

Forum » Development » Remote Capture with Quickpay

Remote Capture with Quickpay


Reply
Anyone who have made a remote capture with Quickpay

Replies

 
Nicolai Høeg Pedersen
Reply
If you are using Cartv2 and the quickpay checkout handler it supports remote capture from the orderlist.

Here's our implementation - let me know if you want the entire code from the gateway handler.

//Create HTTP POST request to QuickPay API.
                var request = WebRequest.Create("https://secure.quickpay.dk/api");


                //Create byte array with POST data
                var httpContent =
                    Encoding.UTF8.GetBytes(
                        string.Format("protocol={0}&msgtype={1}&merchant={2}&amount={3}&transaction={4}&md5check={5}",
                                      Protocol, CaptureMsgType, Merchant, order.Price.PricePIP, order.TransactionNumber,
                                      CaptureMD5(order)));


                //Set headers
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = httpContent.Length;


                // Get response from QuickPay
                string responseText;
                try
                {
                    //Get output stream and write content values
                    using (var stream = request.GetRequestStream())
                        stream.Write(httpContent, 0, httpContent.Length);


                    //Get response from QuickPay
                    var response = (HttpWebResponse)request.GetResponse();
                    LogEvent(order, "Remote capture response: HttpStatusCode = {0}, HttpStatusDescription = {1}",
                             response.StatusCode, response.StatusDescription);


                    //Read entire response
                    var reader = new StreamReader(response.GetResponseStream());
                    responseText = reader.ReadToEnd();
                    LogEvent(order, "Remote capture ResponseText: {0}", responseText);
                }
                catch (Exception ex)
                {
                    LogError(order, "Unable to make http request to QuickPay: {0}", ex.Message);
                    return new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed, "Unable to make http request to QuickPay");
                }


                //Parse response
                var xml = new XmlDocument();
                xml.LoadXml(responseText);


                // Get root node 'response'
                var root = xml["response"];
                if (root == null)
                {
                    LogError(order, "Unable to read reaspone from QuickPay capture");
                    return new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed,
                                                "Unable to read reaspone from QuickPay capture");
                }


                // Get all parameters
                var quickPayResponse =
                    new List<string>
                        {
                            "msgtype",
                            "ordernumber",
                            "amount",
                            "currency",
                            "time",
                            "state",
                            "qpstat",
                            "qpstatmsg",
                            "chstat",
                            "chstatmsg",
                            "merchant",
                            "merchantemail",
                            "transaction",
                            "cardtype",
                            "cardnumber",
                            "md5check"
                        }.ToDictionary(x => x, x => root[x] == null ? null : root[x].InnerText);


                // Check that all values are send
                foreach (var key in quickPayResponse.Where(x => x.Value == null).Select(x => x.Key))
                {
                    LogError(order, "The expected parameter from QuickPay '{0}' was not send", key);
                    return new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed,
                                                "The expected parameter from QuickPay '{0}' was not send");
                }


                // Check msgtype
                if (quickPayResponse["msgtype"] != CaptureMsgType)
                {
                    LogError(order, "Response expected: 'capture'. Response recieved: '{0}'.",
                             quickPayResponse["msgtype"]);
                    return new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed, "Wrong msgtype recieved");
                }


                // Check MD5
                var calculatedMD5 =
                    Base.MD5HashToString(
                        string.Join("", quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) +
                        SecretKey);
                if (!calculatedMD5.Equals(quickPayResponse["md5check"], StringComparison.CurrentCultureIgnoreCase))
                {
                    LogError(order,
                             "The MD5 checksum returned from callback does not match: Callback: {0}, calculated: {1}",
                             quickPayResponse["md5check"], calculatedMD5);
                    return new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed,
                                                "The MD5 ch  ecksum returned from callback does not match");
                }


                // Check state and qpstat
                if (quickPayResponse["state"] != "3" || quickPayResponse["qpstat"] != "000")
                {
                    LogError(order, "Incorrect state and state code received from QuickPay: state: {0}, qpstat: {1}",
                             quickPayResponse["state"], quickPayResponse["qpstat"]);
                    return new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Failed,
                                                "Incorrect state and state code received from QuickPay");
                }


                // All good
                LogEvent(order, "Capture successfull");
                return new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Success, "Capture successfull");

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
I can just add that both Quickpay 3 (Payment gateway--CartV1, and Checkout handler--CartV2) support this out of the box. You just need to set your Quickpay account up to allow capture from the IP address of the caller--in this case your site. If you're hosted at HostNordic then the external IP of your site would most likely be the IP of HostNordic's firewall.

- Jeppe

EDIT: If you want to know more about Remote Capture: http://engage.dynamicweb-cms.com/Admin/Public/Download.aspx?File=Files%2fFiler%2fDocumentation%2fDevelopment%2feCommerce%2f(en-US)+Remote+capture%2c+Dynamicweb+eCommerce.pdf
 
Reply
Thanks for the great answer's it was a big help. If I want to know more about the "out of the box" possiblities then is there a documentation for that and where?
 
Jacob Jensen
Reply
Hi, I've got a shop up and running. This shop has chosen not to have any payment fees on any of their payment methods. So I've just made one payment option called "All available cards" and hidden this in the frontend form. The customers will then choose a payment method when they reach to Quickpay.
Here's the problem: When a payment is successful, the data retrieved back into Dynamicweb eCommerce is missing the cardtype data. This is annoying for my client who has to deal with the captures. When they can't see which card have been used they can't do the correct bookkeeping without having to log-in to the Quickpay manager. So I would like the Payment Method column in the orders list view, to reflect the response from Quickpay. I can see that they have a response field called "cardtype" which to my best knowledge should reflect the card type chosen...
http://doc.quickpay.dk/api/specificationsandfeatures.html#index3h2

 

You must be logged in to post in the forum