Payment Express Pxpay With Httpclient And Linq To Xml
Payment Express is one of the most popular payment gateways based in New Zealand. PxPay provides handy APIs for Auth, Purchase, and Token Billing. All APIs use XML format for data exchange. This article shows you how I use HttpClient and LINQ to XML to consume those APIs.
Payment Express PxPay
PxPay is currently at version 2.0. You can check out its Integration Guide from this link. It also provides sample C# code. You can even customize their hosted payment page with your own CSS from their admin site.
Web.config
SendRequest
We use SendRequest to interact with Payment Express Web Services. XElement is used to parse and generate xml string.
GenerateRequest
We use GenerateRequest to get the URL of DPS hosted payment page. Auth, Purchase, and Token Billing all use this method.
Handy Wrappers
I write some wrappers around GenerateRequest so that I won’t be annoyed by many parameters which might not be related with the transaction type I’m about to use. For example, if you need to issue a Purchase request, you can call Purchase method with your txnId and amountInput, or Auth with Auth method etc.
ProcessResponse
After payment is made, customers will be redirected to your SuccessUrl or FailUrl with a response code. You can get transaction details with the code via ProcessResponse. We use XmlSerializer to deserialize xml result to a Response object. Instead of traversing an XML for the info, checking against an Response object is much more handy.