Microsoft Dynamics CRM 4.0 and Direct Payment Systems – PX Post

Roshan Mehta, 21 October 2010

In my previous post, I showed you how Microsoft Dynamics CRM 4.0 can be integrated with PX Pay – a credit card transaction processing service provided by Direct Payment Systems. In this blog, I will describe how you can use an alternative method to handle your online purchasing needs.

PX Post is designed to handle online credit card transactions using a HTTPS Post request, but unlike PX Pay, it does not require the use of a third party web form hosted by DPS. The benefit of this approach is that all credit card details can be entered on a custom web form that you create, eliminating the need for users to enter details on multiple web forms.

Microsoft Dynamics CRM 4.0 and Direct Payment Systems – PX Post 

I have created a custom ASPX page which will be hosted inside CRM. Firstly, we need to create the connection between our custom page and DPS. Visit the Payment Express website to learn more about setting up an account and creating a connection between custom applications and the DPS service.

Next, we create  StringWriter and XmlTextWriter objects in order to start building the request that will be sent to DPS. For information on the different attributes which can be sent as part of the request, visit http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html

            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);

            xtw.WriteStartElement("Txn");
            xtw.WriteElementString("PostUsername", "MyUserName");
            xtw.WriteElementString("PostPassword", "MyPassword");
            xtw.WriteElementString("CardHolderName", "Mr J. Bloggs");
            xtw.WriteElementString("CardNumber", "1234567890123456");
            xtw.WriteElementString("Amount", "200.00");
            xtw.WriteElementString("DateExpiry", "1011");
            xtw.WriteElementString("Cvc2", "");
            xtw.WriteElementString("InputCurrency", "NZD");
            xtw.WriteElementString("TxnType", "Purchase");
            xtw.WriteElementString("TxnId", "");
            xtw.WriteElementString("MerchantReference", "MyReferenceNumber");
            xtw.WriteEndElement();
            xtw.Close();

We are now ready to send the XML request to PX Post.

            //send the xml message to pxpost
            WebRequest request = WebRequest.Create(uri);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

Once this is done, we can check the response message for any errors.

WebResponse wrs = request.GetResponse();

If the response is successful, we can use the Microsoft Dynamics CRM 4.0 SDK to store the transaction data inside CRM.

DPS makes it easy to build applications to interact with their services. They provide test accounts for developers as well as test credit card numbers which you can use for debugging (and it won’t cost you a fortune testing with a real credit card!).