DEV Community

Cover image for Part 2: Testing the Paystack Integration Using Postman
omoluabidotcom
omoluabidotcom

Posted on • Edited on

Part 2: Testing the Paystack Integration Using Postman

This is a follow-up article to Part 1, which guided Paystack payment gateway integration. It is going to be a very short and straightforward guide. We are going to be using Postman to test our endpoint.

This article will definitely not make sense if you haven't read Part 1, so please visit here to read and come back here.
We have three endpoints to make requests to accept payment.

CreatePlan Endpoint

Starting with the first endpoint, "CreatePlan endpoint," from PaystackController POJO, we see that the Createplan methods require us to pass in a request body three parameters, as in the image below.

Image description

The URL will be according to your configuration, and the request is a POST request. After hitting the endpoint, if everything goes well, the response will be as shown in the image below.

Image description

InitializePayment Endpoint
InitializePayment endpoint. From the name, it initiates the payment. This endpoint accepts a POST request, and its request body needs five JSON parameters as shown in the image below.

Image description

The initializepayment endpoint URL should be similar to the createplan just the last part makes them different. The amount here in the JSON body should be the same as the amount used in createplan endpoint, and the value of the plan here in initializepayment endpoint is gotten from the response in the createplan endpoint, in particular the plan_code value.
Make a request to initializepayment endpoint if everything goes well, your response should be as in the image below.

Image description

The authorization_url in the response is where you redirect to. Since we are testing on the backend, copy the URL and paste it into a web browser, Paystack checkout page appears, and the user makes a payment, as shown in the pictures below.

Checkout Page

Image description

Payment Succesful

Image description

VerifyPayment Endpoint

Paystack makes available means to verify if payment has been made. The verifypayment endpoint accepts GET requests.
Verifypayment endpoint needs three path variables to be passed in the URL to make a valid request as it relates to our implementation.
The three path variables to be added are reference, plan, and id respectively.
The reference is gotten from the initializepayment response body, the plan is the plan the user is paying for and the id is the user id.
If everything goes as expected, the response would be like the picture below.

Image description

That is all for now, Thank you for your time. If you have questions, please drop them in the comment section. Have a great day.

Credit

Paystack Documentation

Top comments (2)

Collapse
 
philip_ajibola_6f6565055a profile image
Philip Ajibola

is paystack meant for subcription alone can't we use the platform for like an estore... where by when acustomer buys a product they pay with teh help paystack integration.... i don't know if you get what i am trying to say

Collapse
 
exhibit19 profile image
Ijedibia Daniel

Just saw it now, thanks again