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!





I will be Back Blogging!

3 09 2009

After a month’s hiatus due to my really busy schedule last month, I was unable to spend some time on this blog. However, Derek’s Tech Blog will be coming back with a BANG this month!

Derek is a Windows 7 Rock Star

Derek is a Windows 7 Rock Star

Firstly, I have been selected as a Windows 7 Rock Star to blog regarding my experiences with Windows 7. As a result, I am now waiting for my final copy of Windows 7 to be sent to me for everyday use. Do look out for a twice a week posting on my experience with Windows 7 in the coming month!

Secondly, I would also be doing reviews on several software and websites. I currently owe 2 reviews for a music software and a cable selling company ever since July! I would like to sincerely apologize for the delay… Watch out for the 2 reviews to be published soon as well.

Hold your horses and I will be right back with more on tech!





The Future of Hard Disks – Solid State Drives (SSD)

22 07 2009

Burn baby Burn!How many hard disks and how many precious data have ever died on you before you did a full backup? For me, I had 2 experiences which almost made me hang myself… SERIOUSLY! In my previous encounters with dying hard disks, precious pictures, videos and document files disappeared before I even got a chance to back them up, thus causing total heartbreak! So the question that most of you may ask is: Why are hard disks failures so common today?

One of the main reasons why traditional magnetic hard disks gets spoiled so easily is because it  runs on spinning magnetic disks. This means that even a speck of dust entering this traditional drive can cause your hard disk to die a slow death, leading to data loss and damages. A strand of hair on the other hand would cause even worst damage. Spinning magnetic disks have been creating problems for so many years till I have no idea why it took so long for the engineers to come up with something new. But fast forward to year 2009, these problems are starting to get answered.

2009 have been a very progressive year for  Solid State Drives, also commonly known as SSD so far. SSD resolves the issues that we have been facing by changing the way data is being read from a disk. By using solid-state memory to store persistent data instead of spinning disks, your data could still survive even if the hard disk have fallen from the 3rd floor of a building. Check out this great video by the guys at Samsung for proof!

Besides being reliable, SSDs also offers better performance, faster startup, no noise and lower temperatures!

The only issue that is preventing SSD from kicking off at the moment though is pricing. Several companies such as Dell and Apple are already introducing SSD based laptops in their lineup. However, the price is still too expensive for the mass public to purchase. Current checks on PC-Zone’s latest brochure shows that a 32GB SSD drive will cost RM299 (USD 150)! That amount of money would be almost enough to purchase a 1 TB traditional hard disk today.  A 64GB one on the other hand would cost RM599(USD200).

Intel® X25-M SATA Solid-State Drive (SSD)

Intel® X25-M SATA Solid-State Drive (SSD)

Of course, having said that, I bring you good news regarding the latest development in SSD technology. Just today, Intel announced that they have successfully delivered the industry’s first 34-Nanometer NAND Flash Solid-State Drives. What does this means for us as consumers? SSD drives will now be cheaper by up to 60 percent! So if you are really looking into getting a SSD, you can start scouting around for it in the next few months already.

As time goes on, we hope to see SSDs replacing traditional hard disks in the future so that we do not need to end up keeping backups all the time. And there you have it, the future of more reliable hard disks is coming to you right now!

Delivers Industry’s First 34-Nanometer NAND Flash Solid-State Drives; Advancement Lowers Prices by Up to 60 Percent





A Big THANK YOU to all Visitors!!!

13 07 2009

Wordpress LogoAfter checking my blog’s stats at WordPress today, I was in for quite a surprise. This blog is hitting close to 1000 hits a week! From a humble beginning of 10 visitors a week in the 1st week of April, the number of visitors have been steadily increasing from strength to strength. I am proud to say that this is quite a milestone achievement for a tech blog which have just started.

Derek's Tech Blog Statistics as of 13th June 2009

Derek's Tech Blog Statistics as of 13th July 2009

As of such, I will try my very best to write more about simple tech stuff that YOU can do. Don’t only view tech from a user standpoint, try getting involved in it too! 😀

I would also like to take this opportunity to thank everyone who have chipped in their comments and ideas in this blog as well. Lets keep in touch. 🙂





Windows 7 RC Build 7100 Released!

8 05 2009

Windows 7 RC1 changesThis may be a little outdated as the release was back on the 5th of May. However, for those of you who do not know, you can download the latest version of Windows 7 right here with your Windows Live ID.

Some of the changes includes a Windows XP mode, which is something like running a Windows XP VPC on Windoes 7, turning off features such as Internet Explorer and Windows Media Player, a modified Aero Peek, better performances and 30 0ther changes from beta (Build 7000) to RC (Build 7100) as shown here.

I am itching to get it installed during the weekend already. Time to get started!





Me Grimlock is MP-08!

6 04 2009

After stressing myself out on work, I have decided to go over to Graffiti Toys to get myself a Master Piece Transformer. This is the very first time that I have got myself a Transformer which is of masterpiece quality. The MP that I got was none other than Dinobot Commander, Grimlock which was just release in Japan about 2 weeks ago! I was pretty lucky to get it for just RM360 (Original retail price: RM400).Below are some snapshots of the toy in robot mode and alternate mode.

MP08 Grimlock has quite a number of interesting features and tricks. By pushing his arm, you can get the gun/sword that he is holding to blink. Besides that, he also comes with a apron and drink tray to serve, a la the 1st generation Transformers cartoon! What an interesting toy… Now I am poisoned to get MP01 Optimus Prime… HELP!