Payment Module for EPIServer Commerce using credit card method
Vote:
Hi I have been trying to create payment module for EPIServer Commerce for DPS (Payment Express). I have been following other's example on creating module. I have been getting "Failed to process payment." after clicking next on payment page from the shopping cart. I am usinig EPIServer Commerce SP1. Product Version: 5.2 (build: 628)
I am using Wine Sample shopping template. I have included a bit code that i think is failing me.
I have hardcoded the values for purpose of testing. Any advice on this would be great.
public class PxPost : AbstractPaymentGateway
{
public static readonly string UserNameParameter = "";
public static readonly string PasswordParameter = "";
public static readonly string URL = "https://sec.paymetexpress.com/pxpost.aspx";
public static readonly string TransactionType = "Purchase";
public static readonly string Currency = "NZD";
public override bool ProcessPayment(Payment payment, ref string message)
{
string PxPostUserName;
string PxPostPassword;
string PxPostURL;
string TxnType;
string Curr;
if (!Settings.ContainsKey(UserNameParameter) ||
!Settings.ContainsKey(PasswordParameter) ||
!Settings.ContainsKey(URL) ||
!Settings.ContainsKey(TransactionType)||
!Settings.ContainsKey(Currency))
{
throw new Exception("PxPost is not configured yet");
}
PxPostUserName = Settings[UserNameParameter].ToString();
PxPostPassword = Settings[PasswordParameter].ToString();
PxPostURL = Settings[URL].ToString();
TxnType = Settings[TransactionType].ToString();
Curr = Settings[Currency].ToString();
CreditCardPayment info =(CreditCardPayment) payment;
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.WriteStartElement("Txn");
xtw.WriteElementString("PostUsername", PxPostUserName);
xtw.WriteElementString("PostPassword", PxPostPassword);
xtw.WriteElementString("CardHolderName", info.CustomerName);
xtw.WriteElementString("CardNumber", info.CreditCardNumber);
xtw.WriteElementString("Amount", info.Amount.ToString("#.##"));
xtw.WriteElementString("DateExpiry", info.ExpirationMonth < 10 ? "0" + info.ExpirationMonth.ToString() + info.ExpirationYear.ToString() : info.ExpirationMonth.ToString()+ info.ExpirationYear.ToString());
xtw.WriteElementString("Cvc2", info.CreditCardSecurityCode);
xtw.WriteElementString("InputCurrency", Curr);
xtw.WriteElementString("TxnType", TxnType);
// xtw.WriteElementString("TxnId", "");
// xtw.WriteElementString("MerchantReference", txtMerchantRef.Text);
// xtw.WriteElementString("TxnData1", txtTxnData1.Text);
// xtw.WriteElementString("TxnData2", txtTxnData2.Text);
// xtw.WriteElementString("TxnData3", txtTxnData3.Text);
xtw.WriteEndElement();
xtw.Close();
// File.WriteAllText(path, sw.ToString(), Encoding.UTF8);
//Send the Xml message to PXPost
WebRequest wrq = WebRequest.Create(PxPostURL);
wrq.Method = "POST";
wrq.ContentType = "application/x-www-form-urlencoded";
byte[] b = Encoding.ASCII.GetBytes(sw.ToString());
wrq.ContentLength = b.Length;
Stream s = wrq.GetRequestStream();
s.Write(b, 0, b.Length);
s.Close();
WebResponse wrs = wrq.GetResponse();
if (wrs != null)
{
StreamReader sr = new StreamReader(wrs.GetResponseStream());
XmlDocument xd = new XmlDocument();
xd.LoadXml(sr.ReadToEnd().Trim());
info.TransactionID = xd.SelectSingleNode("/Txn/Transaction/AuthCode").InnerText;
info.AcceptChanges();
}
message = "Payment Was successful";
return true;
}
If you debug your application from Line No 57(Read XD on line 76). It can give you some clue that why it is failing. General Issues are, Authentication, Acount is not properly Configured and XML Request is not on properly formatted etc.
Hi I have been trying to create payment module for EPIServer Commerce for DPS (Payment Express). I have been following other's example on creating module. I have been getting "Failed to process payment." after clicking next on payment page from the shopping cart. I am usinig EPIServer Commerce SP1. Product Version: 5.2 (build: 628)
I am using Wine Sample shopping template. I have included a bit code that i think is failing me.
I have hardcoded the values for purpose of testing. Any advice on this would be great.