# How to integrate Popup Checkout

> Initialize a Paystack transaction on your server and complete it in the browser with Popup Checkout.

For an overview of how Checkout works, see [Checkout](/payments/online/checkout).

## Install InlineJS

Use either the CDN script or the package:

```html
<script src="https://js.paystack.co/v2/inline.js"></script>
```

```bash
npm i @paystack/inline-js
```

```js
import Paystack from '@paystack/inline-js'

const popup = new Paystack()
```

## Initialize the transaction on your backend

Create the transaction from your server and return the `access_code` to the browser.

<callout type="danger">

Never call the Paystack API directly from your frontend code. Doing so exposes your secret key to anyone who views your page source or intercepts the request. All Paystack API calls must be made from your server, and your frontend should only receive what your server chooses to pass back.

</callout>

```js
const https = require('https')

const params = JSON.stringify({
  email: 'customer@email.com',
  amount: '500000',
  callback_url: 'https://your-app.example.com/payment/callback'
})

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 response returns:

```json
{
  "status": true,
  "message": "Authorization URL created",
  "data": {
    "authorization_url": "https://checkout.paystack.com/nkdks46nymizns7",
    "access_code": "nkdks46nymizns7",
    "reference": "nms6uvr1pl"
  }
}
```

## Open Popup with the access code

Call your backend endpoint, then resume the transaction in the browser.

```js
import Paystack from '@paystack/inline-js'

const popup = new Paystack()

async function startPayment() {
  const response = await fetch('/api/initialize-payment', { method: 'POST' })
  const { access_code } = await response.json()

  popup.resumeTransaction(access_code)
}
```

## Handle the callback URL

Set a `callback_url` when you initialize the transaction. Paystack appends the transaction reference to that URL after the payment attempt.

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

Do not fulfil the order from the callback alone.

## Verify the transaction

Verify the returned `reference` from your server:

```js
const https = require('https')

const options = {
  hostname: 'api.paystack.co',
  port: 443,
  path: '/transaction/verify/:reference',
  method: 'GET',
  headers: {
    Authorization: 'Bearer YOUR_SECRET_KEY'
  }
}

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

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

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

Check `response.data.status` and `response.data.amount` before you deliver value.

## Handle the webhook

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](https://dashboard.paystack.com/v2/developers/api-configuration), and [verify the signature](/developer-tools/integration/webhooks#verify-webhook-signatures) on every event with your webhook signing secret.

```json
{
  "event": "charge.success",
  "data": {
    "status": "success",
    "reference": "re4lyvq3s3",
    "amount": 40333,
    "channel": "card"
  }
}
```

Use the verify endpoint for callback handling, reconciliation, and cases where you need to confirm the final state manually.
