There are two methods available for integrating with PayFast, ITN, which is our preferred integration method and PDT, a method that we are deprecating, but might still be useful to some. The main difference, besides better security in ITN, is that with ITN our server contacts your website and notifies you of the payment, whereas with PDT you are required to contact and confirm with us.
The following is a list of pages that are generally needed on your website or application:
|Confirm page||Buyer clicks a button to confirm their order and is redirected to PayFast for payment|
|Success page||Page on your site which the buyer sees after successful payment|
|Cancelled page||Page on your site which the buyer sees after payment is cancelled on PayFast|
|Notify page||Callback page which does all the ‘heavy lifting’ with regards to updating your database with payment information etc.|
This page will have an HTML form, usually hidden, with a number of fields containing all the necessary information needed for PayFast to process the payment. Some shopping cart systems will have the buyer click on a ‘Confirm Order’ or ‘Pay Now’ to submit the form and some shopping carts automatically redirect the user to the PayFast payment engine when they land on this page.
Success Page ‘return_url’
This page on your site is where the buyer is redirected to, from PayFast, after a successful payment. A plain HTML page thanking the buyer for their purchase (and maybe mentioning the delivery procedure) is usually the norm. The page is specified by the return_url variable in the HTML form on the Confirm Page.
If you are using the PDT method to update your custom integration this page would handle any required functionality.
Cancelled Page ‘cancel_url’
This page (on your site) is where the buyer is redirected from PayFast if they cancel their payment. Good practice is to set this to a page which will allow the buyer to try and purchase again. Our recommendation is that you return the buyer to the Confirm Page. This page is specified by the cancel_url variable as defined in the HTML form on the Confirm Page.
Notify Page ‘notify_url’
This page would do all the ‘work’ which is required (e.g. updating the order in your database), when using our ITN method. This page is ‘called’ by our server directly after a successful payment and before the user is redirected to the Success Page. If there are any issues getting to or errors encountered, our server would try again (up to four more times).
Possible Sequence of events
Below is a sequence of events for a successful and unsuccessful (cancelled) payment on PayFast assuming the use of the above integration process and using the ITN method.
- Variables POSTed to PayFast from merchant website. The URL to which they are posted is:
- Payment collected from customer through payment engine
- Upon successful payment on PayFast:
- ITN notification triggered by separate process to notify_url
- PayFast server POSTs payment variables to notify_url
- ITN process completes
- Customer displayed success screen on PayFast
- Customer redirected to return_url on merchant website
- If first ITN was unsuccessful (eg. due to merchant server outage), ITN is attempted again after 5 minutes, up to 4 consecutive times
- Variables POSTed to PayFast from merchant
- Buyer cancels payment on PayFast during any step
- Customer displayed unsuccessful screen on PayFast
- Customer redirected to cancel_url on merchant’s site
- Note: no ITN is triggered for a cancelled payment