Sign in

Payments

How to integrate Redirect Checkout

View as Markdown

In a nutshell

Initialize a transaction, redirect to Paystack Checkout, and verify the result on return.

For the product overview, see Checkout.

Warning

Confirm that your server can complete a TLSv1.2 connection to Paystack's servers. Most up-to-date software handles this automatically. If you receive SSL errors, contact your hosting provider.

Copy linkInitialize the transaction on your backend

Create the transaction from your server and include a callback URL.

const https = require('https')

const params = JSON.stringify({
  email: '[email protected]',
  amount: '20000',
  callback_url: 'https://hello.pstk.xyz/callback',
  metadata: {
    cancel_action: 'https://your-cancel-url.com'
  }
})

const options = {
  hostname: 'api.paystack.co',
  port: 443,
  path: '/transaction/initialize',
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR_SECRET_KEY',
    'Content-Type': 'application/json'
  }
}

const req = https.request(options, (res) => {
  let data = ''

  res.on('data', (chunk) => {
    data += chunk
  })

  res.on('end', () => {
    console.log(JSON.parse(data))
  })
})

req.write(params)
req.end()

A successful initialization returns authorization_url, access_code, and reference.

Copy linkRedirect the customer to authorization_url

After initialization, send the customer to the hosted Checkout page.

app.post('/pay', async (req, res) => {
  const response = await initializeTransaction(req.body)
  res.redirect(response.data.authorization_url)
})

Use your own unique transaction reference if you generate one internally.

Copy linkHandle the callback

When the customer completes the flow, Paystack redirects them back to your callback URL with the transaction reference in the query string.

app.get('/callback', (req, res) => {
  const { reference } = req.query
  res.redirect(`/payment-status?reference=${reference}`)
})

A visited callback URL only means the customer returned to your app. It does not confirm success.

Copy linkVerify the transaction from your server

Verify the returned reference before fulfilment.

curl https://api.paystack.co/transaction/verify/:reference \
-H "Authorization: Bearer YOUR_SECRET_KEY" \
-X GET

The verify response contains the transaction status and the amount charged. Fulfil the order only when data.status is success and the amount matches the transaction you created.

Copy linkHandle webhook confirmation

Use the charge.success webhook as your primary signal to fulfill orders, grant access, or update your database. The customer can close the page before your callback runs, but the webhook still arrives.

Add your webhook URL on the Paystack Dashboard, and verify the signature on every event with your webhook signing secret.

Keep the verify call for callback handling and reconciliation.

Was this page helpful?