eWAY is the easiest way to accept payments in your app or on your website. Get integrated and start selling more, faster - in a range of languages using the eWAY SDKs, helpful documentation, and 24/7 support from real humans. eWAY - with you every step of the way.
Accept payments quickly and easily with eWAY using the eWAY Rapid Ruby SDK (also known as the eWAY Ruby Gem). Using the Ruby SDK provides convenient access to all the features of eWAY’s Rapid API, so you can create transactions, process refunds, query transactions, create token customer and more!
InstallationThe easiest way to add the eWAY Ruby SDK to your project is using RubyGems and Bundler – it will add the eWAY Rapid Ruby Gem along with its required dependencies.
To add the eWAY Rapid Ruby Gem, in your project’s Gemfile add the following line:
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 using the eWAY Ruby Gem, this example will show how to accept a payment with the Responsive Shared Page. This example assumes that Ruby, RubyGems and Bundler are already installed. Only the eWAY specific code is shown so it can be added to your preferred framework.
1. Add the eWAY Ruby Gem
In the project’s Gemfile, add the Ruby Gem:
Then on the command line execute:
to install the Gem and its dependencies.
2. Load the eWAY Client
3. Create a Shared Payment URL
In order to send a customer to the Responsive Shared Page, a URL must be generated using the create_transaction function. This accepts a PaymentMethod and a transaction object.
This step would usually take place after collecting the customer’s information in a checkout process. For this example, just some dummy data will be used:
To make sure everything went well, check the errors array is empty. If it isn’t, user_display_message can be used to convert any error codes to human readable messages:
4. Redirect the Customer
Once the shared page URL has been created, the customer can be redirected. How this is done will depend on the project and framework being used. For example, if using Ruby on Rails, the method would be:
So now a Responsive Shared Page URL has been created and the customer is redirected to complete their payment.
5. Fetch the Result
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.
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 ResponseMessage. An example of handling this information would be:
That’s it – a complete Responsive Shared Page integration!
For more information on the functions available in the eWAY Ruby Gem, check out the eWAY Rapid API Reference.
Image: The Ruby logo is Copyright © 2006, Yukihiro Matsumoto.