# InlineJS

> Paystack's browser JavaScript library for accepting payments in web apps.

## Introduction

InlineJS is Paystack’s Javascript library that offers a simple, secure, and convenient payment flow for web applications. It provides methods for initiating different types of payments e.g one time, recurring, split etc. and handle payment state, all with a few lines of code.

For a step-by-step guide to opening Paystack Popup with InlineJS, see [Popup](/payments/online/checkout/popup).

## Browser support

Paystack InlineJS is designed to support all recent versions of major browsers. The library is compiled to ES5 and polyfilled to ensure it can work on as many devices as possible.

We don't support outdated browsers like IE9 nor browsers that disable the use of Javascript, like Opera mini.

- We require TLS 1.2 to be supported by the browser
- We support Chrome and Safari on all platforms
- We support Firefox on desktop platforms
- We support the Android native browser on Android 4.4 and later

<callout title="Opera Mini support" type="warning">

We don't support Opera Mini because Javascript is disabled in it. However, we support the Opera browser, except in super saver mode where JavaScript is disabled as well.

</callout>

## Installation

Paystack InlineJS can be included in your app via `CDN`, `NPM` or `Yarn`:

<code-tabs :labels="{"cdn":"CDN","npm":"NPM","yarn":"Yarn"}">
<template v-slot:cdn="">

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

</template>

<template v-slot:npm="">

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

</template>

<template v-slot:yarn="">

```bash
yarn add @paystack/inline-js
```

</template>
</code-tabs>

If you used `NPM` or `Yarn`, ensure you import the library as shown below:

<code-tabs :labels="{"cdn":"CDN","npm":"NPM"}">
<template v-slot:cdn="">

```javascript
const popup = new PaystackPop();
```

</template>

<template v-slot:npm="">

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

const popup = new Paystack()
```

</template>
</code-tabs>

## Paystack object

The `Paystack` object gives access to the methods and interfaces available in InlineJS. It exposes methods, alongside configuration options that can help you accept payment seamlessly in your web app. The methods exposed by the `Paystack` object include:

1. `checkout(options)`: This is an asynchronous method used to create a transaction.
2. `newTransaction(options)`: This is a synchronous method used to create a transaction.
3. `resumeTransaction(accessCode)`: With this method, you can initiate a transaction from your backend using the initialize endpoint, then complete the transaction in the frontend without redirecting.
4. `cancelTransaction(id)`: Sometimes, it might take a while to load a transaction. In such a situation, this method can be used to cancel the transaction.
5. `preloadTransaction(options)`: This method is used to load a transaction in the background such that when the user is about to checkout, the Popup loads instantly.
6. `paymentRequest(options)`: This is best suited for handling a custom user experience when your users can make a payment from their wallet (for example Apple Pay or Google Pay)

<callout title="Wallet support" type="info">

`paymentRequest()` supports Apple Pay, and Google Pay for businesses in South Africa. Both wallets are also available in the card section of Checkout through `checkout()`, with no extra work on your part.

</callout>

## Callbacks

The `Paystack` object also exposes callbacks that can be used to monitor certain states during the lifecycle of a transaction.

### onLoad

This is called when the transaction is successfully loaded and the customer can see the Popup. It returns an object with the following parameters:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      This is the transaction id
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        accessCode
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      This is a unique payment code used for creating the payment link and loading the Popup
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        customer
      </code>
    </td>
    
    <td>
      Object
    </td>
    
    <td>
      The details of the customer making the payment
    </td>
  </tr>
</tbody>
</table>

```javascript
onLoad: (response) => {
  // Transaction has loaded
  // You can parse the transaction object if you need to.
}
```

### onSuccess

This is called when the customer successfully completes a transaction. It returns an instance of a transaction object:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        reference
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      This is the unique payment reference that can be used for reconciliation
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        trans
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      This is the transaction id (for backward compatibility)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        status
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      The final state of the transaction
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        message
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      Complimentary note of the transaction status
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        transaction
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      This is the transaction id
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        trxref
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      This is the unique payment reference that can be used for reconciliation (for backward compatibility)
    </td>
  </tr>
</tbody>
</table>

```javascript
onSuccess: (transaction) => {
  // Post payment flow can go here
}
```

### onElementsMount

This is called once mounting has finished for every wallet. It returns an object reporting each wallet, `{ applePay: Boolean, googlePay: Boolean }`, or `null` when mounting failed. A wallet reports `false` when the customer's device or browser can't pay with it.

```javascript
onElementsMount: (elements) => { // { applePay: Boolean, googlePay: Boolean } or null
  if (elements) {
    console.log("Successfully mounted elements: ", JSON.stringify(elements));
  } else {
    console.log('Could not load elements');
  }
}
```

### onCancel

This is called when the transaction is cancelled. It returns no response.

```javascript
onCancel: () => {
  console.log("User cancelled")
}
```

### onError

This is called when there is an issue loading the transaction.

```javascript
onError: (error) => {
  console.log("Error: ", error.message);
}
```

## Transaction request

With Paystack, a transaction can be initiated for different scenarios such as:

- One-time payment
- Split payment
- Multi-split payment
- Subscriptions

InlineJS provide parameters and methods to to create the different types of transaction. The table below shows the general options that be used when creating a transaction:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Your public key, from <a href="https://dashboard.paystack.com/v2/developers/api-configuration" rel="nofollow" target="_blank">
        Developers → API configuration
      </a>
      
       on your Paystack Dashboard
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        amount
      </code>
    </td>
    
    <td>
      Number
    </td>
    
    <td>
      True
    </td>
    
    <td>
      The amount of the transaction in the lowest denomination of your currency
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        email
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      The customer's email address
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        currency
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The currency of the transaction, such as <localized-value page-key="markets" path="currency_code">
        
      </localized-value>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        firstName
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The customer's first name
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        lastName
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The customer's last name
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        phone
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The customer's phone number
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        customerCode
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      A valid Paystack customer code. If provided, this overrides all the customer information above
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        channels
      </code>
    </td>
    
    <td>
      Array
    </td>
    
    <td>
      False
    </td>
    
    <td>
      An array of payment channels to use. Available channels are <code>
        ['card', 'bank', 'ussd', 'qr', 'eft', 'mobile_money', 'bank_transfer', 'apple_pay', 'google_pay']
      </code>
      
      . <code>
        google_pay
      </code>
      
       is for businesses in South Africa and must be passed alongside <code>
        card
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        metadata
      </code>
    </td>
    
    <td>
      Object
    </td>
    
    <td>
      False
    </td>
    
    <td>
      A valid object of extra information that you want to be saved to the transaction.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        reference
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Unique case sensitive transaction reference. Only <code>
        -
      </code>
      
      , <code>
        .
      </code>
      
      , <code>
        =
      </code>
      
       and alphanumeric characters allowed.
    </td>
  </tr>
</tbody>
</table>

## One-time transaction

The most basic way to use InlineJS is to accept payment for a one-off transaction. Generally, the payment is non-recurring and requires no special configuration. We provide two methods to accept one-time payments:

1. newTransaction(options)
2. checkout(options)

### newTransaction(options)

This is a synchronous method used to create a transaction. It’s best suited for cases where using an asynchronous flow isn’t necessary. It takes all the general transaction request options and can be used as shown below:

```javascript
const popup = new Paystack()

popup.newTransaction({
  key: 'pk_domain_xxxxxx',
  email: 'sample@email.com',
  amount: 23400,
  onSuccess: (transaction) => {
    console.log(transaction);
  },
  onLoad: (response) => {
    console.log("onLoad: ", response);
  },
  onCancel: () => {
    console.log("onCancel");
  },
  onError: (error) => {
    console.log("Error: ", error.message);
  }
})
```

### checkout(options)

Similar to its counterpart but for an asynchronous flow. It takes all the general transaction request options and can be used as shown below:

```javascript
const popup = new Paystack()

popup.checkout({
  key: 'pk_domain_xxxxxx',
  email: 'sample@email.com',
  amount: 23400,
  onSuccess: (transaction) => {
    console.log(transaction);
  },
  onLoad: (response) => {
    console.log("onLoad: ", response);
  },
  onCancel: () => {
    console.log("onCancel");
  },
  onError: (error) => {
    console.log("Error: ", error.message);
  }
})
```

## Payment request

Payment requests are used for handling wallet payments such as Apple Pay and Google Pay. It's used to create a custom experience by making the wallet option more prominent on your website. For example, you can have the wallet buttons and another button to load the checkout.

Both wallets mount into the same container, and each one is offered only where a charge could succeed. Use the `channels` option to control which wallets a transaction offers. Google Pay is available to businesses in South Africa. It needs `google_pay` passed alongside `card`, and your Google Pay merchant details saved on the Dashboard. See [Google Pay](/za/payments/channels/google-pay) for the full setup.

### paymentRequest(options)

The `paymentRequest` method the following options in addition to the general option:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        container
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      ID of div to mount the payment request button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        loadPaystackCheckoutButton
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      ID of button to open checkout form
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        styles
      </code>
    </td>
    
    <td>
      Object
    </td>
    
    <td>
      False
    </td>
    
    <td>
      CSS style for the wallet button
    </td>
  </tr>
</tbody>
</table>

The `styles` object takes the following options:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        theme
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Option to customize the button background and text color. Available options are <code>
        dark
      </code>
      
       | <code>
        light
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        applePay
      </code>
    </td>
    
    <td>
      Object
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Styles for the Apple Pay button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        googlePay
      </code>
    </td>
    
    <td>
      Object
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Styles for the Google Pay button. South Africa only
    </td>
  </tr>
</tbody>
</table>

The `applePay` object takes the following options:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        width
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Specify the width of the button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        height
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Specify the height of the button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        borderRadius
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Specify the radius of the button edges
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        type
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      This determines the text that shows on the button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        locale
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Set the language of the button
    </td>
  </tr>
</tbody>
</table>

The `googlePay` object takes the following options. Google Pay is available to businesses in South Africa.

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        width
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Specify the width of the button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        height
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Specify the height of the button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        borderRadius
      </code>
    </td>
    
    <td>
      String | Number
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Specify the radius of the button edges. Takes the same shape as <code>
        applePay.borderRadius
      </code>
      
      , so <code>
        '3px'
      </code>
      
       and <code>
        3
      </code>
      
       both work. Defaults to <code>
        '3px'
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        buttonType
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      This determines the text that shows on the button. Defaults to <code>
        pay
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        buttonColor
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Set the button color independently of <code>
        theme
      </code>
      
      , which it otherwise follows
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        buttonSizeMode
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      How the button fills the space it's given. Defaults to <code>
        fill
      </code>
    </td>
  </tr>
</tbody>
</table>

<callout title="Google Pay button styling" type="info">

Google requires its own SDK to draw the Google Pay button, so `googlePay` isn't freeform CSS the way `applePay` is. Apart from `width`, `height` and `borderRadius`, every key is passed through to Google's [createButton](https://developers.google.com/pay/api/web/reference/client#createButton), so anything it accepts works here. That includes Google's own `buttonRadius`, which takes a bare number and applies when you don't pass `borderRadius`.

</callout>

```html
<!-- Payment request buttons, styles and event listeners will be injected to this div -->
<div id="payment-request-buttons"></div>
<button id="pay-button">More payment options</button>
```

<localized-snippet src="developer-tools/inline-js/payment-request">



</localized-snippet>

## Resume transaction

Resuming a transaction lets you initiate it on your server and complete it in the browser. This flow provides both the security of server initialization and the convenience of the user experience in the browser. To get started, make a `POST` request from your backend to the [Initialize Transaction](/api/transaction#initialize) endpoint:

<request-response>
<template v-slot:curl="">

```bash
curl https://api.paystack.co/transaction/initialize \
  -H "Authorization: Bearer $PAYSTACK_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "customer@email.com",
    "amount": 500000
  }' \
  -X POST
```

</template>

<template v-slot:js="">

```javascript
const https = require("https");

const params = JSON.stringify({
  "email": "customer@email.com",
  "amount": 500000
});

const options = {
  hostname: "api.paystack.co",
  port: 443,
  path: "/transaction/initialize",
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PAYSTACK_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(res.statusCode, JSON.parse(data));
  });
});

req.on("error", (error) => {
  console.error(error);
});

req.write(params);
req.end();
```

</template>

<template v-slot:php="">

```php
<?php
$fields = [
  "email" => "customer@email.com",
  "amount" => 500000,
];

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.paystack.co/transaction/initialize",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode($fields),
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer " . getenv("PAYSTACK_SECRET_KEY"),
    "Content-Type: application/json",
    "Cache-Control: no-cache",
  ),
));
$response = curl_exec($curl);
echo curl_getinfo($curl, CURLINFO_HTTP_CODE) . " " . $response;
?>
```

</template>

<template v-slot:response="">

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

</template>
</request-response>

In the `data` object of the response returned, you need to save the `access_code` and send it to your frontend.

<callout title="Secret key safeguarding" type="danger">

Don't make an API request to the Initialize Transaction endpoint directly on your mobile app because it requires your secret key. Your secret key should only be used on your server where stronger security measures can be put in place.

</callout>

### resumeTransaction(accessCode)

In your frontend, you can use this `access_code` to complete the payment without leaving your site.

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        accessCode
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Access code returned from the transaction initialization
    </td>
  </tr>
</tbody>
</table>

```javascript
const popup = new Paystack()

popup.resumeTransaction(access_code)
```

The `resumeTransaction` method triggers the checkout in the browser, allowing the user to choose their preferred payment channel to complete the transaction.

## Split transaction

Sometimes you need to share a transaction with another business or entity. To do this you can [create a subaccount](/payments/split-payments/subaccounts) and pass the `subaccoutCode` from the response when setting up payment:

```javascript
const popup = new Paystack()

popup.newTransaction({
  key: 'pk_domain_xxxxxx',
  email: 'sample@email.com',
  amount: 45000,
  subaccountCode: 'ACCT_dskvlw3y3dsvkmt',
  onSuccess: (transaction) => {
    console.log(transaction);
  },
  onLoad: (response) => {
    console.log("onLoad: ", response);
  },
  onCancel: () => {
    console.log("onCancel");
  },
  onError: (error) => {
    console.log("Error: ", error.message);
  }
})
```

The table below shows the parameters that can be used to config split payments:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        subaccountCode
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      A valid Paystack subaccount code for example <code>
        ACCT_8f4s1eq7ml6rlzj
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bearer
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      This is used to specific the account that bears the Paystack charges. Values can be <code>
        account
      </code>
      
       or <code>
        subaccount
      </code>
      
       (defaults to <code>
        account
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        transactionCharge
      </code>
    </td>
    
    <td>
      Number
    </td>
    
    <td>
      False
    </td>
    
    <td>
      A flat fee (in the smallest denomination of your currency) the main account should take. This overrides the split percentage set when the subaccount was created.
    </td>
  </tr>
</tbody>
</table>

## Multi-split transaction

Multi-split payment is used to share a single transaction with multiple partners. Based on your use-case, the split can be created ahead of time via the API or dynamically during the transaction initiation.

If you are certain of your split configuration ahead of time, you can [create the split](/payments/split-payments/multi-split) and pass the `split_code` when setting up the transaction:

```javascript
const popup = new Paystack()

popup.newTransaction({
  key: 'pk_domain_xxxxxx',
  email: 'multi@split.com',
  amount: 98540,
  split_code: 'SPL_RYUUL4u1hP',
  onSuccess: (transaction) => {
    console.log(transaction);
  },
  onLoad: (response) => {
    console.log("onLoad: ", response);
  },
  onCancel: () => {
    console.log("onCancel");
  },
  onError: (error) => {
    console.log("Error: ", error.message);
  }
})
```

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        split_code
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      A valid Paystack split code with configuration for how payment should be split with partners
    </td>
  </tr>
</tbody>
</table>

Otherwise, you might want to create the split on the fly by passing the `split` object in the transaction request:

<localized-snippet src="developer-tools/inline-js/multi-split-dynamic">



</localized-snippet>

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        name
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Name of the split
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        type
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Takes either <code>
        flat
      </code>
      
       or <code>
        percentage
      </code>
      
       to indicate if you want a fixed or variable share
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        currency
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Currency of the split, such as <localized-value page-key="markets" path="currency_code">
        
      </localized-value>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subaccounts
      </code>
    </td>
    
    <td>
      Array
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Takes an array of subaccount objects used to specify the account and share of each account
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bearer_type
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The bearer of the transaction fee: <code>
        all
      </code>
      
      , <code>
        all-proportional
      </code>
      
      , <code>
        account
      </code>
      
       or <code>
        subaccount
      </code>
      
      . Set it explicitly
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bearer_subaccount
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      Subaccount code of the bearer. Required if <code>
        bearer_type
      </code>
      
       is <code>
        subaccount
      </code>
    </td>
  </tr>
</tbody>
</table>

## Subscriptions

Subscription allows you process recurring billing for your customers. The first time you are setting up payments, you can add the following parameters that tells us to continuously charge the customer:

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        planInterval
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Interval for the plan. Valid intervals are <code>
        daily
      </code>
      
      , <code>
        weekly
      </code>
      
      , <code>
        monthly
      </code>
      
      , <code>
        annually
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subscriptionLimit
      </code>
    </td>
    
    <td>
      Number
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The number of times to charge for this subscription
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subscriptionStartDate
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The start date for the subscription (after the first charge)
    </td>
  </tr>
</tbody>
</table>

```javascript
const popup = new Paystack()

popup.newTransaction({
  key: 'pk_domain_xxxxxx',
  email: 'sub@main.com',
  amount: 20000,
  planInterval: 'weekly',
  onSuccess: (transaction) => {
    console.log(transaction);
  },
  onLoad: (response) => {
    console.log("onLoad: ", response);
  },
  onCancel: () => {
    console.log("onCancel");
  },
  onError: (error) => {
    console.log("Error: ", error.message);
  }
})
```

<callout title="Subscription amount" type="info">

The amount specified in the request will be used subsequently for the subscription.

</callout>

Alternatively, you can create a plan [via the API](/payments/recurring/subscriptions/quickstart#step-1-create-a-plan) or dashboard and pass the `planCode` in the transaction request:

```javascript
const popup = new Paystack()

popup.newTransaction({
  key: 'pk_domain_xxxxxx',
  email: 'plan@email.com',
  amount: 40000,
  planCode: 'PLN_l6aglbqzebn32c6',
  onSuccess: (transaction) => {
    console.log(transaction);
  },
  onLoad: (response) => {
    console.log("onLoad: ", response);
  },
  onCancel: () => {
    console.log("onCancel");
  },
  onError: (error) => {
    console.log("Error: ", error.message);
  }
})
```

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        planCode
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      A valid Paystack plan code for example <code>
        PLN_cujsmvoyq2209ws
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subscriptionCount
      </code>
    </td>
    
    <td>
      Number
    </td>
    
    <td>
      False
    </td>
    
    <td>
      The number of subscriptions to create for this plan
    </td>
  </tr>
</tbody>
</table>

<callout title="Plan amount precedence" type="info">

While amount is a required parameter, the amount used to create the plan takes precedence when subscribing to a plan.

</callout>

## Preload transaction

Preloading a transaction is similar to creating a new transaction but with a little twist. Rather than waiting till the final moment to make a transaction request, you can load the transaction ahead of time.

This method loads a transaction on the Popup without opening it. It returns a function that can be used to open the Popup at a later time. This allows the Popup to load instantly at the point the user is ready to make a payment.

### preloadTransaction(options)

This method takes all the general options of a transaction request:

```html
<button id="make-payment">Make Payment</button>
```

<localized-snippet src="developer-tools/inline-js/preload-transaction">



</localized-snippet>

## Cancel transaction

There are situations where you want to build a logic to cancel a transaction. The `cancelTransaction` method allows you to cancel a transaction and hide the checkout iFrame.

### cancelTransaction(id)

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      String
    </td>
    
    <td>
      True
    </td>
    
    <td>
      Transaction ID of the payment to cancel
    </td>
  </tr>
</tbody>
</table>

```javascript
const popup = new Paystack()

const transaction = popup.newTransaction({
  key: 'pk_domain_xxxxx', // Replace with your public key
  email: "demo@example.com",
  amount: 10000,
  onLoad: (transaction) => {
    window.clearInterval(redirectTimer);
  }
});

let timeElapsed = 0;
const timeLimit = 2;
const redirectURL = 'https://your.redirecturl.com';
const redirectTimer = setInterval(() => {
  timeElapsed += 1;
  if (timeElapsed === timeLimit) {
    popup.cancelTransaction(transaction.id);
    window.location.href = redirectURL;
  }
}, 1000);
```
