Become an eWAY merchant today.
With 24/7 support, over 250 integrations and 20+ years experience – the team at eWAY are here to provide you with the leading all-in-one payments solution.
Accept payments quickly and easily with eWAY and .NET (C#) using the eWAY Rapid .NET SDK. Using the eWAY .NET SDK provides convenient access to all the features of eWAY’s Rapid API, so you can create transactions, process refunds, query transactions, create token customers, and more!
The eWAY .NET SDK is available from NuGet, a .NET package manager. Installing with NuGet means you will also fetch the eWAY .NET SDK dependencies, plus receive notification of any package updates.
To install with the NuGet Package Manager Console, simply run
1 | PM> Install-Package eWAY.Rapid |
Alternatively, use the NuGet dialog and search for eWAY to add the package to your solution.
To make development and testing with eWAY easy, get a free partner account which provides access to the eWAY Sandbox.
Now you are all set to build your eWAY integration! You can find code samples for integrating various eWAY functions as part of the eWAY Rapid API reference.
To demonstrate adding the eWAY .NET SDK, this example will show how to accept a payment with the Responsive Shared Page.
This example assumes that Visual Studio with NuGet is being used. To keep things simple, only the eWAY specific code is shown so it can be added to your preferred network.
1 | Install-Package eWAY.Rapid |
With the eWAY .NET SDK installed, the next step is to add the eWAY integration to your project. To start, generate an instance of the eWAY RapidClient which interacts with eWAY’s Rapid API. It needs an eWAY Rapid API key & password, along with the endpoint to connect to (Live or Sandbox):
1 2 3 4 5 | string apiKey = "60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR"; string password = "API-P4ss"; string rapidEndpoint = "Sandbox"; IRapidClient ewayClient = RapidClientFactory.NewRapidClient(apiKey, password, rapidEndpoint); |
In order to send a customer to the Responsive Shared Page, a URL must be generated using thecreate function. This accepts a PaymentMethod and a Transaction object.
The PaymentMethod determines how the card data will be accepted (in this case ResponsiveShared) while the Transaction object contains customer and invoice details – more details of the variables that can be passed can be found in the Rapid API reference.
1 2 3 4 5 6 7 8 9 10 11 12 13 | Transaction transaction = new Transaction() { PaymentDetails = new PaymentDetails() { TotalAmount = 1000 }, RedirectURL = "http://www.eway.com.au", CancelURL = "http://www.eway.com.au", TransactionType = TransactionTypes.Purchase }; CreateTransactionResponse response = ewayClient.Create(PaymentMethod.ResponsiveShared, transaction); |
1 2 3 4 5 6 7 | if (response.Errors != null) { foreach (string errorCode in response.Errors) { Console.WriteLine("Error Message: " + RapidClientFactory.UserDisplayMessage(errorCode, "EN")); } } |
1 | return Redirect(response.SharedPaymentUrl); |
Once the customer has gone to the Responsive Shared Page and submitted their payment information, they will be redirected back to the RedirectUrl specified in the request. This page should use the AccessCode (passed as a query variable) to fetch the result of the transaction.
1 | QueryTransactionResponse response = ewayClient.QueryTransaction(AccessCode); |
Key information such as the success of the transaction and the transaction ID can be found in the TransactionStatus of the response. If the transaction wasn’t successful, the reason can be found in the ResponsiveMessage. An example of handling this information would be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | if ((bool)response.TransactionStatus.Status) { Console.WriteLine("Payment successful! ID: " + response.TransactionStatus.TransactionID); } else { string[] errorCodes = response.TransactionStatus.ProcessingDetails.ResponseMessage.Split(new[] { ", " }, StringSplitOptions.None); foreach (string errorCode in errorCodes) { Console.WriteLine("Response Message: " + RapidClientFactory.UserDisplayMessage(errorCode, "EN")); } } |
That’s it – a complete Responsive Shared Page integration!
For more information on the functions available in the eWAY .NET SDK, check out the eWAY Rapid API Reference.
With 24/7 support, over 250 integrations and 20+ years experience – the team at eWAY are here to provide you with the leading all-in-one payments solution.