Understanding Web Hooks (and how to consume them)

31 01 2016

Hello all. In this round of posting, I will be explaining a little bit about what web hooks are and how you can consume them within your own application. According to PBWorks, web hooks are simply HTTP callbacks or HTTP POST requests that occurs when something happens. Another important point to note is that a web application implementing web hooks will POST a message to a URL when certain things happen.

understanding web hooks

Imagine having the flexibility of sending a customised email when a customer has being added or updating your own application when the failed payment web hook is fired. All this can be done simply through simple HTTP web hook calls which may have been provided by Ezypay or any other software as a service (SaaS) applications online.

Earlier last year, Ezypay has also released some web hooks to allow developers to customise their application and receive notifications whenever something occurs on our end. Therefore, I am going to use examples of how you can use consume web hooks which are provided by Ezypay for explanation purposes.

The first step in getting your web hooks running is to always subscribe to the web hook to the URL that you have control over. In the case of Ezypay, you can do that by accessing the Developer Center (for organisation level log in only). At the bottom of the screen under the API tab, you should be able to view the web hooks section which will allow you to set up the URL for the notification that you want.

understanding web hooks One of the best places to test if a web hook works would be a free site known asRequestBin. RequestBin provides a FREE (YES It’s FREE!) temporary URL for developers to check out HTTP responses from any particular website especially web hooks. To test it out, head to the RequestBin website and create your own RequestBin URL. Upon entering the website, hit the understanding web hooks to create your own temporary URL. Once the URL is created, RequestBin should prompt you with a screen which looks something like below:understanding web hooks Using the URL that RequestBin has generated, use it as the URL that you would like Ezypay to notify you with of any event. For simplicity of testing, we would like to get a notification when a customer is created, and therefore I will add the URL into the CreateCustomer web hook as shown below. Complete the step by clicking on the understanding web hooks button. understanding web hooks   That would be all to do to run your web hook test. It’s that simple! To check if the web hook work, simply create a customer via the Secure Site, API or the Online Signup form and refresh your RequestBin page. If you have followed the steps correctly, you should be prompted with a different looking page on the same RequestBin URL as shown below on refresh: understanding web hooksInspecting the POST request that came through, you can see that Ezypay is just simply returning a JSON string in which you can parse on your code for your own manipulation. By passing in more requests, you will get more results displayed on the same RequestBin page. Do note that a RequestBin URL only stored 20 requests and lasts for 48 hours only! By using our favourite JSON parser JSON.NET, a .NET developer should have no issue understanding and using the data that has been passed through. As JSON is a commonly understood markup language, it should be parseable by any form of modern software development language. Enjoyed what you have read or learnt something new? Please stay tuned for more weekly articles from the iconnect360 Engineering Blog. If you are interested in learning how to consume Ezypay’s APIs, there was also a tutorial created by me on how to Integrate with Ezypay’s Direct Debit API Using C#. Cheers!





Integrating with Ezypay’s Direct Debit API Using C#

21 12 2015

As a Tech Support and Pre-Sales representative in Ezypay, one of the most common question that comes from  our clients and 3rd party developers would be on integrating with Ezypay via the Direct Debit API (Application Programming Interface). The direct debit API that is provided by Ezypay is useful as it allows businesses to integrate their existing systems with us and bill their customers as required. With our Direct Debit API, developers would be able to:

  • Create customers for billing with Ezypay (on demand or via pre-created Payment Plans)
  • Create debits so that Ezypay will help you bill your customers
  • Retrieve details on a customer and their debits
  • Get a report on the daily transactions in your Ezypay account

*Please note that this article only works for Ezypay billing customers only and not for iconnect360. The iconnect360 API is almost completed and will be released pretty soon. Please move along this article if you are already signed up with Ezypay and are interested to learn how to integrate with us via our API. 

Before going any further, kindly open up the following document to get the methods available on our API: http://www.ezypay.com/help/Content/Resources/PDF/Ezypay_Direct_Debit_API.pdf

To use our API, you will need to have some understanding on HTTP Methods and REST services. If you don’t really know, the 3 HTTP methods that we have are:

  • GET – to retrieve data
  • POST – to insert new data
  • PUT – to update existing data

Our REST service conforms to web standards, and thus can be called via any software development language ranging from .NET (C#, Visual Basic), PHP, Ruby on Rails, Java and many more. The example I will be showing here is going to be written in C#. By grasping the concepts that I am about to explain below, you should be able to port it over to your development tool pretty easily.

To start using our API, you must first obtain a token from our Secure Site Service at http://hello.ezypay.com. Please ensure that you have authenticated login details from the authorized vendor or get them to create a login for you to use to retrieve the authentication token.

After logging in, head over to the Developer Centre as shown below and get the key from the Token Generation Section under the Authentication Token field:

integrating with Ezypay

integrating with Ezypay

Now that you have the authentication part resolved, we will now see what is required to call our service. First, let’s look at what we should pass to the HTTP header.

The 3 things which are required on the HTTP header when making a request are:

  • The Authorization field (Type would be Basic)
  • The Content-Type field
  • The Accept field

Therefore, when properly composed, your header should look something like below

Authorization: Basic aZj1zkAivrnZiiWpiM71O3hBUAAN6S:a
Content-Type: application/json
Accept: application/json

The authorization username will be the token that you have obtained from our Secure Site at http://hello.ezypay.com. In the above snippet, I have set the password to just ‘a’. No passwords are required and will be validated when calling our APIs so you may enter any character or string that you wish. Please ensure that you also set the Content-Type and Accept as application/json as shown above

When it comes to composing the Body of the HTTP request, please ensure that the content is in JSON format only.

Now I will be showing you how we can make a basic call to the Get Customer Detail API using C#. In the following example, I will be making a call to the Retrieve Single Customer method found in our API documentation.

WebRequest req = WebRequest.Create(@"https://api.ezypay.com/api/v1/customers/11111111-1111-1111-1111-1111"); 
req.Method = "GET"; 
req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("aZj1zkAivrnZiiWpiM71O3hBUAAN6S:a")); 
req.ContentType = "application/json"; 
HttpWebResponse resp = req.GetResponse() as HttpWebResponse; 
if (resp.StatusCode != HttpStatusCode.OK) { 
    var message = String.Format("Request failed. Received HTTP {0}", resp.StatusCode); 
    throw new ApplicationException(message); 
} 

var responseValue = string.Empty; // grab the response using (var responseStream = resp.GetResponseStream()) { 
if (responseStream != null) 
    using (var reader = new StreamReader(responseStream)) { 
        responseValue = reader.ReadToEnd(); 
    } 
} 
Console.WriteLine(responseValue);

In the above example, I am attempting to retrieve a customer using HTTP GET with the id, 11111111-1111-1111-1111-1111. I have basically setup the service by passing in the URL to the WebRequest object, and then ensuring that the headers complies to the Authorization as well as the Content-Type. The Accept section needs not require any love when it comes to developing on C# so that could be ignored. Once the service is properly initialized, I am able to recover the details by reading the stream from the HTTPWebResponse object.

Now let’s do something a little more challenging and perform an insert instead. This would require an additional section (which is the HTTP Body) to allow us to send these details to Ezypay for processing. This time, I will be using the Create a debit method found in the API Documentation.

WebRequest req = WebRequest.Create(@"https://api.ezypay.com/api/v1/debits");
req.Method = "POST"; req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("aZj1zkAivrnZiiWpiM71O3hBUAAN6S:a")); 
req.ContentType = "application/json"; 
using (var streamWriter = new StreamWriter(req.GetRequestStream())) 
{ 
    string json = "{\"customerId\":\"11111111-1111-1111-1111-1111\", \"amount\":55, \"date\":\"2014-12-29\"}"; 
    streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); 
} 
HttpWebResponse resp = req.GetResponse() as HttpWebResponse; 

if (resp.StatusCode != HttpStatusCode.OK) { 
    var message = String.Format("Request failed. Received HTTP {0}", resp.StatusCode); 
    throw new ApplicationException(message); 
} 

var responseValue = string.Empty; // grab the response using (var responseStream = resp.GetResponseStream()) { if (responseStream != null) 
    using (var reader = new StreamReader(responseStream)) { 
        responseValue = reader.ReadToEnd(); 
    } 
} 
Console.WriteLine(responseValue);

From the example above, there are a few differences when compared to the GET example prior to this. The obvious one would be the request method that has now been changed to POST instead of GET. At the same time, there is also a new section which has been added to pass in the JSON body (under the using block of the code). If successful, you should be able to get a HTTPStatusCode.OK and that would mean that the debit was successfully created for the customer onEzypay.

I certainly hope that this post has assisted you in understanding how our API can be integrated with your system. We also have many other exciting tools for developers such as the Web Hook which would help provide developers with notifications and details of triggered events in the organization such as customers being added and failed payments. As mentioned at the start of this article, we are also going to release an API for iconnect360 which would help developers to integrate iconnect360 to their existing systems as well.

If you have further questions, please feel free to e-mail me. Have a great day all!





Updated to iPhone's iOS4 and Downloaded the Vuvuzuela App!

27 06 2010

I have just downloaded the latest iOS4 update and jailbroken it with PwnageTool 4.01 for my iPhone 3GS. For those who are interested in jailbreaking it, visit this URL at RedmondPie and follow the guide. All iPhone models from 2G to 3GS can apply this update. Again, please jailbreak at your own risk and a Mac is required to complete this process! As promised by Apple, iOS4 comes with over 100 new features which includes mainly; multitasking, folder management, improved e-mail, iBooks and digital zoom for the camera. For the full list of features, click here.

Below are some screens on the latest features in iOS4 from my iPhone (From top left: (1) A brand new Home Screen, (2) Folder Management, (3) Multitasking bar, (4) Camera Digital Zoom up to 5x:


Due to the World Cup season, I also managed to find a free Vuvuzuela app which you can download from the AppStore. All you need to do is to select your favorite team and touch or shake your phone to emit the buzzing sound which has been a culture and also an annoyance to players and fans altogether throughout World Cup 2010. You can get that app from here via iTunes too. A screenshot available below.

I have also realized in a way that the new iOS4 is faster and a little more smoother when in comes to rendering transitions than previous OS versions as opposed to what other people commented. Probably the 3GS still has enough juice to run iOS4 without any issues. Signing off for now and enjoying Apple’s latest iOS. Wooot! I can’t wait for iPhone 4 already!





iPhone 4 Round-Up

25 06 2010


The iPhone 4 has already gone on sale at the United States yesterday. Summary: Thousands of people are lining up to purchase it, iOS4 is already jailbroken and the phone breaks easily when it drops (from only just 1 foot mind you)!

Below are a round-up of some interesting articles:





Hardware Preview: Belkin Wireless N Technology (Basic, Surf, Share and PlayMax) Routers

24 06 2010

The Belkin Wireless N Technology Routers Lineup

The guys at Belkin Malaysia have just launched their new line of Wireless N Technology routers on the 22nd of June 2010 here. The lineup consist of 4 types of models: Basic, Surf, Share and Play Max. The main difference between the new line of routers compared to other ones in the market would be the ease of setup and built-in apps. One of the apps in my opinion, which is TorrentGenie available on the higher end Play Max model, can actually allow you to download torrent contents off the web without turning your PC on! All you need is just a hard disk plugged into the router, run the app, and you will be downloading content in no time without a PC running overnight.

With 4 ethernet ports and 2 USB ports available, you can connect up to 4 PCs via wire and 2 USB printers or hard disk. The new Belkin routers are all running on 802.11N standard which would allow you to transfer data up to 300MB per second. It also comes with the ‘Easy Start’ and ‘Self-Healing’ feature to ensure easy installation and simple troubleshooting on your network.

Play Max Back View (4 ethernet ports and 2 USB ports for more device connectivity)

Besides the TorrentGenie app which I have introduced earlier, Belkin’s Play Max routers also come with many other apps such as Music Mover, which will allow you to play an entire music library on smart devices, like the Xbox® or PS3™. There is also a Daily DJ app serves up daily personalized playlists to match moods. By analyzing the musical DNA of a collection, Daily DJ creates playlists around three mood mixes: High-Energy, Steady Groove, and Kick Back. Lastly, there is the Song Labeller which will be able to detect and automatically label untitled songs from CDs or MP3s. Be reminded that most of these apps are only available on the higher end Play Max model.

A Sleek Looking Play Max Router from the Front

The Belkin Wireless N Technology routers will be available in Malaysia’s IT stores in mid July 2010. Expect pricing to be around RM100 to RM500 depending on the model.





Sharing your Webpage on Facebook

22 06 2010

With Facebook becoming a trend setter in social networking, it is hardly surprising to see websites coming up with ways to allow users to share content through it. In this post, I will show how you can easily place a Facebook sharing link and place it onto any page of yours.

To do this, firstly, you will require some basic knowledge in HTML. Open up your web page editor and just place in the following code into the location where you want the sharing link to be at:

<a name=”fb_share” type=”button_count” share_url=”www.example.com”  href=”http://www.facebook.com/sharer.php?”>Share</a&gt;
<script src=”http://static.ak.fbcdn.net/connect.php/js/FB.Share&#8221; type=”text/javascript”></script>

Make sure you replace http://www.example.com with your own site URL to ensure that it works. Once successful, you should be seeing a result like this below:
Share

By clicking on it, you will be redirected to Facebook and you should be seeing a result like this:

Facebook sharing!

And that is all you need to share your site on Facebook. Will be coming up with more details on the Facebook API such as the “Like Box” coming here soon!





Edit Videos directly on YouTube!

18 06 2010

YouTube

Always finding it troublesome to edit videos on your PC? Fret no further, the YouTube video editor is here to stay! All you need is a set of video snippets uploaded to Youtube, and you are good to go. You can even add music files from the AudioSwap library, but it may come with some advertisements.

YouTube Editor in action (Taken from HardOCP.com)

For all YouTubers out there, start editing your videos now at http://www.youtube.com/editor. A YouTube account is required. And oh, there are some demo videos you can find here too!








Follow

Get every new post delivered to your Inbox.

Join 164 other followers