Part 2: Testing the Paystack Integration Using Postman

Part 2: Testing the Paystack Integration Using Postman

Testing the integrated Paystack APIs

Table of contents

No heading

No headings in the article.

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.

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.

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.

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.

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

Payment Succesful

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.

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