npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@confirmo/overlay

v4.2.1

Published

Confirmo overlay library

Downloads

200

Readme

Confirmo

npm

npm install @confirmo/overlay

yarn

yarn add @confirmo/overlay

CDN

<script src="https://cdn.jsdelivr.net/npm/@confirmo/[email protected]/dist/confirmo.js"></script>

Overlay

Bundlers

import { Invoice } from '@confirmo/overlay';

/**
 * Opens Confirmo invoice overlay
 *
 * @param {string} invoice_url - URL of invoice.
 * @param {callback} [callback_fnc] - Optional - callback which is called when overlay was closed
 * @param {InvoiceOverlayConfig} [overlayConfig] - Optional - Confirmo overlay configuration (currently only for auto-close when invoice is paid)
 *
 * @example
 *
 * // URL of invoice created from REST API
 * const invoice_url = 'https://confirmo.demo/#/public/invoice/invv9e1rxdz8';
 *
 * // (optional) Callback which is called when overlay was closed
 * const callback_fnc = () => alert('Overlay has been closed');
 * 
 * // (optional) Confirmo overlay configuration
 * const overlayConfig = {
 *   closeAfterPaid: true,
 *   closeAfterPaidTimeoutMs: 2000, // when unspecified, default is 2000ms
 * }
 *
 */
const overlay = Invoice.open(invoice_url, callback_fnc, overlayConfig);

/**
 * Closes Confirmo invoice overlay
 */
overlay.close();

Script Tag

<script>
  const overlay = Confirmo.Invoice.open(invoice_url, callback_fnc, overlayConfig);

  overlay.close();
</script>

Payment button

HTML

<div id="placeholder-for-button"></div>

Bundlers

import { PaymentButton } from '@confirmo/overlay';

/**
 * Creates Confirmo payment button
 */
const button = PaymentButton.initialize(
  {
    id: 'placeholder-for-button',
    paymentButtonId: 'pbt16354asde',
    buttonType: 'SIMPLE',
    values: {
      productName: 'Some cool product',
      productDescription: 'Simple description',
      reference: 'merchantRef',
      returnUrl: 'https://my-cool-eshop.com/?q=this+is+return+url',
      overlay: true,
    },
  },
  /**
   * Overlay related properties (relevant only if values.overlay set to `true`)
   */
  // (optional) Callback function called on Invoice.close() (see overlay.d.ts)
  () => {
    console.log('Overlay has been closed!');
  },
  // (optional) Invoice overlay config
  overlayConfig,
);

/**
 * Removes Confirmo payment button
 */
button.remove();

Script Tag

<script>
  const button = Confirmo.PaymentButton.initialize(
    {
      id: 'placeholder-for-button',
      paymentButtonId: 'pbt16354asde',
      buttonType: 'SIMPLE',
      values: {
        productName: 'Some cool product',
        productDescription: 'Simple description',
        reference: 'merchantRef',
        returnUrl: 'https://my-cool-eshop.com/?q=this+is+return+url',
      },
    },
    /**
     * Overlay related properties (relevant only if values.overlay set to `true`)
     */
      // (optional) Callback function called on Invoice.close() (see overlay.d.ts)
    () => {
      console.log('Overlay has been closed!');
    },
    // (optional) Invoice overlay config
    overlayConfig,
  );

  button.remove();
</script>

Overlay events

Events fired from Public invoice view via window#postMessage API https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

A component using @confirmo/overlay can listen to InvoiceOverlayMessageEventData accordingly:

import {
  ConfirmoOverlayMessageAction,
  ConfirmoOverlayInvoiceStatus,
  Invoice,
} from '@confirmo/overlay';

const overlay = Invoice.open(invoiceUrl, callback_fnc);

// Custom implementation of closing Confirmo overlay after invoice being paid
window.addEventListener('message', (event) => {
  if (
    invoiceUrl.includes(event.origin) &&
    event.data.action === ConfirmoOverlayMessageAction.CONFIRMO_OVERLAY_INVOICE_STATUS_CHANGE &&
    event.data.status === ConfirmoOverlayInvoiceStatus.PAID
  ) {
    // handle paid invoice (e.g. by closing the overlay)
    setTimeout(() => {
      overlay.close();
    }, 2000); // close overlay after 2 seconds
  }
});

_Note: the same effect as shown above can be achieved simply by setting overlayConfig's closeAfterPaid

import { Invoice } from '@confirmo/overlay';

const overlayConfig = {
  closeAfterPaid: true,
}

Invoice.open(invoiceUrl, callback_fnc, overlayConfig);