This repository show how you can integrate payfast with your next js application to receive online payments.
First, run the command to install all the dependencies:
npm install
Then start the development server:
npm run dev
# or
yarn dev
You need to install a tool called NGROK ([https://ngrok.com/download] ) to publicly make your notify_url accessible, this is the page payfast will send the payment notification once they payment has been made. Check ngrok official website to learn how to make your localhost available on the internet.
Next, open http://localhost:3000 with your browser to see the result.
NB: Don't forget to include merchant_id and merchant_key as provided by payfast in your .env file. Visit their site [https://developers.payfast.co.za/] to get those details for sandbox testing environment.
Payfast documentation only shows how to do the integration in PHP. This code can still be refactored to make it more secure, please feel free to make changes and improve it.