Skip to content

Instantly share code, notes, and snippets.

@ianleeder
Last active February 8, 2016 23:46
Show Gist options
  • Save ianleeder/a977ad896a858c3a9d3b to your computer and use it in GitHub Desktop.
Save ianleeder/a977ad896a858c3a9d3b to your computer and use it in GitHub Desktop.
Test case to show InvoiceDescription (and CurrencyCode) aren't returned for TransactionTypes.Purchase
public static void TestInvoiceDescription()
{
// Register a user
string token = TestRegisterInvoiceDescription();
TestRecurringPaymentInvoiceDescription(token);
}
public static string TestRegisterInvoiceDescription()
{
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",
SaveCustomer = 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 intermittently receive S5099 Incomplete (Access Code in progress/incomplete)
System.Threading.Thread.Sleep(1000);
// STEP 3
// Retrieve results from eWAY
QueryTransactionResponse response = ewayClient.QueryTransaction(createResponse.AccessCode);
// InvoiceNumber, InvoiceReference, TotalAmount are all returned
// But no InvoiceDescription or CurrencyCode
string invoiceDescription = response.Transaction.PaymentDetails.InvoiceDescription;
string output = "Invoice description was: " +
(String.IsNullOrEmpty(invoiceDescription) ? "EMPTY!" : invoiceDescription);
Console.WriteLine(output);
Debug.WriteLine(output);
return response.Transaction.Customer.TokenCustomerID;
}
public static void TestRecurringPaymentInvoiceDescription(string id)
{
Transaction t = new Transaction
{
Customer = new Customer
{
TokenCustomerID = id
},
TransactionType = TransactionTypes.Recurring,
PaymentDetails = new PaymentDetails
{
TotalAmount = 1000,
CurrencyCode = "AUD",
InvoiceNumber = "Inv 21541",
InvoiceDescription = "Recurring Invoice Description",
InvoiceReference = "513457",
}
};
IRapidClient ewayClient = RapidClientFactory.NewRapidClient(ApiKey, ApiPassword, RapidEndpoint);
CreateTransactionResponse response = ewayClient.Create(PaymentMethod.Direct, t);
// All return ok here (CurrencyCode, InvoiceDescription, InvoiceNumber, InvoiceReference, TotalAmount)
string invoiceDescription = response.Transaction.PaymentDetails.InvoiceDescription;
string output = "Invoice description was: " +
(String.IsNullOrEmpty(invoiceDescription) ? "EMPTY!" : invoiceDescription);
Console.WriteLine(output);
Debug.WriteLine(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment