@payperform/widget
TypeScript icon, indicating that this package has built-in type declarations

4.3.13 • Public • Published

Orbital Widget

Orbital Widget simplifies embedding external pages within an iframe for seamless integration, removing the need for redirects. With a few lines of code, you can integrate the widget into your site and provide a smoother user experience.

Features

  • Embed Orbital's payment pages in an iframe with minimal setup.
  • No redirects needed; content is embedded directly on your site.

Installation

To install via npm:

npm install @payperform/widget

or yarn

yarn add @payperform/widget

Via cdn:

You can also include Orbital Widget using the CDN for faster integration:

Use the latest version: To always load the most up-to-date version of the widget:

<script src="https://widgets.getorbital.io/index-latest.js"></script>

Specify a specific version: If you want to lock in a particular version of the widget:

<script src="https://widgets.getorbital.io/index-{version}.js"></script>

Example (React)

Here’s a simplified example of how you can integrate the Orbital Widget in a React application. This version focuses on embedding the widget, and the signature should be fetched from your own backend server.

import React, { useEffect, useState, useRef } from 'react'
import { init } from '@payperform/widget'
import styles from './OrbitalWidget.module.scss'

const OrbitalWidget: React.FC = () => {
  const [signature, setSignature] = useState<string | null>(null)
  const orbitalRef = useRef<HTMLDivElement | null>(null)

  useEffect(() => {
    // Fetch signature from your backend server and set it here
    // Example: setSignature(response.signature);
    // Developer should replace this with their own server call to fetch signature
    setSignature('your-signature-from-backend')
  }, [])

  useEffect(() => {
    if (signature && orbitalRef.current) {
      orbitalRef.current.setAttribute('signature', signature)

      init({
        container: 'orbital',
      })
    }
  }, [signature])

  return <div className={styles['iframe-container']} id="orbital" ref={orbitalRef}></div>
}

export default OrbitalWidget

Note: In this example, the fetching of the signature is not included. You should replace setSignature('your-signature-from-backend') with a call to your own server to retrieve the signature.

If you would like to see a full implementation including fetching the signature from a backend, please refer to the examples/react folder in this repository.

Usage Once integrated, the widget will automatically embed Orbital's payment page within the provided container on your site.

Example (Vanilla JavaScript)

Here’s a simple example of how to integrate the Orbital Widget using vanilla JavaScript. In this example, the signature is fetched from your own backend server. The actual server call has been simplified for clarity.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Orbital Widget Example</title>
  </head>
  <body>
    <div id="orbital"></div>
    <script src="https://widgets.getorbital.io/index-latest.js"></script>
    <script>
      window.addEventListener('load', async () => {
        // Simulate fetching the signature from your backend
        const signature = 'your-signature-from-backend' // Replace with your own logic to get the signature

        const orbitalElement = document.getElementById('orbital')
        if (orbitalElement && signature) {
          orbitalElement.setAttribute('signature', signature)
        }

        if (typeof OrbitalWidget !== 'undefined' && typeof OrbitalWidget.init === 'function') {
          OrbitalWidget.init({
            container: 'orbital',
          })
        } else {
          console.error('OrbitalWidget was not loaded properly.')
        }
      })
    </script>
  </body>
</html>

Backend Implementation

To fetch the signature required for the Orbital Widget, you can set up a simple Express server. Below is an example of how to create an endpoint that interacts with the Orbital API to retrieve the invoice widget signature.

Example (Node.js with Express) First, ensure you have the necessary packages installed:

npm install express axios cors dotenv

Then, create a file (e.g., server.js) and add the following code:

require('dotenv').config()
const express = require('express')
const axios = require('axios')
const cors = require('cors')

const app = express()
// Enable CORS for all origins
app.use(cors())
app.use(express.json())

app.post('/generate-signature', async (req, res) => {
  try {
    const response = await axios.post(
      process.env.API_URL || 'https://hpp.getorbital.io/invoice/widgets', // Use API URL from .env
      req.body,
      {
        headers: {
          'Content-Type': 'application/json',
          'x-api-key': process.env.API_KEY, // Use API key from .env
        },
      }
    )

    res.status(200).json(response.data)
  } catch (error) {
    res.status(500).json({
      message: 'Error sending request',
      error: error.response ? error.response.data : error.message,
    })
  }
})

const PORT = process.env.PORT || 3000
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`)
})

Usage Environment Variables: Make sure to create a .env file in your project root and add your API URL and API key:

API_URL=https://hpp.getorbital.io/invoice/widgets
API_KEY=your_api_key_here

Run the Server: Start the server by running:

node server.js

Fetch Signature: You can now send a POST request to /generate-signature from your frontend application to retrieve the signature needed for the Orbital Widget.

Note: This server implementation is not part of the Orbital Widget library, but it provides a necessary backend for users to fetch the required signature.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.3.14--canary.088f080.07canary
4.3.133latest

Version History

VersionDownloads (Last 7 Days)Published
4.3.14--canary.088f080.07
4.3.14--canary.5e8457c.01
4.3.133
4.3.13--canary.bf4db3a.00
4.3.13--canary.6a39728.00
4.3.13--canary.cc23717.00
4.3.13--canary.5838b58.00
4.3.120
4.3.12--canary.76.91aaadb.00
4.3.12--canary.8e90932.00
4.3.110
4.3.11--canary.5054275.00
4.3.11--canary.8aaeed0.00
4.3.11--canary.71.8be758c.00
4.3.11--canary.3b3e15d.00
4.3.11--canary.69f7cb0.01
4.3.11--canary.24f33cc.00
4.3.11--canary.e8a5c6e.00
4.3.11--canary.c272b10.00
4.3.11--canary.65.469c4c0.00
4.3.11--canary.65.07ef18c.20
4.3.11--canary.65.07ef18c.10
4.3.11--canary.65.07ef18c.00
4.3.11--canary.65.fd9d7b2.00
4.3.11--canary.65.c3c9a24.00
4.3.11--canary.65.efeb86e.00
4.3.11--canary.65.b8621ec.00
4.3.100
4.3.10--canary.63.23e0d13.00
4.3.90
4.3.9--canary.61.865c646.00
4.3.9--canary.f32fab4.00
4.3.9--canary.e5182fa.00
4.3.9--canary.3d844e9.00
4.3.9--canary.d02d851.00
4.3.9--canary.c4578bd.00
4.3.9--canary.da0e62c.00
4.3.9--canary.89f1343.00
4.3.80
4.3.8--canary.57.e9f0a48.00
4.3.8--canary.57.6fcfcfc.00
4.3.8--canary.57.6fcfef5.00
4.3.8--canary.57.dfa830f.00
4.3.8--canary.57.3b4650d.00
4.3.8--canary.57.bf6e08f.00
4.3.8--canary.57.8dd0d2a.00
4.3.8--canary.57.8939189.00
4.3.8--canary.ef3d81b.00
4.3.8--canary.972d0e9.00
4.3.70
4.3.7--canary.55.52aa77c.00
4.3.7--canary.55.fa8fa75.00
4.3.7--canary.53.19bb69e.00
4.3.7--canary.54.2aa3884.00
4.3.7--canary.53.dab3699.00
4.3.7--canary.bebb2f9.00
4.3.7--canary.9c956c1.00
4.3.7--canary.52.ed6040e.00
4.3.7--canary.52.c768653.00
4.3.7--canary.d9dd344.00

Package Sidebar

Install

npm i @payperform/widget

Weekly Downloads

12

Version

4.3.13

License

UNLICENSED

Unpacked Size

19.3 kB

Total Files

14

Last publish

Collaborators

  • dkorbital
  • leonardo.ordonez
  • pgconstruct
  • vpcreis