---
updatedAt: 2026-04-10T09:41:15.000Z
agentTools:
  projectIndex: https://docs.br-dge.io/llms.txt
---

# PayPal JavaScript SDK

This guide provides technical instructions for integrating PayPal using **BR-DGE’s** API-first approach. This flow separates order creation from payment processing to provide greater control over the transaction lifecycle.

This guide make reference to scripts, functions & callbacks provided by the PayPal JavaScript SDK. The examples on this page are intended to be used to kick start your integration. For a full overview of the PayPal JavaScript SDK and it's features you should also read <Anchor label="PayPal's documentation" target="_blank" href="https://developer.paypal.com/sdk/js/">PayPal's documentation</Anchor>.

# Overview

The API-first integration follows a structured sequence where orders are created via the **BR-DGE** REST API, customer approval is managed by the PayPal SDK, and final payment processing is completed via **BR-DGE** after approval.

PayPal via the **BR-DGE** REST API flows in the following way:

1. You load the PayPal SDK and inject the PayPal button into your checkout page.
2. Your customer clicks the PayPal button.
3. You create a PayPal order with a call from your backend server to the **BR-DGE** REST API.
4. **BR-DGE** return a PayPal order and you pass the order details to PayPal.
5. Your customer completes the payment directly with PayPal and you're informed of the completion.
6. You authorise or capture the payment with a backend API call to **BR-DGE**.

# Prerequisites

To get started making PayPal payments via **BR-DGE** ensure you have the following:

* A **BR-DGE** Server API Key.
* A PayPal account configured on your retail channel.
* Your PayPal Client ID configured with **BR-DGE**.

# Load PayPal SDK

Load the PayPal SDK into your checkout page by passing the required variables. You can dynamically create a script element to include your clientId and currency.

```javascript Load PayPal SDK Example
function loadPaypalSDK(config) {
  const script = document.createElement('script');
  script.src = `https://www.paypal.com/sdk/js?client-	id=${PAYPAL_CLIENTID}&currency=${TRANSACTION_CURRENCY}`;
  script.onload = renderPaypalButton;
  document.head.appendChild(script);
}
```

### PayPal Pay Later

To enable PayPal Pay Later functionality, include the specific components and funding flags in the SDK URL.

* **Components**: `buttons`, `messages`.
* **Enable Funding**: `paylater`.

```html Pay Later Example URL
<script src="https://www.paypal.com/sdk/js?client-	id=${PAYPAL_CLIENTID}&components=buttons,messages&enable-funding=paylater"></script>
```

<Callout icon="📘" theme="info">
  Pay Later offers are determined by the PayPal SDK based on country and buyer eligibility.
</Callout>

# Render PayPal Button

Once the SDK is loaded, render the button to your container. You must provide the two callback functions defined above.

The below example has two additional functions: `createPayPalOrder` & `finalisePayPalPayment`. Making PayPal call functions from their callbacks is not mandatory. You can run the order creation & post approval steps directly inline with the callback functions. The PayPal SDK documentation shows examples of how you can achieve this:

* <Anchor label="`createOrder`" target="_blank" href="https://developer.paypal.com/sdk/js/reference/#createorder">`createOrder`</Anchor>
* <Anchor label="`onApprove`" target="_blank" href="https://developer.paypal.com/sdk/js/reference/#onapprove">`onApprove`</Anchor>

```javascript Render PayPal Button
function renderPaypalButton() {
  paypal.Buttons({
    createOrder: createPayPalOrder,
    onApprove: finalisePayPalPayment
  }).render('#paypal-button-container');
}
```

# Callback Functions

PayPal require a minimum of two callback functions to be defined for use as part of the payment processing flow.

* `createOrder` --> Informs your backend that the customer has clicked the button to initiate an order.
* `onApprove` --> Called by PayPal after the customer completes the checkout so you can finalise the payment.

PayPal offer additional callbacks in their SDK all the available functions are available to view on the PayPal documentation site, [here](https://developer.paypal.com/sdk/js/reference/#buttons).

## Create Order Callback

The `createOrder` callback is fired by PayPal when the customer has clicked the PayPal button prompting you to make a call from your backend server to the **BR-DGE** REST API to create a PayPal order.

You do this by making a request to `POST /v1/paypal/orders` passing in the required request details. Check out the <Anchor label="API reference documentation" target="_blank" href="/reference/createpaypalorderusingpost">API reference documentation</Anchor> for this endpoint for a full view of how to create a PayPal order.

Your callback should return the `orderId` from the BR-DGE REST API to the `createOrder` function.

You can check out the PayPal `createOrder` documentation directly, [here](https://developer.paypal.com/sdk/js/reference/#createorder).

## On Approve Callback

The `onApprove` callback is fired by PayPal when the customer has completed the payment.

When this callback is fired you should inform your backend server and make a request to `POST /v1/paypal/orders/{orderId}/payments` endpoint passing in the `orderId` from the order creation step.

Check out the <Anchor label="API reference documentation" target="_blank" href="/reference/paypalorderpaymentusingpost">API reference documentation</Anchor> for this endpoint for a full view of how to authorise or capture a PayPal order.

<Callout icon="❗️" theme="error">
  If you do not call the **BR-DGE** REST API to authorise or capture the order the funds will **not** be collected by PayPal.
</Callout>

You can check out the PayPal `onApprove` documentation directly, [here](https://developer.paypal.com/sdk/js/reference/#createorder).

# Support

If you assistance integrating the PayPal SDK please <Anchor label="contact our support team" target="_blank" href="/docs/support">contact our support team</Anchor>.

<br />