Skip to content

Instantly share code, notes, and snippets.

@ianleeder
Created November 18, 2015 23:51
Show Gist options
  • Save ianleeder/e09c440998c0019c6ef3 to your computer and use it in GitHub Desktop.
Save ianleeder/e09c440998c0019c6ef3 to your computer and use it in GitHub Desktop.
Test code to try and generate TokenCustomerIDs.
public static void TestTransaction()
{
IRapidClient ewayClient = RapidClientFactory.NewRapidClient(ApiKey, ApiPassword, RapidEndpoint);
// STEP 1
// Create the transaction with eWAY
Transaction transaction = new Transaction()
{
Customer = new Customer()
{
Reference = "A12345",
Title = "Mr.",
FirstName = "John",
LastName = "Smith",
Address = new Address()
{
Street1 = "Level 5",
Street2 = "369 Queen Street",
City = "Sydney",
State = "NSW",
Country = "au",
PostalCode = "2000",
},
},
PaymentDetails = new PaymentDetails()
{
TotalAmount = 1000,
InvoiceNumber = "Inv 21540",
InvoiceDescription = "Individual Invoice Description",
InvoiceReference = "513456",
CurrencyCode = "AUD"
},
RedirectURL = "http://www.eway.com.au",
Capture = true,
TransactionType = TransactionTypes.Purchase
};
CreateTransactionResponse createResponse = ewayClient.Create(PaymentMethod.TransparentRedirect, transaction);
// STEP 2
// Post payment (credit card) details
// Spoof an HTML form with POST submit action
#region HTML POST
WebRequest req = WebRequest.Create(createResponse.FormActionUrl);
string postData = "EWAY_ACCESSCODE=" + createResponse.AccessCode +
"&EWAY_PAYMENTTYPE=Credit Card" +
"&EWAY_CARDNAME=Mr. John Smith" +
"&EWAY_CARDNUMBER=4444333322221111" +
"&EWAY_CARDEXPIRYMONTH=1" +
"&EWAY_CARDEXPIRYYEAR=2019" +
"&EWAY_CARDCVN=123";
byte[] dataToSend = Encoding.Default.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = dataToSend.Length;
Stream sout = req.GetRequestStream();
sout.Write(dataToSend, 0, dataToSend.Length);
sout.Flush();
sout.Close();
#endregion
// Need to pause, otherwise we receive S5099 Incomplete (Access Code in progress/incomplete)
System.Threading.Thread.Sleep(1000);
// STEP 3
// Retrieve results from eWAY
QueryTransactionResponse queryResponse = ewayClient.QueryTransaction(createResponse.AccessCode);
string token = String.IsNullOrEmpty(queryResponse.Transaction.Customer.TokenCustomerID)
? "empty"
: queryResponse.Transaction.Customer.TokenCustomerID;
Console.Out.WriteLine("[Transaction] TokenCustomerID = " + token);
}
public static void TestCustomer()
{
IRapidClient ewayClient = RapidClientFactory.NewRapidClient(ApiKey, ApiPassword, RapidEndpoint);
// STEP 1
// Create the transaction with eWAY
Customer c = new Customer()
{
Reference = "A12345",
Title = "Mr.",
FirstName = "John",
LastName = "Smith",
Address = new Address()
{
Street1 = "Level 5",
Street2 = "369 Queen Street",
City = "Sydney",
State = "NSW",
Country = "au",
PostalCode = "2000",
},
RedirectURL = "http://www.eway.com.au"
};
CreateCustomerResponse createResponse = ewayClient.Create(PaymentMethod.TransparentRedirect, c);
// STEP 2
// Post payment (credit card) details
// Spoof an HTML form with POST submit action
#region HTML POST
WebRequest req = WebRequest.Create(createResponse.FormActionUrl);
string postData = "EWAY_ACCESSCODE=" + createResponse.AccessCode +
"&EWAY_PAYMENTTYPE=Credit Card" +
"&EWAY_CARDNAME=Mr. John Smith" +
"&EWAY_CARDNUMBER=4444333322221111" +
"&EWAY_CARDEXPIRYMONTH=1" +
"&EWAY_CARDEXPIRYYEAR=2019" +
"&EWAY_CARDCVN=123";
byte[] dataToSend = Encoding.Default.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = dataToSend.Length;
Stream sout = req.GetRequestStream();
sout.Write(dataToSend, 0, dataToSend.Length);
sout.Flush();
sout.Close();
#endregion
// Need to pause, otherwise we receive S5099 Incomplete (Access Code in progress/incomplete)
System.Threading.Thread.Sleep(1000);
// STEP 3
// Retrieve results from eWAY
QueryTransactionResponse queryResponse = ewayClient.QueryTransaction(createResponse.AccessCode);
string token = String.IsNullOrEmpty(queryResponse.Transaction.Customer.TokenCustomerID)
? "empty"
: queryResponse.Transaction.Customer.TokenCustomerID;
Console.Out.WriteLine("[Customer] TokenCustomerID = " + token);
}
@UmairAnhar
Copy link

Hi Ian,

Im facing an issue regarding the CustomerTokenId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment