Created
August 22, 2014 21:12
-
-
Save uxdrew/3b706c1083bd9cbdc2a0 to your computer and use it in GitHub Desktop.
WebServices PrePaidBalanceSwipe with Token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TOKEN | |
{ | |
// Transaction Varialbles | |
private static string merchantID = "023358150511666"; | |
private static string password = "xyz"; | |
private static string invoiceNo = string.Empty; | |
private static string memo = "Testing: WebServices.CSharp"; | |
private static decimal purchase = 2.25m; | |
private static string operatorID = "test"; | |
// Gift Test Card | |
private static string swipedGiftTrack2 = "6050110010021825160=250110115"; | |
private static string keyedGiftAcctNo = "6050110010021825160"; | |
private static string keyedGiftExpDate = "0125"; | |
public void Run() | |
{ | |
PrePaidBalanceSwiped(); | |
Console.Write("End of samples"); | |
Console.ReadLine(); | |
} | |
private static void PrePaidBalanceSwiped() | |
{ | |
Console.Write("Hit Enter to run PrePaid Balance (Swiped)"); | |
Console.ReadLine(); | |
invoiceNo = NewInvoiceNo(); | |
// Create Request KeyValuePairs | |
Dictionary<string, object> requestDictionary = new Dictionary<string, object>(); | |
requestDictionary.Add("MerchantID", merchantID); | |
requestDictionary.Add("IpPort", "9100"); | |
requestDictionary.Add("TranType", "PrePaid"); | |
requestDictionary.Add("TranCode", "Balance"); | |
requestDictionary.Add("InvoiceNo", invoiceNo); | |
requestDictionary.Add("RefNo", invoiceNo); | |
requestDictionary.Add("Memo", memo); | |
requestDictionary.Add("Track2", swipedGiftTrack2); | |
requestDictionary.Add("OperatorID", operatorID); | |
// Process Transaction and get Response KeyValuePairs | |
Dictionary<string, string> responseDictionary = ProcessGiftTransaction(requestDictionary, password); | |
DisplayResponseKeyValuePairs(responseDictionary, "PrePaid", "Balance"); | |
} | |
private static string NewInvoiceNo() | |
{ | |
return DateTime.Now.ToString("yyMMddhhmmssfff"); | |
} | |
private static Dictionary<string, string> ProcessGiftTransaction(Dictionary<string, object> requestDictionary, string password) | |
{ | |
// Build XML Request from KeyValuePairs | |
string xmlRequest = XMLHelper.BuildXMLRequest(requestDictionary).ToString(); | |
string xmlResponse = string.Empty; | |
using (MercuryWebServices.wsSoapClient client = new MercuryWebServices.wsSoapClient()) | |
{ | |
Console.WriteLine("Processing Gift Transaction..."); | |
xmlResponse = client.GiftTransaction(xmlRequest, password); | |
} | |
// Parse XML Response into KeyValuePairs | |
return XMLHelper.ParseXMLResponse(xmlResponse); | |
} | |
private static void DisplayResponseKeyValuePairs(Dictionary<string, string> responseDictionary, string tranType, string tranCode) | |
{ | |
Console.WriteLine(); | |
Console.WriteLine(string.Format("--- Response Key Value Pairs for {0} {1} ---", tranType, tranCode)); | |
foreach (KeyValuePair<string, string> kvp in responseDictionary) | |
{ | |
Console.WriteLine(string.Format("{0}:{1};", kvp.Key, kvp.Value)); | |
} | |
Console.WriteLine(); | |
Console.WriteLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment