Sunday, 21 March 2004

WorldPay with C#/.NET [2]

Maybe useful info for those using C# with WorldPay...

WorldPay.COMcallbackClass callback = new WorldPay.COMcallbackClass(); 
callback.processCallback(); 
if (callback.hadError() ) { 
Trace.Write("WorldPay Error", callback.getRawAuthMessage() ) 
} 
if (callback.didTransSuc() ) { 

// #### WORLDPAY demo page #### 
string traceInfo = ""; 
traceInfo +="culture:" + Thread.CurrentThread.CurrentCulture.EnglishName + "\n"; 
traceInfo +="uiculture:" + Thread.CurrentThread.CurrentUICulture.EnglishName + "\n"; 

traceInfo +="getTransId:" + callback.getTransId() + "\n"; 
traceInfo +="getRawAuthMessage:" + callback.getRawAuthMessage() + "\n"; 
traceInfo +="getRawAuthCode:" + callback.getRawAuthCode() + "\n"; 
traceInfo +="getTransTime:" + callback.getTransTime() + "\n"; 
traceInfo +="shopperId:" + callback.shopperId + "\n"; 

traceInfo +="getInstallationId:" + callback.getInstallationId() + "\n"; 
traceInfo +="getCompanyName:" + callback.getCompanyName() + "\n"; 
traceInfo +="getAuthMode:" + callback.getAuthMode() + "\n"; 
traceInfo +="getAmount:" + callback.getAmount() + "\n"; 
traceInfo +="getCurrencyISOCode:" + callback.getCurrencyISOCode() + "\n"; 
traceInfo +="getAmountString:" + callback.getAmountString() + "\n"; 

traceInfo +="getDescription:" + callback.getDescription() + "\n"; 
traceInfo +="Customer getName:" + callback.getName() + "\n"; 
traceInfo +="Customer getAddress:" + callback.getAddress() + "\n"; 
traceInfo +="Customer getPostalCode:" + callback.getPostalCode() + "\n"; 
traceInfo +="Customer getCountryISOCode:" + callback.getCountryISOCode() + "\n"; 
traceInfo +="Customer getTelephone:" + callback.getTelephone() + "\n"; 
traceInfo +="Customer getFax:" + callback.getFax() + "\n"; 
traceInfo +="Customer getEmail:" + callback.getEmail() + "\n"; 

traceInfo +="\nTRANS_ID:" + callback.getParameterString("MC_DataID") + "\n";  // CUSTOM PARAM prefix with MC_ 
traceInfo +="MEMBER_ID:" + callback.getParameterString("MC_MemberID") + "\n"; // CUSTOM PARAM 

Trace.Write("WorldPay", traceInfo);

And if you're programming in Japanese... trying to get Japanese characters to display on the WorldPay pages was a real pain-- encoding issues (i'm using UTF-8 for my site - they use Shift_JIS). To set the job description, name and address info i'm currently using this hack

// so manually converting to HTML Unicode Entities 
// as discussed here http://www.randyrants.com/archives/000348.asp 
int ch1; 
string snail2="";  
foreach (char c in currentTransaction.Desc) { 
ch1 = c; 
if (!((ch1 >= 160) && (ch1 < 256))) {// if in 'ascii' range - *THINK* this works....
snail2 += c; // leave as-is 
} else { // convert to entity format Ӓ 
snail2 += string.Concat("&#", ch1.ToString(System.Globalization.NumberFormatInfo.InvariantInfo), ";"); 
} 
} 
purchase.setDescription (snail2); // HACK: HTML Entity Encoding 
[4-May-04] UPDATED CODE here

2 comments:

  1. please let me know where the classes are available to create WorldPay.COM.....?

    ReplyDelete
  2. Sorry Trailblazer - this post was way back in 2004... it's been a while since I've worked with WorldPay.

    I'm pretty sure you must be a client of WorldPay (www.worldpay.com) before they will supply the COM components to install on your web server.

    ReplyDelete

Note: only a member of this blog may post a comment.