Using the Paystack Payment API — Part I

Subomi Oluwalana
2 min readNov 1, 2016

--

In this post, I want to share how to use the paystack payment API, which i believe to be very easy to use. The best part is paystack, to a large extent is an indigenous company, and it’s third party API for various platforms are maintained by nigerian developers … how cool is that?

So, lets jump in

There are 3 major ways of communicating with the API, which are:

  1. Paystack Inline
  2. Paystack Standard
  3. Paystack Pages

Understand that the paystack api is a restful api that lives at https://api.paystack.co

To walk through this tutorial, you’ll majorly one thing — a paystack account, which is free, LoL … so head over to https://paystack.co and create an account.

PAYSTACK INLINE

Paystack inline is communicating with the paystack api from the frontend of your code. It is the easiest methodology of integrating the api. To integrate is simple:

On your frontend attach this js code for integration.

Inserting the paystack inline script.

In that js library, just one function does the trick: paystackpop.setup

paystackpop.setup receives a object of parameters and returns an object, and on that object you fire your request. Lets see the example below:

Note: When you create an account, paystack generates two keys for you public key and secret key. In the key property of the object, you are to use only your public key. Never ever fix in there your secret key.

And off you go, the paystack api responds with some form to input card details etc.

The important part of this model of payment, is the callback property of the object passed into the paystackpop.setup function. After payment is made a response Json object is returned containing details about a successful transaction

With this callback, you can then show your customers their invoice.

NOT BLINDSIDING YOUR BACKEND APPLICATION

In this manner, transaction has been made, but then your actual backend server is not aware of this, but below are two models of updating your backend application:

  1. Manual Update in Callback: You could update it when your callback function is called. This can be stressful for your client app.
  2. Webhooks: I would specifically talk about webhooks later in this series, but to say a little, you can input a webhook url (A simple link or route to your backend server) at your paystack dashboard and once this event occurs, it would the information automatically to your server.

Use the image below to grasp it better:

Would continue form here, from paystack redirect, next post. Please drop your questions, comments and don’t forget to like and follow on twitter @_subomijs

The full code:

--

--